/* ============================================================
   FamAPI User Dashboard — Complete Styles v4
   Canva purple #a370fc | Light + Dark theme
   ============================================================ */
:root{
  --canvas:#f7f5fc;--ink:#0f0a1e;--body:#4b4560;--muted:#8b86a0;--muted-soft:#a9a4bc;
  --hairline:#eae6f5;--hairline-soft:#f1eef9;
  --surface:#ffffff;--surface-soft:#faf9fe;--surface-strong:#f3eeff;
  --primary:#a370fc;--primary-active:#8b5cf6;
  --grad:linear-gradient(135deg,#a370fc,#8b5cf6);
  --green:#10b981;--up:#10b981;--down:#ef4444;--warn:#f59e0b;
  --shadow-sm:0 1px 4px rgba(124,58,237,.07);
  --shadow:0 4px 18px rgba(124,58,237,.10);
  --radius:16px;--radius-sm:12px;
  --mono:'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,monospace;
}
[data-theme="dark"]{
  --canvas:#0a0a0a;--ink:#ffffff;--body:#d1d5db;--muted:#9ca3af;--muted-soft:#6b7280;
  --hairline:#1f2937;--hairline-soft:#141c2c;
  --surface:#111827;--surface-soft:#161f33;--surface-strong:#1f2937;
}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:'Inter',system-ui,-apple-system,sans-serif;background:
  radial-gradient(900px 400px at 85% -10%,rgba(139,92,246,.08),transparent 60%),var(--canvas);
  color:var(--ink);line-height:1.55;font-size:15px}
a{color:var(--primary);text-decoration:none}
img{max-width:100%}
.mono{font-family:var(--mono)}

/* ============ APP LAYOUT ============ */
.app{display:flex;min-height:100vh}
.sidebar{width:252px;position:fixed;top:0;bottom:0;left:0;z-index:200;background:linear-gradient(180deg,#fff,#fbf9ff);border-right:1px solid var(--hairline);display:flex;flex-direction:column;transition:transform .28s ease}
.app-content{flex:1;margin-left:252px;display:flex;flex-direction:column;min-width:0}
.app-main{flex:1;padding:30px clamp(16px,4vw,42px);max-width:1060px;width:100%;margin-inline:auto}

/* ---- Sidebar internals ---- */
.side-header{padding:20px 20px 14px;border-bottom:1px solid var(--hairline-soft)}
.side-brand{display:flex;align-items:center;gap:9px;font-weight:800;font-size:17px;color:var(--ink);letter-spacing:-.3px}
.side-brand .brand-accent{color:var(--primary)}
.brand-mark{display:flex}
.side-close{display:none;position:absolute;top:14px;right:14px;background:none;border:0;color:var(--muted);cursor:pointer;padding:7px;border-radius:9px}
.side-close:hover{background:var(--surface-strong)}
.side-nav{flex:1;padding:16px 13px;overflow-y:auto;display:flex;flex-direction:column;gap:2px}
.nav-section{font-size:10.5px;font-weight:800;text-transform:uppercase;letter-spacing:1.3px;color:var(--muted-soft);padding:14px 11px 7px}
.nav-item{display:flex;align-items:center;gap:12px;padding:10.5px 12px;border-radius:11px;color:var(--body);font-size:14px;font-weight:600;transition:.16s}
.nav-item:hover{background:var(--surface-strong);color:var(--ink)}
.nav-item.active{background:linear-gradient(90deg,rgba(163,112,252,.15),rgba(139,92,246,.08));color:var(--primary-active);box-shadow:inset 0 0 0 1px rgba(163,112,252,.28)}
.nav-icon{width:19px;height:19px;flex-shrink:0}
.nav-item.signout{color:var(--down)}
.nav-item.signout:hover{background:#feecec}
.side-footer{padding:15px;border-top:1px solid var(--hairline-soft)}
.side-user{display:flex;align-items:center;gap:11px;padding:10px;background:var(--surface-soft);border:1px solid var(--hairline);border-radius:12px}
.user-avatar{width:36px;height:36px;border-radius:50%;background:var(--grad);color:#fff;font-weight:800;display:flex;align-items:center;justify-content:center;font-size:14px;overflow:hidden;flex-shrink:0}
.user-avatar img,.user-btn-avatar img{width:100%;height:100%;object-fit:cover}
.side-user-name{font-size:13.5px;font-weight:750;line-height:1.25;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.side-user-email{font-size:11.5px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.side-user div{min-width:0}
.side-overlay{display:none;position:fixed;inset:0;background:rgba(10,6,20,.5);backdrop-filter:blur(2px);z-index:190}

/* ---- Topbar ---- */
.topbar{position:sticky;top:0;z-index:150;height:60px;display:flex;align-items:center;justify-content:space-between;gap:14px;padding:0 clamp(16px,4vw,42px);background:color-mix(in srgb,var(--canvas) 82%,transparent);backdrop-filter:blur(14px);border-bottom:1px solid var(--hairline)}
.topbar-title{font-size:17px;font-weight:800;letter-spacing:-.3px}
.topbar-actions{display:flex;align-items:center;gap:9px;position:relative}
.menu-btn{display:none;background:var(--surface);border:1px solid var(--hairline);color:var(--ink);cursor:pointer;padding:9px;border-radius:10px;box-shadow:var(--shadow-sm)}
.menu-btn:hover{border-color:var(--primary)}
.user-btn{display:flex;align-items:center;gap:10px;background:var(--surface);border:1px solid var(--hairline);border-radius:99px;padding:5px 13px 5px 6px;cursor:pointer;font-family:inherit;font-size:13.5px;font-weight:650;color:var(--ink);box-shadow:var(--shadow-sm);position:relative}
.user-btn:hover{border-color:var(--primary)}
.user-btn-avatar{width:31px;height:31px;border-radius:50%;background:var(--grad);color:#fff;font-weight:800;display:flex;align-items:center;justify-content:center;font-size:12.5px;overflow:hidden;flex-shrink:0}
.user-dropdown{position:relative}
.user-dropdown-menu{position:absolute;top:calc(100% + 9px);right:0;width:230px;background:var(--surface);border:1px solid var(--hairline);border-radius:14px;box-shadow:0 14px 44px rgba(20,10,50,.16);padding:7px;display:none;text-align:left;z-index:300}
.user-dropdown-menu.open{display:block}
.dropdown-header{padding:11px 13px;border-bottom:1px solid var(--hairline);margin-bottom:6px}
.dropdown-name{font-size:13.5px;font-weight:750;color:var(--ink)}
.dropdown-email{font-size:11.5px;color:var(--muted);word-break:break-all}
.dropdown-item{display:flex;align-items:center;gap:11px;padding:9.5px 12px;border-radius:9px;color:var(--body);font-size:13.5px;font-weight:600;width:100%;background:none;border:0;cursor:pointer;font-family:inherit;text-align:left}
.dropdown-item:hover{background:var(--surface-strong);color:var(--ink)}
.dropdown-icon{width:17px;height:17px;flex-shrink:0}
.dropdown-item.dropdown-danger{color:var(--down)}
.dropdown-item.dropdown-danger:hover{background:#feecec}

/* ============ PAGE HEAD ============ */
.page-head{margin-bottom:26px}
.page-title{font-size:clamp(21px,3vw,27px);font-weight:800;letter-spacing:-.6px;margin-bottom:6px}
.page-sub{font-size:14px;color:var(--muted)}

/* ============ CARDS / STATS ============ */
.card{background:var(--surface);border:1px solid var(--hairline);border-radius:var(--radius);padding:24px;box-shadow:var(--shadow-sm);margin-bottom:22px}
.card-title{font-size:16.5px;font-weight:800;margin-bottom:5px;letter-spacing:-.2px}
.card-sub{font-size:13px;color:var(--muted);margin-bottom:18px}
.stat-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:14px;margin-bottom:24px}
.stat-card{background:var(--surface);border:1px solid var(--hairline);border-radius:14px;padding:18px;box-shadow:var(--shadow-sm);position:relative;overflow:hidden}
.stat-card.primary{background:var(--grad);border:0;color:#fff}
.stat-card.primary .stat-label{color:#e9ddff}
.stat-label{font-size:11.5px;font-weight:750;text-transform:uppercase;letter-spacing:1px;color:var(--muted);margin-bottom:7px}
.stat-value{font-size:23px;font-weight:800;letter-spacing:-.6px;font-variant-numeric:tabular-nums}
.stat-value.up{color:var(--up)}
.stat-value.down{color:var(--down)}
.stat-card.primary .stat-value.up,.stat-card.primary .stat-value.down{color:#fff}

/* ============ BUTTONS ============ */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;font-weight:700;font-size:14px;padding:10px 20px;border-radius:11px;border:1.5px solid transparent;cursor:pointer;transition:.16s;font-family:inherit;line-height:1.2}
.btn svg{width:16px;height:16px}
.btn-primary{background:var(--grad);color:#fff;box-shadow:0 4px 14px rgba(139,92,246,.32)}
.btn-primary:hover{transform:translateY(-1px);box-shadow:0 7px 20px rgba(139,92,246,.42)}
.btn-secondary{background:var(--surface-strong);color:var(--primary-active)}
.btn-secondary:hover{filter:brightness(.96)}
.btn-outline{border-color:var(--hairline);color:var(--ink);background:var(--surface)}
.btn-outline:hover{border-color:var(--primary);color:var(--primary)}
.btn-sm{padding:7px 14px;font-size:12.5px;border-radius:9px}
.btn-block{width:100%}
.btn:disabled{opacity:.55;cursor:not-allowed;transform:none!important}

/* ============ FORMS ============ */
label,.form-label{display:block;font-size:13px;font-weight:700;margin-bottom:7px;color:var(--ink)}
input,select,textarea{width:100%;padding:11px 14px;border:1.5px solid var(--hairline);border-radius:11px;font-size:14.5px;font-family:inherit;background:var(--surface-soft);color:var(--ink);outline:none;transition:.16s}
input:focus,select:focus,textarea:focus{border-color:var(--primary);background:var(--surface);box-shadow:0 0 0 4px rgba(163,112,252,.13)}
.input{width:100%}
.divider{height:1px;background:var(--hairline);margin:20px 0;border:0}

/* ============ ALERTS ============ */
.alert{padding:13px 16px;border-radius:12px;font-size:13.5px;margin-bottom:18px;border:1px solid;line-height:1.5}
.alert-success{background:#ecfdf5;border-color:#a7f3d0;color:#047857}
.alert-error{background:#fef2f2;border-color:#fecaca;color:#b91c1c}
.alert-warn{background:#fffbeb;border-color:#fde68a;color:#92400e}
[data-theme="dark"] .alert-success{background:rgba(16,185,129,.1);border-color:rgba(16,185,129,.35);color:#6ee7b7}
[data-theme="dark"] .alert-error{background:rgba(239,68,68,.1);border-color:rgba(239,68,68,.35);color:#fca5a5}
[data-theme="dark"] .alert-warn{background:rgba(245,158,11,.1);border-color:rgba(245,158,11,.35);color:#fcd34d}

/* ============ TABLES ============ */
.table-wrap{overflow-x:auto;border:1px solid var(--hairline);border-radius:13px;background:var(--surface)}
.data-table{width:100%;border-collapse:collapse;font-size:13.5px;min-width:520px}
.data-table th{text-align:left;padding:12px 15px;font-weight:750;font-size:11.5px;text-transform:uppercase;letter-spacing:.8px;color:var(--muted);background:var(--surface-soft);border-bottom:1px solid var(--hairline);white-space:nowrap}
.data-table td{padding:12px 15px;border-bottom:1px solid var(--hairline-soft);vertical-align:middle}
.data-table tr:last-child td{border-bottom:0}
.empty-row td{text-align:center;color:var(--muted);padding:34px 15px;font-size:13.5px}
.key-row{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;padding:13px 0;border-bottom:1px dashed var(--hairline)}
.key-row:last-child{border-bottom:0}
.key-label{font-size:12px;color:var(--muted);font-weight:700;text-transform:uppercase;letter-spacing:.7px}
.key-text{font-family:var(--mono);font-size:13px;word-break:break-all}

/* ============ BADGES ============ */
.badge{display:inline-flex;align-items:center;gap:5px;font-size:11px;font-weight:800;padding:4px 11px;border-radius:99px;text-transform:uppercase;letter-spacing:.6px;white-space:nowrap}
.badge-green{background:#e7f9f1;color:#047857}
.badge-red{background:#fee2e2;color:#b91c1c}
.badge-amber{background:#fef3c7;color:#92400e}
.badge-blue{background:#ede9fe;color:#6d28d9}
.badge-gray{background:var(--surface-strong);color:var(--muted)}
[data-theme="dark"] .badge-green{background:rgba(16,185,129,.15);color:#6ee7b7}
[data-theme="dark"] .badge-red{background:rgba(239,68,68,.15);color:#fca5a5}
[data-theme="dark"] .badge-amber{background:rgba(245,158,11,.15);color:#fcd34d}
[data-theme="dark"] .badge-blue{background:rgba(139,92,246,.15);color:#c4b5fd}

/* ============ PRICING (plans page) ============ */
.pricing-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:18px}
.pricing-card{background:var(--surface);border:1.5px solid var(--hairline);border-radius:16px;padding:26px 22px;display:flex;flex-direction:column;position:relative;transition:.2s}
.pricing-card:hover{transform:translateY(-4px);box-shadow:var(--shadow)}
.pricing-card.featured{border-color:var(--primary);box-shadow:0 12px 34px rgba(139,92,246,.2)}
.price-label{font-size:12.5px;font-weight:800;text-transform:uppercase;letter-spacing:1.1px;color:var(--primary-active);margin-bottom:10px}
.price{font-size:34px;font-weight:800;letter-spacing:-1.2px}
.price-strike{font-size:14px;color:var(--muted);text-decoration:line-through;margin-left:8px;font-weight:600}
.price-row{margin-bottom:16px;padding-bottom:15px;border-bottom:1px dashed var(--hairline)}
.check-list{list-style:none;margin-bottom:20px;flex:1;display:flex;flex-direction:column;gap:10px}
.check-list li{display:flex;gap:9px;font-size:13.5px;color:var(--body);align-items:flex-start}
.check-list li::before{content:'✓';color:var(--up);font-weight:900;flex-shrink:0}

/* ============ MODAL ============ */
.modal-overlay{position:fixed;inset:0;background:rgba(10,6,20,.62);backdrop-filter:blur(4px);z-index:400;display:none;align-items:center;justify-content:center;padding:20px;pointer-events:none}
.modal-overlay.active{display:flex;pointer-events:auto}
.modal{background:var(--surface);border:1px solid var(--hairline);border-radius:18px;padding:30px 26px;width:min(420px,100%);max-height:88vh;overflow:auto;animation:modal-in .25s cubic-bezier(.2,1.2,.4,1);position:relative}
@keyframes modal-in{from{transform:scale(.92);opacity:0}}
.modal-title{font-size:19px;font-weight:800;margin-bottom:6px}
.modal-sub{font-size:13.5px;color:var(--muted);margin-bottom:18px}
.modal-status{margin-bottom:18px}
.modal-price{font-size:38px;font-weight:800;letter-spacing:-1.2px;background:var(--grad);-webkit-background-clip:text;background-clip:text;color:transparent;margin-bottom:4px}
.modal-close{position:absolute;top:14px;right:14px;background:var(--surface-strong);border:0;color:var(--muted);cursor:pointer;padding:8px;border-radius:9px;display:flex}
.modal-close:hover{color:var(--ink)}

/* ============ QR FRAME ============ */
.qr-frame{background:#fff;border:2px dashed #d8ccff;border-radius:16px;padding:18px;margin:0 auto;width:260px;height:260px;text-align:center}
.qr-frame img{width:240px;height:240px;object-fit:contain;border-radius:10px;display:block;margin:0 auto}
.qr-hint{font-size:12.5px;color:var(--muted);text-align:center;margin-top:12px}
.timer{font-family:var(--mono);font-weight:800;color:var(--warn);font-variant-numeric:tabular-nums}

/* ============ FILTER CHIPS / UTILITIES ============ */
.filter-chip{display:inline-flex;padding:7px 15px;border-radius:99px;font-size:12.5px;font-weight:700;border:1.5px solid var(--hairline);background:var(--surface);color:var(--muted);cursor:pointer;transition:.15s;font-family:inherit}
.filter-chip.active{background:var(--grad);color:#fff;border-color:transparent}
.flex{display:flex}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.justify-between{justify-content:space-between}
.gap-8{gap:8px}.gap-16{gap:16px}.mt-24{margin-top:24px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:16px}
@media(max-width:640px){.grid2{grid-template-columns:1fr}}

/* ============ MOBILE SIDEBAR ============ */
@media(max-width:920px){
  .sidebar{transform:translateX(-104%);box-shadow:none;width:270px}
  .sidebar.open{transform:none;box-shadow:24px 0 60px rgba(10,5,25,.25)}
  .app-content{margin-left:0}
  .menu-btn{display:flex}
  .side-close{display:flex}
  .side-overlay.show{display:block}
  .topbar-title{font-size:15.5px}
  .app-main{padding:22px 16px}
  .stat-value{font-size:19px}
}

/* ============ THEME TOGGLE (day / night) ============ */
.theme-toggle{width:38px;height:38px;border-radius:11px;background:var(--surface);border:1px solid var(--hairline);color:var(--ink);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:var(--shadow-sm);transition:.18s;padding:0}
.theme-toggle:hover{border-color:var(--primary);color:var(--primary);transform:rotate(15deg)}
.theme-icon{width:19px;height:19px}
html:not([data-theme="dark"]) .theme-moon{display:none}
html[data-theme="dark"] .theme-sun{display:none}

/* ============ TOGGLE SWITCH ============ */
.switch{position:relative;display:inline-block;width:48px;height:26px;cursor:pointer;flex-shrink:0}
.switch input{opacity:0;width:0;height:0;position:absolute}
.switch-track{position:absolute;inset:0;background:var(--hairline);border-radius:13px;transition:.25s;display:block}
.switch-thumb{position:absolute;left:3px;top:3px;width:20px;height:20px;background:#fff;border-radius:50%;transition:.25s;box-shadow:0 2px 5px rgba(0,0,0,.2);display:block}
.switch input:checked + .switch-track{background:var(--primary)}
.switch input:checked + .switch-track .switch-thumb{transform:translateX(22px)}

/* ============ DOCS TERMINAL (logged-in users) ============ */
.docs-wrap{padding:0 4px}
.docs-section{background:#fff;border:1px solid var(--hairline);border-radius:var(--radius);padding:28px 24px;margin:22px 0}
.docs-section h2{font-size:20px;font-weight:800;margin-bottom:12px}
.docs-section p{color:var(--body);font-size:14px;line-height:1.65;margin-bottom:10px}
.docs-callout{background:var(--surface-soft);border-left:3px solid var(--primary);border-radius:0 11px 11px 0;padding:12px 16px;font-size:13px;color:var(--primary);margin:14px 0}
.docs-num{display:inline-flex;width:28px;height:28px;border-radius:50%;background:var(--grad);color:#fff;font-weight:800;font-size:13px;align-items:center;justify-content:center;margin-right:8px}
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;border:1px solid var(--hairline);border-radius:12px;margin:14px 0}
.table-wrap .data-table{min-width:500px}
.table-wrap .data-table th{font-size:10.5px;padding:10px 12px;white-space:nowrap;letter-spacing:.06em}
.table-wrap .data-table td{font-size:13px;padding:10px 12px;white-space:nowrap}
.table-wrap .data-table td:last-child{white-space:normal;min-width:130px}
.table-wrap .badge{font-size:10px;padding:3px 8px}
.code-block{margin:14px 0;border-radius:12px;overflow:hidden;background:#0d0d0d;border:1px solid #2a2a2a}
.code-label{display:flex;justify-content:space-between;align-items:center;padding:9px 14px;background:#1a1a1a;color:#a0a0a0;font-size:11.5px;font-weight:700;font-family:var(--mono);border-bottom:1px solid #2a2a2a}
.code-label::before{content:'›';color:#4ade80;margin-right:6px;font-size:14px}
.code-block pre{background:#0d0d0d!important;color:#e2e8f0!important;font-family:var(--mono);font-size:12.5px;line-height:1.7;padding:16px 18px;overflow-x:auto;white-space:pre-wrap;word-break:break-all;margin:0;border-radius:0}
.copy-btn{background:rgba(74,222,128,.12);border:1px solid rgba(74,222,128,.3);color:#4ade80;font-size:11px;font-weight:700;padding:4px 10px;border-radius:6px;cursor:pointer;font-family:'Inter',sans-serif;transition:.2s}
.copy-btn:hover{background:rgba(74,222,128,.25)}
.copy-btn.copied{background:#4ade80;color:#0d0d0d;border-color:#4ade80}
.docs-section pre{background:#0d0d0d!important;color:#e2e8f0!important;border:1px solid #2a2a2a;border-radius:12px;padding:16px 18px;margin:12px 0;overflow-x:auto;font-family:var(--mono);font-size:12.5px;line-height:1.7;white-space:pre-wrap;word-break:break-all}
.docs-wrap .desc code,.docs-section code{background:#1a1a1a;color:#4ade80;padding:2px 7px;border-radius:5px;font-family:var(--mono);font-size:.88em;border:1px solid #2a2a2a}
@media(max-width:640px){
  .docs-section{padding:20px 16px;margin:14px 12px}
  .docs-section h2{font-size:18px}
  .table-wrap .data-table{min-width:460px}
  .code-block pre{font-size:11.5px;padding:12px 14px}
}
