/* MetaScan Pro — web panel. Mirrors the iOS brand: deep near-black, magenta→violet→cyan
   gradient, glassy raised cards, generous rounding. */
:root {
  --bg: #0a0d14;
  --bg2: #070910;
  --surface: #171826;
  --surface-2: #1f2133;
  --stroke: rgba(255, 255, 255, 0.07);
  --magenta: #d14af2;
  --violet: #8c59fa;
  --cyan: #00e6d9;
  --success: #33e680;
  --warning: #ffb020;
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.62);
  --text-faint: rgba(255, 255, 255, 0.4);
  --grad: linear-gradient(90deg, var(--magenta), var(--violet), var(--cyan));
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 80% -10%, rgba(140, 89, 250, 0.16), transparent 60%),
    radial-gradient(900px 600px at -10% 20%, rgba(209, 74, 242, 0.12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

.glass {
  background: linear-gradient(180deg, rgba(31, 33, 51, 0.72), rgba(23, 24, 38, 0.72));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--stroke);
}

/* Brand lockup */
.brand-lockup { font-weight: 800; letter-spacing: -0.02em; font-size: 30px; display: inline-flex; gap: 8px; align-items: baseline; }
.brand-lockup.sm { font-size: 20px; }
.brand-word { color: var(--text); }
.brand-pro {
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  font-style: italic;
}

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; gap: 18px; grid-template-rows: 1fr auto; }
.auth-card { width: min(420px, 100%); border-radius: 24px; padding: 34px 30px; align-self: center; box-shadow: 0 40px 120px rgba(0,0,0,0.5); }
.auth-sub { color: var(--text-dim); margin: 8px 0 26px; font-size: 15px; }
.field-group { display: flex; flex-direction: column; gap: 12px; }
.field-label { font-size: 13px; color: var(--text-dim); }
.input {
  width: 100%; padding: 15px 16px; border-radius: 14px; font-size: 16px;
  background: var(--bg2); border: 1px solid var(--stroke); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(140,89,250,0.22); }
.code-input { letter-spacing: 0.5em; text-align: center; font-size: 22px; font-weight: 700; }

.btn {
  border: none; border-radius: 999px; padding: 15px 20px; font-size: 16px; font-weight: 700;
  color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn .chev { opacity: .8; font-weight: 500; }
.btn-primary { background: var(--grad); box-shadow: 0 10px 30px rgba(209,74,242,0.35); transition: transform .12s, filter .12s; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(.985); }
.btn-primary[disabled] { opacity: .55; pointer-events: none; }
.btn-text { background: none; border: none; color: var(--text-dim); font-size: 14px; padding: 4px; }
.btn-text:hover { color: var(--text); }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 13px; margin: 22px 0 18px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--stroke); }
#apple-btn { display: flex; justify-content: center; }

.auth-note { margin-top: 22px; font-size: 13px; color: var(--text-faint); line-height: 1.5; }
.auth-note strong { color: var(--text-dim); }
.auth-error { color: #ff6b6b; font-size: 14px; min-height: 18px; margin: 12px 0 0; }
.auth-footer { color: var(--text-faint); font-size: 12px; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 14px clamp(16px, 4vw, 40px); border-left: none; border-right: none; border-top: none;
}
.tabs { display: flex; gap: 4px; background: var(--bg2); padding: 4px; border-radius: 999px; border: 1px solid var(--stroke); }
.tab { background: none; border: none; color: var(--text-dim); font-weight: 600; font-size: 14px; padding: 8px 18px; border-radius: 999px; }
.tab.is-active { color: #fff; background: linear-gradient(180deg, var(--surface-2), var(--surface)); box-shadow: inset 0 0 0 1px var(--stroke); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.email-chip { color: var(--text-dim); font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-icon { background: var(--surface); border: 1px solid var(--stroke); color: var(--text); width: 38px; height: 38px; border-radius: 50%; font-size: 16px; }
.btn-icon:hover { background: var(--surface-2); }

.content { padding: clamp(18px, 4vw, 36px); max-width: 1160px; margin: 0 auto; }

/* Section headers */
.sec-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 20px; }
.sec-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.sec-head .count { color: var(--text-faint); font-size: 14px; }

/* Library grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.scan-card { border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--stroke); transition: transform .15s, border-color .15s, box-shadow .15s; }
.scan-card:hover { transform: translateY(-3px); border-color: rgba(140,89,250,0.5); box-shadow: 0 18px 44px rgba(0,0,0,0.45); }
.thumb { position: relative; aspect-ratio: 1 / 1; background: radial-gradient(120% 120% at 50% 20%, rgba(140,89,250,0.18), var(--bg2)); display: grid; place-items: center; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .placeholder { font-size: 46px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.badge { position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 800; letter-spacing: .04em; padding: 5px 9px; border-radius: 999px; color: #fff; }
.badge.hd { background: var(--grad); }
.badge.pending { background: rgba(0,0,0,0.5); border: 1px solid var(--stroke); color: var(--text-dim); }
.card-body { padding: 12px 14px 14px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { color: var(--text-faint); font-size: 12px; margin-top: 3px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions .btn-sm { flex: 1; }
.btn-sm { font-size: 13px; font-weight: 600; padding: 9px 10px; border-radius: 11px; border: 1px solid var(--stroke); background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-sm:hover { background: #262841; }
.btn-sm.grad { background: var(--grad); border: none; }
.btn-sm.danger:hover { background: rgba(255,80,80,0.16); border-color: rgba(255,80,80,0.5); color: #ff8a8a; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--magenta); animation: spin 0.8s linear infinite; }
.thumb .working { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.55); gap: 8px; grid-auto-flow: row; color: #fff; font-size: 12px; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.empty .big { font-size: 48px; margin-bottom: 12px; opacity: .5; }

/* Profile */
.profile-card { border-radius: var(--radius); padding: 22px; margin-bottom: 16px; }
.profile-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--stroke); }
.profile-row:last-child { border-bottom: none; }
.profile-row .k { color: var(--text-dim); font-size: 14px; }
.profile-row .v { font-weight: 600; }
.danger-zone h3 { color: #ff8a8a; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 12px; }

/* Viewer modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(4,5,10,0.7); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 20px; }
.modal { width: min(880px, 100%); border-radius: 22px; overflow: hidden; position: relative; box-shadow: 0 40px 120px rgba(0,0,0,0.6); }
.modal-close { position: absolute; top: 14px; right: 14px; z-index: 3; width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,0.5); border: 1px solid var(--stroke); color: #fff; font-size: 15px; }
.viewer-stage { aspect-ratio: 4 / 3; background: radial-gradient(120% 120% at 50% 15%, rgba(140,89,250,0.2), var(--bg2)); display: grid; place-items: center; }
.viewer-stage model-viewer { width: 100%; height: 100%; --poster-color: transparent; }
.viewer-stage img { max-width: 80%; max-height: 80%; object-fit: contain; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 20px; flex-wrap: wrap; }
.viewer-meta { color: var(--text-dim); font-size: 14px; }
.viewer-meta strong { color: #fff; }
.viewer-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; background: var(--surface-2); border: 1px solid var(--stroke); color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 12px 30px rgba(0,0,0,0.5); opacity: 0; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { border-color: rgba(255,80,80,0.5); }

/* ---------- Admin console ---------- */
.subtabs { display: inline-flex; gap: 4px; background: var(--bg2); padding: 4px; border-radius: 999px; border: 1px solid var(--stroke); margin-bottom: 22px; flex-wrap: wrap; }
.subtab { background: none; border: none; color: var(--text-dim); font-weight: 600; font-size: 13px; padding: 8px 16px; border-radius: 999px; }
.subtab.is-active { color: #fff; background: linear-gradient(180deg, var(--surface-2), var(--surface)); box-shadow: inset 0 0 0 1px var(--stroke); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius); padding: 20px; }
.stat-val { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-val.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-label { color: var(--text-faint); font-size: 13px; margin-top: 6px; }

.panel { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius); padding: 20px; }
.panel-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 12px; }
.kv-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--stroke); font-size: 14px; }
.kv-row:last-child { border-bottom: none; }
.kv-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.kv-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.kv-row .dot.queued { background: var(--warning); }
.kv-row .dot.running { background: var(--cyan); }
.kv-row .dot.done, .kv-row .dot.complete { background: var(--success); }
.kv-row .dot.failed, .kv-row .dot.error { background: #ff6b6b; }

.table-panel { padding: 6px 6px; overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 12px 14px; border-bottom: 1px solid var(--stroke); }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--stroke); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.admin-table .num { font-variant-numeric: tabular-nums; }
.admin-table .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.admin-table .badge { position: static; }
.badge.muted { background: var(--surface-2); border: 1px solid var(--stroke); color: var(--text-dim); }
.card-sub.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.form-panel { max-width: 520px; }
.form-panel .field-label { display: block; margin: 16px 0 6px; }
.form-panel .field-label:first-of-type { margin-top: 0; }
.form-panel textarea.input { resize: vertical; font-family: inherit; }
.form-hint { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin: 0 0 6px; }

@media (max-width: 560px) {
  .tabs { order: 3; }
  .topbar { flex-wrap: wrap; }
  .email-chip { display: none; }
}
