/* ============================================================
   JinYer Balance — Admin Dashboard
   Brand: #0a0a0a bg | #C2C8D4 silver | Space Grotesk + DM Sans
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0a0a0a;
  --surface:      #111214;
  --surface-2:    #161718;
  --border:       rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.16);
  --silver:       #C2C8D4;
  --steel:        #8A9AB0;
  --slate:        #6e8393;
  --muted:        #94a3b8;
  --white:        #f7f8fa;
  --danger:       #ef4444;
  --success:      #22c55e;
  --warning:      #f59e0b;
  --font-head:    'Space Grotesk', system-ui, sans-serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --radius:       999px;
  --radius-card:  14px;
  --radius-sm:    8px;
}

html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
}
/* Film grain overlay — subtle texture, applies globally */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0.032;
  z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: var(--font-body); }

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ── Login Page ───────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -40%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(194,200,212,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 40px;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 8px;
}

.login-logo span {
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--white);
}

.login-badge {
  display: block;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--silver);
  background: rgba(194,200,212,0.08);
  border: 1px solid rgba(194,200,212,0.15);
  border-radius: var(--radius);
  padding: 3px 12px;
  margin: 0 auto 32px;
  width: fit-content;
}

.login-title {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  text-align: center;
}

.login-sub {
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 32px;
}

/* ── Form Elements ────────────────────────────────────── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 7px;
}

.field input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--white);
  transition: border-color 0.2s;
  outline: none;
}

.field input:focus {
  border-color: rgba(194,200,212,0.4);
  background: rgba(255,255,255,0.06);
}

.field input::placeholder { color: var(--slate); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: none;
  border-radius: var(--radius);
  padding: 11px 24px;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary {
  background: var(--silver);
  color: #0a0a0a;
  width: 100%;
  padding: 13px;
  font-size: 0.9rem;
}

.btn-primary:hover { background: #d4dae5; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 0.8rem;
}
.btn-ghost:hover { border-color: var(--border-hover); color: var(--white); }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.8rem;
  padding: 10px 14px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.show { display: block; }

/* ── App Layout ───────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────── */
/* ── Top nav v3 ─────────────────────────────────
   Replaces left sidebar. Edge-to-edge horizontal nav.
   ───────────────────────────────────────────── */
.topnav {
  position: sticky; top: 0;
  z-index: 100;
  background: rgba(10,10,10,0.85);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--border);
}
.topnav-inner {
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 24px;
}
.topnav-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.topnav-brand:hover { opacity: 0.85; }
.topnav-mark {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.topnav-mark img { width: 100%; height: 100%; object-fit: contain; }
.topnav-lockup { display: flex; flex-direction: column; line-height: 1.2; }
.topnav-wordmark {
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--white);
}
.topnav-badge {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--steel);
  margin-top: 2px;
}
.topnav-sections {
  display: flex; gap: 4px;
  flex: 1;
  margin-left: 4px;
}
.topnav-link {
  position: relative;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.topnav-link:hover { background: rgba(255,255,255,0.045); color: var(--white); }
.topnav-link.active {
  background: linear-gradient(180deg, rgba(194,200,212,0.10), rgba(194,200,212,0.04));
  color: var(--white);
  box-shadow: inset 0 -2px 0 0 var(--silver);
}
.topnav-utility { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topnav-search {
  display: flex; align-items: center; gap: 6px;
  width: 220px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  transition: border-color 0.15s, background 0.15s;
}
.topnav-search:focus-within {
  border-color: rgba(194,200,212,0.35);
  background: rgba(255,255,255,0.06);
}
.topnav-search svg { width: 14px; height: 14px; color: var(--muted); flex-shrink: 0; }
.topnav-search input {
  background: transparent; border: none; outline: none;
  color: var(--white); font-family: var(--font-body);
  font-size: 0.82rem; flex: 1; min-width: 0;
}
.topnav-search input::placeholder { color: var(--muted); }
.topnav-icon {
  position: relative;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.025);
  border-radius: 10px;
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.topnav-icon:hover { color: var(--white); border-color: rgba(255,255,255,0.16); background: rgba(255,255,255,0.045); }
.topnav-icon.active { color: var(--silver); border-color: rgba(194,200,212,0.3); }
.topnav-icon svg { width: 16px; height: 16px; }
.topnav-dot {
  position: absolute; top: 8px; right: 8px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--silver);
}
.topnav-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #1f2937, #0a0a0a);
  border: 1px solid var(--border);
  color: var(--silver);
  font-family: var(--font-head);
  font-weight: 700; font-size: 0.82rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: default;
  flex-shrink: 0;
}
.topnav-burger {
  display: none;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.025);
  border-radius: 10px;
  color: var(--muted);
  align-items: center; justify-content: center;
  cursor: pointer;
}
.topnav-burger svg { width: 18px; height: 18px; }

/* Centered burger on mobile — absolute centered horizontally on the topnav row */
@media (max-width: 900px) {
  .topnav-inner { position: relative; }
  .topnav-burger {
    display: inline-flex;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
  }
}

/* Avatar inline with page title (topbar) */
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1f2937, #0a0a0a);
  border: 1px solid var(--border);
  color: var(--silver);
  font-family: var(--font-head);
  font-weight: 700; font-size: 0.78rem;
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}
/* .topnav-avatar removed from JS render — kept selector for legacy fallback */
.topnav-avatar { display: none; }

/* Mobile overlay */
.topnav-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.95);
  backdrop-filter: blur(20px);
  z-index: 200;
  display: none;
  opacity: 0;
  transition: opacity 0.18s;
}
.topnav-overlay.open { display: block; opacity: 1; }
.topnav-overlay-inner {
  padding: 64px 28px 32px;
  max-width: 480px;
  margin: 0 auto;
}
.topnav-overlay-close {
  position: absolute; top: 18px; right: 20px;
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  color: var(--white);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.topnav-overlay-nav { display: flex; flex-direction: column; gap: 4px; }
.topnav-overlay-nav a {
  padding: 14px 16px;
  border-radius: 10px;
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--white);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: background 0.15s;
}
.topnav-overlay-nav a:hover { background: rgba(255,255,255,0.045); }
.topnav-overlay-divider {
  height: 1px; background: var(--border);
  margin: 12px 0;
}

/* Mobile breakpoint */
@media (max-width: 900px) {
  .topnav-sections { display: none; }
  .topnav-search { width: 140px; }
  .topnav-burger { display: inline-flex; }
  .topnav-icon[aria-label="Notifications"],
  .topnav-icon[aria-label="Settings"] { display: none; }
  .topnav-lockup { display: none; }
  .topnav-inner { padding: 12px 16px; gap: 12px; }
}
@media (max-width: 480px) {
  .topnav-search { display: none; }
}

/* legacy sidebar — collapsed (kept for any pages not yet migrated) */
.sidebar {
  display: none;
  width: 220px;
  min-height: 100vh;
  max-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
}
.sidebar-logo:hover { opacity: 0.85; }

.sidebar-logo .logo-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #C2C8D4, #6e8393);
  color: #0a0a0a;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.sidebar-logo .logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.sidebar-logo .wordmark {
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--white);
}

.sidebar-logo .badge {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--steel);
  margin-top: 3px;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  margin-left: 12px;
  margin-right: 12px;
  padding-left: 0;
  padding-right: 0;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 24px;
}

.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--slate);
  padding: 0 8px;
  margin-bottom: 6px;
  display: block;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.18s, color 0.18s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,0.045); color: var(--white); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(194,200,212,0.10), rgba(194,200,212,0.04));
  color: var(--white);
}
.nav-item.active::before {
  content: ""; position: absolute;
  left: -12px; top: 6px; bottom: 6px;
  width: 2px; border-radius: 2px;
  background: linear-gradient(180deg, var(--silver), var(--steel));
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.65; transition: opacity 0.18s; }
.nav-item.active svg { opacity: 1; color: var(--silver); }

.nav-badge {
  margin-left: auto;
  background: var(--silver);
  color: #0a0a0a;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 2px 7px;
}

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

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.user-row:hover { background: rgba(255,255,255,0.04); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(194,200,212,0.15);
  border: 1px solid rgba(194,200,212,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--silver);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--muted); }

.logout-btn, .signout-btn {
  background: none;
  border: none;
  color: var(--slate);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.logout-btn, .signout-btn:hover { color: var(--danger); }

/* ── Main Content ─────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: 0;
  max-width: 1500px;
  width: 100%;
  margin-right: auto;
  margin-left: auto;
  min-height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 16px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.page { padding: 32px; flex: 1; }

/* ── Stats Row ────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px 24px;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--border-hover); }

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.stat-value {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--white);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-delta {
  font-size: 0.75rem;
  color: var(--muted);
}
.stat-delta.up { color: var(--success); }
.stat-delta.warn { color: var(--warning); }

/* ── Section ──────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ── Client Cards ─────────────────────────────────────── */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  transition: all 0.2s;
  cursor: pointer;
  text-decoration: none;
  display: block;
  color: inherit;
}
.client-card:hover { border-color: rgba(194,200,212,0.25); transform: translateY(-2px); }

.client-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.client-initials {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(194,200,212,0.08);
  border: 1px solid rgba(194,200,212,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--silver);
  flex-shrink: 0;
}

.client-info { flex: 1; min-width: 0; }
.client-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.client-business { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Unified status pill system ─────────────────────────
   ONE rule across stages, invoices, files, requests:
     success (green)  → done / paid / launched / approved
     warn    (amber)  → in progress / partial / pending
     info    (steel)  → neutral / draft / sent / meeting
     danger  (rose)   → overdue / blocked / revision needed
     muted   (gray)   → void / paused / archived
   Radius 4px to match jinyerbalance.com index pill spec.
   ───────────────────────────────────────────────────── */
.status-pill,
.stage-badge,
.pill {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1.4;
  white-space: nowrap;
}
/* semantic variants */
.status-success, .stage-badge.launch, .stage-badge.ongoing,
.pill.paid {
  background: rgba(34,197,94,0.12); color: #4ade80;
}
.status-warn, .stage-badge.build, .stage-badge.review,
.pill.partial, .pill.pending {
  background: rgba(245,158,11,0.12); color: #f59e0b;
}
.status-info, .stage-badge.meeting, .stage-badge.proposal,
.pill.draft, .pill.sent {
  background: rgba(138,154,176,0.14); color: #b8c4d3;
}
.status-danger,
.pill.overdue {
  background: rgba(244,63,94,0.12); color: #fb7185;
}
.status-muted,
.pill.void, .pill.paused {
  background: rgba(148,163,184,0.10); color: #94a3b8;
}

.client-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ── Empty State ──────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state svg { margin: 0 auto 16px; opacity: 0.3; }
.empty-state h3 { font-family: var(--font-head); font-size: 1rem; font-weight: 600; color: var(--white); margin-bottom: 8px; opacity: 0.5; }
.empty-state p { font-size: 0.85rem; }

/* ── Loading ──────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--muted);
  font-size: 0.875rem;
  gap: 10px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--silver);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Skeleton screens (replace spinners for known-shape loading) ── */
.skel {
  background: linear-gradient(90deg, rgba(255,255,255,0.025) 0%, rgba(255,255,255,0.07) 50%, rgba(255,255,255,0.025) 100%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius-sm);
  display: block;
}
@keyframes skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-line       { height: 11px; margin-bottom: 8px; }
.skel-line.short  { width: 38%; }
.skel-line.medium { width: 62%; }
.skel-line.long   { width: 84%; }
.skel-line.full   { width: 100%; }
.skel-line.title  { height: 16px; width: 55%; margin-bottom: 12px; }
.skel-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 18px;
}
.skel-stat-card .skel-line:last-child { margin-bottom: 0; }
.skel-grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.skel-table-row {
  display: grid;
  grid-template-columns: 32px 1.6fr 1fr 1fr 0.6fr;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.skel-avatar { width: 32px; height: 32px; border-radius: 9px; }
.skel-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.skel-card-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 18px;
  margin-bottom: 10px;
}
.skel-card-row:last-child { margin-bottom: 0; }
.skel-card-row .skel-line:last-child { margin-bottom: 0; }

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal-overlay.show .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 4px; }
.modal-close:hover { color: var(--white); }

.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

/* (Pre-S80 640px block removed — all rules relocated + upgraded in the
   comprehensive responsive pass below to eliminate the dual-block
   specificity fight.) */

/* ── v2 (S80) additions ──────────────────────── */

/* Language toggle filter */
/* Bilingual: default shows English only. ES only visible if body.lang-es is set. */
.t-es { display: none !important; }
body.lang-es .t-es { display: inline !important; }
body.lang-es .t-en { display: none !important; }

/* Sidebar pending dot for items awaiting decisions */
.nav-item.nav-pending::after {
  content: '';
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  opacity: 0.8;
  flex-shrink: 0;
}

/* Section rhythm — kill inline margin-top overrides */
.section-title + * { margin-top: 0; }

/* File cabinet tabs — shared pattern for All/Active/Pending/Archived */
.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 22px;
  width: fit-content;
  flex-wrap: wrap;
}
.tab {
  padding: 8px 18px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { color: var(--white); }
.tab.active { background: rgba(255,255,255,0.06); color: var(--white); }
.tab-count {
  font-size: 11px;
  margin-left: 6px;
  color: rgba(255,255,255,0.35);
}

/* Placeholder block for not-yet-wired pages */
.ph-block {
  background: var(--surface);
  border: 1px dashed rgba(255,255,255,0.14);
  border-radius: var(--radius-card);
  padding: 60px 40px;
  text-align: center;
}
.ph-block h2 { font-size: 22px; margin-bottom: 10px; }
.ph-block p { color: var(--muted); font-size: 14px; max-width: 560px; margin: 0 auto; line-height: 1.65; }
.ph-block .ph-tag {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f59e0b;
  background: rgba(245,158,11,0.1);
  padding: 4px 10px;
  border-radius: 4px;
  margin-top: 18px;
  font-weight: 600;
}

/* Stage badges — no more 999px pills */
.stage-pill, .cc-stage { border-radius: 3px !important; }


/* ═══════════════════════════════════════════════════════════
   v2 S80 — RESPONSIVE (tablet + mobile) COMPLETE PASS
   ═══════════════════════════════════════════════════════════ */

/* Mobile menu button — injected by sidebar.js */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 100;
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--white);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}
.mobile-menu-btn svg { width: 20px; height: 20px; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 49;
  opacity: 0;
  transition: opacity 0.2s;
}
.sidebar-overlay.show { opacity: 1; }

/* Tablet (≤ 1100px) — tighten spacing, shrink avatar in cards */
@media (max-width: 1100px) {
  .page { padding: 24px 28px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .clients-grid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
  .rf-stats { grid-template-columns: repeat(3, 1fr); }
}

/* Tablet portrait (≤ 900px) — sidebar collapses to icon rail */
@media (max-width: 900px) {
  aside.sidebar {
    width: 64px;
    min-width: 64px;
  }
  aside.sidebar .wordmark,
  aside.sidebar .badge,
  aside.sidebar .nav-label,
  aside.sidebar .nav-item span,
  aside.sidebar .user-info,
  aside.sidebar .lang-toggle,
  aside.sidebar .sidebar-badge { display: none !important; }
  aside.sidebar .nav-item {
    justify-content: center;
    padding: 10px 0;
    margin: 2px 8px;
  }
  aside.sidebar .sidebar-logo {
    justify-content: center;
    padding: 14px 8px;
    text-align: center;
  }
  aside.sidebar .sidebar-footer {
    padding: 10px 4px;
  }
  .main, .main-content { margin-left: 64px; }
  .topbar { padding: 0 20px; }
  .topbar-title { font-size: 18px; }
  .page { padding: 20px 18px; }
  .rf-stats { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}

/* Phone (≤ 640px) — sidebar slides off, hamburger appears */
@media (max-width: 640px) {
  .mobile-menu-btn { display: flex; }

  aside.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 240px !important;
    min-width: 240px !important;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 50;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
  }
  aside.sidebar.open {
    transform: translateX(0);
  }
  /* Re-show labels when mobile sidebar is open */
  aside.sidebar.open .wordmark,
  aside.sidebar.open .badge,
  aside.sidebar.open .nav-label,
  aside.sidebar.open .user-info,
  aside.sidebar.open .lang-toggle,
  aside.sidebar.open .sidebar-badge { display: block !important; }
  /* Nav labels: only show the selected language (not both) */
  aside.sidebar.open .nav-item .t-en,
  aside.sidebar.open .nav-label .t-en,
  aside.sidebar.open .badge .t-en,
  aside.sidebar.open .wordmark .t-en { display: inline !important; }
  aside.sidebar.open .nav-item .t-es,
  aside.sidebar.open .nav-label .t-es,
  aside.sidebar.open .badge .t-es,
  aside.sidebar.open .wordmark .t-es { display: none !important; }
  body.lang-es aside.sidebar.open .nav-item .t-en,
  body.lang-es aside.sidebar.open .nav-label .t-en,
  body.lang-es aside.sidebar.open .badge .t-en,
  body.lang-es aside.sidebar.open .wordmark .t-en { display: none !important; }
  body.lang-es aside.sidebar.open .nav-item .t-es,
  body.lang-es aside.sidebar.open .nav-label .t-es,
  body.lang-es aside.sidebar.open .badge .t-es,
  body.lang-es aside.sidebar.open .wordmark .t-es { display: inline !important; }
  aside.sidebar.open .nav-item {
    justify-content: flex-start;
    padding: 10px 22px;
    margin: 1px 10px;
  }
  aside.sidebar.open .sidebar-logo {
    justify-content: flex-start;
    padding: 22px 22px 18px;
    text-align: left;
  }

  .main, .main-content {
    margin-left: 0;
    max-width: 100%;
  }
  .topbar {
    padding: 0 16px 0 60px;
    height: 56px;
  }
  .topbar-title { font-size: 16px; }
  .topbar-actions .btn { padding: 8px 14px !important; font-size: 12px !important; }

  .page { padding: 18px 14px 60px; }

  /* Stats — one per row on small phones */
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 16px 18px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }

  /* Clients grid — stack */
  .clients-grid { grid-template-columns: 1fr; gap: 10px; }
  .client-card { padding: 14px 16px; }

  /* Referral stats — stack */
  .rf-stats { grid-template-columns: 1fr; gap: 10px; }

  /* Tables — horizontal scroll instead of breaking */
  .rf-table-wrap { overflow-x: auto; }
  table.rf { min-width: 640px; }
  table.rf th, table.rf td { padding: 10px 12px; font-size: 12.5px; }

  /* Tabs — wrap + scroll */
  .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 7px 14px; font-size: 12.5px; }

  /* Profile head stacks */
  .profile-head { flex-direction: column; gap: 14px; }
  .profile-actions { margin-left: 0; width: 100%; }
  .profile-actions .btn { flex: 1; justify-content: center; }

  /* Modal full-width */
  .modal { padding: 20px; max-width: calc(100vw - 32px); }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* Empty state compact */
  .empty-state { padding: 40px 20px; }
  .ph-block { padding: 40px 20px; }
  .ph-block h2 { font-size: 18px; }
  .ph-block p { font-size: 13px; }

  /* Touch targets ≥ 40px */
  .btn { min-height: 40px; }
  button, a.btn, .tab { min-height: 36px; }

  /* Stage tabs (file cabinet) on phone wrap */
  .stage-tabs { overflow-x: auto; flex-wrap: nowrap; }
}

/* Ultra-narrow (≤ 380px — small iPhones) */
@media (max-width: 380px) {
  .stats-row { grid-template-columns: 1fr; }
  .topbar-actions .btn { padding: 7px 10px !important; }
}

/* ── v2 S80 — Global overflow safety (prevents page-wide horizontal scroll) ── */
html, body { overflow-x: hidden; max-width: 100vw; }
.main { overflow-x: hidden; min-width: 0; }
.main > * { min-width: 0; }

/* ── v2 S80.7 — topbar user chip + settings icon (top-right) ── */
.topbar-user-chip { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-icon:hover { color: var(--white) !important; background: rgba(255,255,255,0.06); }
.topbar-avatar:hover { opacity: 0.85; }

/* Mobile topbar — burger now lives centered in the topnav, no need for left padding */
@media (max-width: 640px) {
  .topbar { padding: 0 18px; }
  .topbar-user-chip { gap: 6px; }
  .topbar-icon { width: 32px !important; height: 32px !important; }
  .topbar-avatar { width: 28px; height: 28px; font-size: 11px; margin-right: 8px; }
  .topbar-title { font-size: 14px !important; flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { gap: 6px; min-width: 0; flex-shrink: 1; }
  .topbar-actions > .btn { padding: 7px 10px !important; font-size: 11px !important; }
}

/* Final comprehensive page padding audit — nothing escapes viewport */
.page, .main > div, main.main-content > div {
  box-sizing: border-box;
  max-width: 100%;
}

/* Any data table inside page must scroll, not push */
.page table, main.main-content table { max-width: 100%; }
.page .table-wrap, main.main-content .table-wrap,
.page .clients-table-wrap, main.main-content .clients-table-wrap,
.page .rf-table-wrap, main.main-content .rf-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Rows of pills/badges wrap on mobile */
@media (max-width: 640px) {
  .page .row, .page .stats, .page .rf-stats,
  .page .stats-row, .page .clients-grid { gap: 10px; }
  .pct-pill { margin-bottom: 4px; }
}

/* ─────────────────────────────────────────────────────────────
   MOBILE RESPONSIVE AUDIT — S80.13
   Ensure every live admin page fits within viewport at ≤640px.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Lock every direct page child to viewport width */
  .page > *, .main > .page > * { max-width: 100%; box-sizing: border-box; }

  /* --- Client profile header: stack on mobile --- */
  .client-header {
    flex-wrap: wrap;
    gap: 14px !important;
  }
  .client-header-info { min-width: 0; flex: 1 1 calc(100% - 80px); }
  .client-header-name {
    font-size: 1.15rem !important;
    line-height: 1.25;
    word-break: break-word;
  }
  .client-header-meta {
    font-size: 0.72rem !important;
    gap: 6px !important;
  }
  .client-header-meta span { word-break: break-all; }
  .client-header-actions {
    flex: 1 1 100%;
    width: 100%;
    flex-direction: column !important;
    gap: 8px !important;
  }
  .client-header-actions > * { width: 100%; justify-content: center; }

  /* --- Clients list table: hide low-priority columns on mobile --- */
  .clients-table th:nth-child(2),   /* Email header */
  .clients-table td.client-email,   /* Email cell */
  .clients-table th:nth-child(4),   /* Added header */
  .clients-table td.client-date,    /* Added cell */
  .clients-table th:last-child,     /* Actions header (often empty) */
  .clients-table td:last-child:not(.client-email):not(.client-date) {
    display: none;
  }
  .clients-table { min-width: 0 !important; }

  /* --- Invoices table: hide everything except # + Client + Status --- */
  .iv-table th:nth-child(3),   /* Title */
  .iv-table td:nth-child(3),
  .iv-table th:nth-child(5),   /* Paid */
  .iv-table td:nth-child(5),
  .iv-table th:nth-child(6),   /* Type */
  .iv-table td:nth-child(6) { display: none; }
  .iv-table { min-width: 0 !important; }

  /* --- Referrals table: hide Referred count + Active/Inactive on mobile --- */
  .rf th:nth-child(3),   /* Deal */
  .rf td:nth-child(3),
  .rf th:nth-child(4),   /* Referred count */
  .rf td:nth-child(4) { display: none; }
  .rf { min-width: 0 !important; }

  /* --- Service toggles grid: single column on mobile --- */
  .services-grid, .svc-grid { grid-template-columns: 1fr !important; }

  /* --- Tab nav — visual cue that more tabs exist, fade still active --- */
  .tab-nav { padding-right: 4px; }
  .tab-item { padding: 10px 14px !important; font-size: 0.78rem !important; }

  /* --- Form rows and cards: stack, don't overflow --- */
  .form-row, .quick-row, .actions-row { flex-direction: column !important; align-items: stretch !important; }
  .form-row > *, .quick-row > *, .actions-row > * { width: 100%; }

  /* --- Main page wrapper: make sure padding stays tight at 375 --- */
  .page { padding: 16px 12px 60px !important; }
}

/* Narrow phone (≤ 380px) — tighten further so nothing clips */
@media (max-width: 380px) {
  .client-header-avatar { width: 48px !important; height: 48px !important; font-size: 1rem !important; }
  .client-header-name { font-size: 1.05rem !important; }
  .tab-item { padding: 10px 12px !important; font-size: 0.74rem !important; }
  .page { padding: 14px 10px 60px !important; }
  .stat-value { font-size: 20px !important; }
  .stat-card { padding: 14px 14px !important; }
}
