/* ------------------------------------------------------------------
   App shell: login screens, sidebar (sections), top bar, page header
   with its section menu, and the phone layout (sidebar as a drawer).
   ------------------------------------------------------------------ */

/* ---------- Login / first-admin setup ---------- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(380px, 100%);
  padding: 28px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-card input { min-height: 46px; }
.login-card button { min-height: 48px; margin-top: 4px; }

.login-logo { display: block; height: 72px; width: auto; margin: 0 auto 8px; }

/* ---------- Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 0 0 248px;
  height: 100vh;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.brand-logo { height: 44px; width: auto; display: block; }

.brand-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  font-weight: 700;
}

.brand-title small { color: var(--muted); font-size: 0.75rem; font-weight: 500; }

/* Section list. Each entry opens the section's first page; the section's pages
   show as the menu under the page title. */
.sidenav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 0;
  padding: 11px 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

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

.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.nav-icon svg { width: 20px; height: 20px; }

.nav-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Sub-page names under each section; only shown in the phone menu. */
.nav-hint {
  display: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-chevron { display: none; color: var(--faint); }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.user-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info span { color: var(--muted); font-size: 0.75rem; }

.icon-btn {
  min-height: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
}

.icon-btn:hover { background: var(--surface-muted); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.sidebar-scrim { display: none; }
.mobile-only { display: none !important; }

/* ---------- Main column ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Kept for screen readers; the page title already shows the section. */
.topbar-section { flex: 1; min-width: 0; visibility: hidden; font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.page {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px;
}

.page-head { display: flex; flex-direction: column; gap: 14px; }

/* Pages of the current section (Ventas · Clientes · ...). */
.pagetabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.pagetabs::-webkit-scrollbar { display: none; }

.pagetab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-height: 0;
  padding: 0 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.pagetab:hover { background: transparent; color: var(--text); }

.pagetab.active {
  color: var(--brand);
  font-weight: 600;
  border-bottom-color: var(--brand);
}

/* A section with a single page has no menu; its own sub-tabs sit right under the title. */
.page-head.single .pagetabs { display: none; }

.panel { min-width: 0; }

/* Panel blocks that used to float on the grey background now sit on cards. */
.panel > h3:first-child { margin-top: 0; }

/* ---------- Tablets ---------- */
@media (max-width: 1100px) {
  .sidebar { flex-basis: 220px; }
  .page, .topbar { padding-left: 20px; padding-right: 20px; }
}

/* ---------- Phones: sidebar becomes the full-screen section menu ---------- */
@media (max-width: 900px) {
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(390px, 100%);
    height: 100%;
    padding: 16px 18px;
    gap: 16px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }

  .app-shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }

  .app-shell.nav-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(28, 27, 31, 0.4);
  }

  .sidebar-brand { padding: 0; justify-content: space-between; }
  .sidebar-brand .brand-title { flex: 1; }

  .sidenav { gap: 8px; }

  .nav-item {
    gap: 14px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    white-space: normal;
  }

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

  .nav-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--brand-soft);
    color: var(--brand);
  }

  .nav-label { font-weight: 700; }
  .nav-hint { display: block; white-space: nowrap; }
  .nav-chevron { display: inline-flex; }
  .nav-chevron svg { width: 18px; height: 18px; }

  .topbar { padding: 10px 16px; min-height: 56px; }
  .page { padding: 18px 16px 32px; gap: 16px; }
  h1 { font-size: 1.45rem; }

  .detail-row { grid-template-columns: 1fr; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
