/* ============================================================
   layout.css — sidebar, contenido principal y responsive
============================================================ */

#app {
  display: flex;
  height: 100vh;
  height: -webkit-fill-available;
  height: 100svh;
  height: 100dvh;
  width: 100vw;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  min-height: 0;
  align-self: stretch;
  transition: width var(--transition);
  /* Escritorio: sin scroll en la barra lateral (el contenido principal scrollea). */
  overflow-y: hidden;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 0 8px 18px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.sidebar-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 1.6rem;
  color: var(--accent);
  line-height: 1;
}

.sidebar-sub {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.sidebar-section {
  padding: 14px 8px 6px 8px;
  font-size: 0.7rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

/* ----- Profile switcher ----- */
.profile-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 8px;
  transition: border-color 150ms;
}

.profile-switcher--static {
  cursor: default;
  pointer-events: none;
}
.profile-switcher--static:hover { border-color: var(--border); }
.profile-switcher:hover { border-color: var(--border-strong); }

.profile-switcher-avatar {
  font-size: 1.4rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 8px;
  flex-shrink: 0;
}

.profile-switcher-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.profile-switcher-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-switcher-sub {
  font-size: 0.72rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.profile-switcher-caret {
  color: var(--text-3);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.profile-dropdown {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-dropdown[hidden] { display: none; }

.profile-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: background 120ms;
}

.profile-dropdown-item:hover { background: var(--surface-2); }
.profile-dropdown-item.active { background: var(--surface-2); }

.profile-dropdown-avatar {
  font-size: 1.2rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 6px;
  flex-shrink: 0;
}

.profile-dropdown-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-dropdown-check {
  color: var(--accent);
  font-weight: 700;
}

.profile-dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.profile-dropdown-create {
  color: var(--accent);
  font-weight: 600;
}

.profile-dropdown-create .profile-dropdown-avatar {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

/* ----- Form de crear perfil ----- */
.profile-dropdown-form {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-form-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.profile-form-label {
  font-size: 0.78rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.profile-avatar-grid {
  display: grid;
  /* Auto-responsive: tantas columnas como quepan con avatares de ~36px */
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 4px;
}

.profile-avatar-option {
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 120ms;
}

.profile-avatar-option:hover { background: var(--bg); }
.profile-avatar-option.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
}

.profile-avatar-preview {
  font-size: 2.2rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.profile-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-switcher .profile-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 8px;
}

.profile-avatar-modes,
.profile-avatar-photo-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.profile-avatar-modes {
  margin-bottom: 10px;
}

.profile-avatar-mode-btn,
.profile-avatar-photo-actions .btn {
  flex: 1;
  min-height: 44px;
  justify-content: center;
}

.profile-avatar-mode-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

#avatarEmojiSection,
#avatarPhotoSection {
  margin-top: 0;
}

.profile-avatar-remove-btn {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.profile-avatar-remove-btn:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface-2));
  border-color: var(--danger);
}

.profile-form-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.profile-form-actions .btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.88rem;
}

/* Sidebar colapsado en mobile */
@media (max-width: 800px) {
  .profile-switcher-info,
  .profile-switcher-caret { display: none; }
  .profile-switcher { justify-content: center; padding: 8px; }
  .profile-dropdown {
    position: absolute;
    left: 64px;
    width: 240px;
    z-index: 50;
  }
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  width: 100%;
  transition: all 150ms;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-2);
  color: var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0 8px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.85rem;
  color: var(--text-2);
  width: 100%;
  margin-top: 8px;
}

.theme-toggle:hover { color: var(--text); }

.toggle-switch {
  width: 32px;
  height: 18px;
  background: var(--bg);
  border-radius: 10px;
  position: relative;
  transition: background var(--transition);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  transition: transform var(--transition);
}

[data-theme="light"] .toggle-switch::after {
  transform: translateX(14px);
}

.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 40px 40px;
  overscroll-behavior: contain;
}

.view {
  animation: fadeUp 360ms cubic-bezier(0.4, 0, 0.2, 1);
}

.view-header {
  margin-bottom: 26px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.view-title { color: var(--text); }

.view-sub {
  color: var(--text-2);
  margin-top: 4px;
  font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 800px) {
  :root { --sidebar-w: 64px; }
  .sidebar {
    padding: 18px 8px calc(18px + var(--safe-area-bottom) + var(--mobile-browser-bottom-buffer));
    /* Móvil: scroll solo si hace falta + barra discreta */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }
  .sidebar::-webkit-scrollbar {
    width: 4px;
  }
  .sidebar::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
  }
  .main {
    padding: 20px 18px calc(32px + var(--safe-area-bottom) + var(--mobile-browser-bottom-buffer));
  }
  .sidebar-header,
  .sidebar-section,
  .sidebar-logo,
  .sidebar-sub,
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 11px; }
  .theme-toggle span { display: none; }
  .theme-toggle {
    justify-content: center;
    padding: 10px 4px;          /* reduce horizontal para que entre en 48px */
  }
  .toggle-switch { width: 30px; } /* mini-reducción para margen extra */
  h1 { font-size: 1.9rem; }
}
