/* ============================================================
   Layout – App Shell, Auth, Sidebar, Topbar, Mobile Nav, Pages
   ============================================================ */

/* ─── Auth Screen ─────────────────────────────────────────── */
.auth-wrapper {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
}

.auth-wrapper.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px;
  position: relative;
}

.auth-glow {
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.06;
  pointer-events: none;
}

.auth-glow.g1 {
  top: -100px;
  inset-inline-end: -60px;
  background: var(--brand);
}

.auth-glow.g2 {
  bottom: -80px;
  inset-inline-start: -40px;
  background: var(--transfer);
}

.auth-brand {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin: 0 auto 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 6px 24px var(--brand-shadow);
}

.auth-name {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.5px;
}

.auth-subtitle {
  font-size: 8px;
  color: var(--text-dim);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 2px;
}

.auth-tagline {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.6;
}

.auth-form {
  position: relative;
  z-index: 1;
}

.auth-field {
  margin-bottom: 10px;
}

.auth-row-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}
@media (max-width: 380px) {
  .auth-row-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

.auth-hint {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-glow);
  color: var(--brand);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
.auth-hint.err {
  background: var(--expense-glow);
  color: var(--expense);
}

.auth-field label {
  font-size: 10px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 3px;
}

.auth-field-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
}
.auth-field-hint.err {
  color: var(--expense);
}

.auth-input {
  width: 100%;
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: var(--brand);
}

/* Password field with show/hide eye toggle */
.auth-pass-wrap {
  position: relative;
}
.auth-pass-wrap .auth-input {
  /* leave room for the eye button on the right (inputs use dir="ltr") */
  padding-right: 40px;
}
.auth-pass-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: color 0.2s, background-color 0.2s;
}
.auth-pass-toggle:hover {
  color: var(--text);
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
}
.auth-pass-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.auth-pass-toggle svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.auth-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2px 0 6px;
}

.auth-checkbox {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--text-dim);
}

.auth-checkbox input {
  accent-color: var(--brand);
}

.auth-forgot {
  font-size: 10px;
  color: var(--brand);
}

.auth-submit {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--brand-shadow);
  transition: opacity 0.15s, transform 0.1s;
}

.auth-submit:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-divider span {
  font-size: 10px;
  color: var(--text-faint);
}

.auth-social {
  display: flex;
  gap: 8px;
}

.auth-social button {
  flex: 1;
  padding: 10px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.auth-social button:active {
  border-color: var(--brand);
}

.auth-footer {
  text-align: center;
  margin-top: 14px;
  font-size: 11px;
  color: var(--text-dim);
}

.auth-footer a {
  font-weight: 600;
}

/* ─── Project Selector ────────────────────────────────────── */
.project-selector {
  position: fixed;
  inset: 0;
  z-index: 490;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.project-selector.visible {
  display: flex;
}

.project-selector-card {
  width: 100%;
  max-width: 480px;
  padding: 40px;
  text-align: center;
}

.project-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.project-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.25s ease, background-color 0.25s ease;
  text-align: start;
}

.project-item:hover {
  border-color: var(--brand);
  background: var(--brand-glow);
}

.project-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.project-info {
  flex: 1;
  min-width: 0;
}

.project-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.project-id {
  font-size: 12px;
  color: var(--text-dim);
  font-family: monospace;
  margin-top: 2px;
}

/* ─── App Shell ───────────────────────────────────────────── */
.app-shell {
  width: 100%;
  height: 100vh;
  display: none;
  overflow: hidden;
  background: var(--bg);
}

.app-shell.visible {
  display: flex;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.sidebar-subtitle {
  font-size: 7px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 8px 12px 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background-color 0.2s ease, color 0.2s ease;
  position: relative;
}

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

.sidebar-item.active {
  background: var(--brand-glow);
  color: var(--brand);
  font-weight: 600;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  inset-inline-start: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
[dir="rtl"] .sidebar-item.active::before {
  border-radius: 3px 0 0 3px;
}

.sidebar-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-badge {
  margin-inline-start: auto;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--brand-glow);
  color: var(--brand);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-theme {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366F1, #8B5CF6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.sidebar-email {
  font-size: 11px;
  color: var(--text-dim);
}

.sidebar-logout {
  margin-inline-start: auto;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-faint);
  transition: color 0.25s ease;
}

.sidebar-logout:hover {
  color: var(--expense);
}

/* ─── Main Area ───────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ─── Surface background (backdrop blur) ──────────────────── */
.surface-bg {
  background: rgba(15, 21, 32, 0.85);
  backdrop-filter: blur(20px);
}

[data-theme="light"] .surface-bg {
  background: rgba(255, 255, 255, 0.88);
}

/* ─── Topbar ──────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

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

.topbar-btn {
  height: 32px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: border-color 0.25s ease, color 0.25s ease;
}

.topbar-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.topbar-btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  border-color: transparent;
  color: #fff;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.25s ease;
}

.topbar-search:hover {
  border-color: var(--brand);
}

.topbar-search input {
  background: none;
  border: none;
  color: var(--text);
  font-size: 11px;
  flex: 1;
  min-width: 0;
}

/* ─── Content Area ────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

/* ─── Mobile Header ───────────────────────────────────────── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  height: var(--mobile-header-h, 56px);
}

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
}

.mobile-logo-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.mobile-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mobile-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}

/* ─── Mobile Navigation (Curved Floating Pill) ────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: calc(12px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 10px;
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  gap: 4px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.12);
  background: rgba(15, 21, 32, 0.92);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
}
[data-theme="light"] .mobile-nav {
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.04);
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 6px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
  background: transparent;
  border: none;
}

.mobile-nav-btn:active {
  transform: scale(0.94);
}

.mobile-nav-btn.active {
  color: var(--brand);
  background: var(--brand-glow);
}

.mobile-nav-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform 0.2s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

.mobile-nav-btn.active .mobile-nav-icon {
  transform: translateY(-1px) scale(1.12);
}

.mobile-nav-label {
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  letter-spacing: 0.01em;
}

/* ─── FAB (Floating Action Button) ────────────────────────── */
.fab-button {
  display: none;
  position: fixed;
  bottom: calc(86px + var(--safe-bottom));
  inset-inline-end: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  color: #FFF;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px var(--brand-shadow), 0 2px 4px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  z-index: 99;
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fab-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px var(--brand-shadow), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.fab-button:active {
  transform: scale(0.94);
}

/* ─── Pages ───────────────────────────────────────────────── */
.page {
  display: none;
  animation: fade-in 0.3s ease;
}

.page.active {
  display: block;
}

/* ─── Theme Switch Toggle ─────────────────────────────────── */
.theme-switch {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.theme-switch-track {
  width: 100%;
  height: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: background-color 0.25s ease;
}

.theme-switch-thumb {
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  background: var(--brand);
  border-radius: 50%;
  transition: inset-inline-start 0.25s ease, transform 0.25s ease;
}

.theme-switch.active .theme-switch-thumb {
  inset-inline-start: 23px;
}

/* ─── Animations ──────────────────────────────────────────── */
@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --mobile-header-h: 56px;
    /* Floating dock = 12px bottom inset + ~64px height + 12px breathing room,
       plus the FAB which lifts 86px from the bottom and is 56px tall. We
       keep --mobile-nav-h conservative enough that any content reaching the
       bottom of the scrollable area always clears BOTH the dock and the FAB. */
    --mobile-nav-h: 152px;
  }

  .sidebar { display: none; }
  .topbar  { display: none; }

  /* The main-area's overflow:hidden previously kept .mobile-header in flow;
     pin it to the viewport so it stays freezed during content scroll on
     real mobile browsers (iOS/Android Chrome) regardless of nested scroll
     containers. */
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    z-index: 50;
  }

  .main-area {
    /* Reserve space for the now-fixed header so content doesn't hide under it */
    padding-top: var(--mobile-header-h);
  }

  .mobile-nav  { display: flex; }
  .fab-button  { display: flex; }

  .content-area {
    padding: 16px;
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
    /* Always allow vertical scroll so the last items reach above the dock */
    scroll-padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
  }
}

@media (max-width: 400px) {
  :root { --mobile-header-h: 52px; }

  .content-area {
    padding: 12px;
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
  }

  .auth-card {
    padding: 24px;
    margin: 16px;
  }
}
