:root {
  --bg: #050505;
  --panel: #0e0e0e;
  --panel-2: #151515;
  --line: rgba(255, 255, 255, 0.09);
  --gold: #f2c14e;
  --gold-dim: rgba(242, 193, 78, 0.16);
  --text: #f4f1ea;
  --muted: #9a968d;
  --green: #5fd38d;
  --blue: #6fb4ff;
  --red: #ff6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: progress; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-gold { background: var(--gold); color: #120d00; }
.btn-gold:hover { background: #ffd36a; }
.btn-outline { background: transparent; color: var(--gold); border-color: rgba(242, 193, 78, .55); }
.btn-outline:hover { background: var(--gold-dim); }
.btn-ghost { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: rgba(255,255,255,.25); }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(255, 107, 107, .4); }
.link { background: none; border: 0; color: var(--gold); cursor: pointer; font: inherit; padding: 0; justify-self: start; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(145deg, #f7d27a, #b8862a); color: #120d00; font-size: 12px; font-weight: 900;
}

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(ellipse at top, rgba(242,193,78,.12), transparent 60%); }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.stack { display: grid; gap: 14px; }
.auth-msg { min-height: 1.4em; margin: 0; font-size: 14px; color: var(--gold); }

/* App */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; background: rgba(5,5,5,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.layout { max-width: 1180px; margin: 0 auto; padding: 20px; display: grid; gap: 20px; grid-template-columns: 360px 1fr; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 14px; }
.scan-panel { position: sticky; top: 78px; }
.scan-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.scan-row input { font-size: 20px; letter-spacing: .06em; padding: 14px; }
.scan-row #camera-btn { grid-column: 1 / -1; padding: 14px; }
.defaults { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.defaults label:first-child { grid-column: 1 / -1; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.scan-msg { margin: 0; min-height: 1.4em; font-weight: 600; }
.scan-msg.ok { color: var(--green); }
.scan-msg.err { color: var(--red); }

.queue-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.count { display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 99px; background: var(--gold-dim); color: var(--gold); font-size: 13px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 500; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--gold); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.active { color: var(--gold); border-color: rgba(242,193,78,.6); background: var(--gold-dim); }
.bulkbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); border-radius: var(--radius); }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: auto 64px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
  cursor: pointer; transition: border-color .15s;
}
.item:hover { border-color: rgba(242,193,78,.45); }
.item input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.thumb { width: 64px; height: 64px; border-radius: 8px; background: #fff center/contain no-repeat; border: 1px solid var(--line); display: grid; place-items: center; color: #999; font-size: 11px; overflow: hidden; }
.thumb.none { background: #1b1b1b; }
.item-main { min-width: 0; display: grid; gap: 3px; }
.item-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.item-side { display: grid; justify-items: end; gap: 4px; }
.price { font-weight: 800; color: var(--gold); }
.badge { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.badge.researching { color: var(--blue); background: rgba(111,180,255,.12); }
.badge.researching::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
.badge.needs_review { color: var(--gold); background: var(--gold-dim); }
.badge.ready { color: var(--green); background: rgba(95,211,141,.12); }
.badge.error { color: var(--red); background: rgba(255,107,107,.12); }
.badge.exported { color: var(--muted); background: rgba(255,255,255,.06); }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 30px 0; margin: 0; }

/* Camera */
.camera-dialog { padding: 0; border: 0; background: #000; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; }
.camera-dialog::backdrop { background: #000; }
.camera-wrap { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.camera-wrap video { width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; width: min(80vw, 420px); height: 160px; border: 2px solid var(--gold); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.camera-status { position: absolute; top: max(24px, env(safe-area-inset-top)); left: 16px; right: 16px; text-align: center; margin: 0; padding: 10px 14px; background: rgba(0,0,0,.7); border-radius: 10px; font-weight: 700; }
.camera-status.ok { color: var(--green); }
.camera-actions { position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; padding: 0 16px; }
.camera-actions .btn { padding: 14px 28px; }
.camera-actions .btn-outline { background: rgba(0,0,0,.6); }
.photo-add-btn { width: 100%; margin-top: 10px; }
.photo-tray { margin-top: 12px; padding: 12px; border: 1px dashed var(--gold); border-radius: 10px; }
.photo-tray .hint { margin: 8px 0; }
.tray-thumbs, .camera-tray { display: flex; gap: 8px; flex-wrap: wrap; }
.tray-thumb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid rgba(255,255,255,.15); }
.tray-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.75); color: #fff; cursor: pointer; line-height: 22px; padding: 0; }
.tray-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.camera-tray { position: absolute; bottom: calc(max(28px, env(safe-area-inset-bottom)) + 64px); left: 16px; right: 16px; justify-content: center; }
.camera-tray .tray-thumb { width: 64px; height: 64px; border-color: var(--gold); }
.camera-picker { position: absolute; top: calc(max(24px, env(safe-area-inset-top)) + 58px); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: rgba(0,0,0,.7); border-radius: 10px; font-size: 13px; font-weight: 600; }
.camera-picker select { max-width: min(70vw, 360px); }

/* Edit */
.edit-dialog { width: min(820px, 96vw); max-height: 92vh; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); }
.edit-dialog::backdrop { background: rgba(0,0,0,.7); }
.edit-dialog form { display: grid; grid-template-rows: auto 1fr auto; max-height: 92vh; }
.edit-head, .edit-foot { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.edit-foot { border-bottom: 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.edit-head h2 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-body { overflow-y: auto; padding: 18px; display: grid; gap: 16px; }
.spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid .span2 { grid-column: span 2; }
.grid label:has(textarea) { grid-column: 1 / -1; }
.image-strip { display: flex; gap: 8px; overflow-x: auto; }
.image-strip img { width: 96px; height: 96px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--gold-dim); color: var(--gold); font-size: 14px; }
.notice.err { background: rgba(255,107,107,.12); color: var(--red); }
.sources summary { cursor: pointer; color: var(--gold); font-weight: 600; }
.sources ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.sources a { color: var(--muted); word-break: break-all; }

/* Session timer + activity */
.station-badge { padding: 3px 10px; border-radius: 99px; background: var(--gold-dim); color: var(--gold); font-weight: 600; white-space: nowrap; }
.station-badge.none { background: rgba(255,107,107,.12); color: var(--red); }
.session-timer { display: flex; gap: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.session-timer b { color: var(--text); font-weight: 600; }
.session-timer .scanning b { color: var(--green); }
.activity-dialog { width: min(1000px, 96vw); }
.activity-inner { display: grid; grid-template-rows: auto 1fr; max-height: 92vh; }
.activity-controls { display: flex; align-items: center; gap: 8px; }
.activity-controls select { width: auto; padding: 6px 10px; }
.activity-section h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; background: var(--panel-2); }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: var(--green); }
.dot.scan { background: var(--gold); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .scan-panel { position: static; }
  .grid { grid-template-columns: 1fr 1fr; }
  .item { grid-template-columns: auto 52px 1fr; }
  .thumb { width: 52px; height: 52px; }
  .item-side { grid-column: 3; justify-items: start; grid-auto-flow: column; justify-content: start; align-items: center; gap: 10px; }
  #user-email { display: none; }
  .topbar-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
}

/* Phones: compact top bar, bigger touch targets, pinned Scan button */
.scan-fab { display: none; }
@media (max-width: 700px) {
  .topbar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); flex-wrap: nowrap; }
  .topbar .brand > span:last-child { display: none; }
  .topbar-right { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; min-width: 0; }
  .topbar-right::-webkit-scrollbar { display: none; }
  .topbar-right > * { flex: none; }
  .btn, .btn-sm { min-height: 44px; }
  .chip, .station-choice, .queue-tools select { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  .layout { padding: 10px 10px calc(96px + env(safe-area-inset-bottom)); }
  body:has(#app-view:not([hidden])) .scan-fab {
    display: inline-flex; align-items: center; gap: 8px;
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 6;
    min-height: 56px; padding: 0 22px; border: 0; border-radius: 99px;
    background: var(--gold); color: #120d00; font: inherit; font-weight: 800; font-size: 16px;
    box-shadow: 0 6px 22px rgba(0,0,0,.6);
  }
}

/* Live floor dashboard */
.floor-dialog { width: min(1200px, 98vw); }
.stat.alert { border-color: rgba(255,107,107,.6); }
.stat.alert .v { color: var(--red); }
.floor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.floor-card { display: grid; gap: 10px; align-content: start; background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 12px; padding: 14px; }
.floor-card.scan { border-left-color: var(--green); }
.floor-card.paused { border-left-color: var(--gold); }
.floor-card.idle { border-left-color: var(--red); }
.floor-card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.floor-card h3 { margin: 0; font-size: 17px; }
.floor-status { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.06); color: var(--muted); }
.floor-status.scan { color: var(--green); background: rgba(95,211,141,.12); }
.floor-status.paused { color: var(--gold); background: var(--gold-dim); }
.floor-status.idle { color: var(--red); background: rgba(255,107,107,.12); }
.floor-people { word-break: break-all; }
.floor-rates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.floor-rates div { background: var(--panel); border-radius: 8px; padding: 8px 4px; }
.floor-rates b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.floor-rates span { font-size: 11px; color: var(--muted); }
.floor-outcomes { display: flex; flex-wrap: wrap; gap: 6px; }
.floor-last { display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; }
.floor-thumb { width: 44px; height: 44px; flex: none; border-radius: 6px; object-fit: contain; background: #fff; }
.floor-thumb.none { display: inline-block; background: var(--panel); }
.floor-feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.floor-feed li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.floor-feed .grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }

/* Station picker + approvals */
button.station-badge { border: 0; cursor: pointer; font: inherit; }
.station-dialog { width: min(520px, 96vw); }
.station-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 12px 0; }
.station-choice { padding: 16px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.station-choice:hover { border-color: var(--gold); }
.station-choice.active { border-color: var(--gold); background: var(--gold-dim); color: var(--gold); }
.station-add { display: flex; gap: 8px; margin-top: 10px; }
.station-add input { flex: 1; }
.approvals.has-pending { border: 1px solid var(--gold); border-radius: 12px; padding: 12px; background: var(--gold-dim); }

/* Queue station filter */
.queue-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.queue-tools select { padding: 6px 10px; font-size: 13px; }

.quick-id { color: var(--blue); }

/* TikTok upload file + labels */
.tt-h { margin: 14px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tt-items { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; max-height: 38vh; overflow: auto; }
.tt-items li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.tt-items .toggle { align-items: flex-start; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }
.tt-upload { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.tt-upload label.btn { display: inline-flex; text-transform: none; letter-spacing: 0; cursor: pointer; }
.tt-admin { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.tt-result { margin-top: 14px; display: grid; gap: 10px; justify-items: start; }
.tt-result ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; display: grid; gap: 6px; }
.labels-dialog { width: min(520px, 96vw); }

/* Spreadsheet import */
.import-dialog { width: min(900px, 96vw); }
.import-pick { display: inline-flex; text-transform: none; letter-spacing: 0; cursor: pointer; margin: 6px 0; }
.import-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.import-options { display: grid; gap: 10px; }
.import-options .toggle { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); }
#import-preview td { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* AI cost table on the Live floor screen */
.ai-cost { width: 100%; border-collapse: collapse; font-size: 14px; }
.ai-cost th, .ai-cost td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line, rgba(255,255,255,.12)); }
.ai-cost th { font-weight: 600; opacity: .7; }
.ai-cost td:not(:first-child), .ai-cost th:not(:first-child) { text-align: right; }

/* TikTok videos (admin) */
.clips-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.clips-list li { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.clips-list li.is-hidden { opacity: .55; }
.clips-list img, .clip-thumb-empty { width: 54px; height: 96px; flex: none; border-radius: 6px; object-fit: cover; background: var(--panel); }
.clips-list .grow { flex: 1; min-width: 0; }
.clips-list a { color: var(--text); }
.clip-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.clip-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#clips-status .notice { display: block; line-height: 1.6; }
#clips-status .btn { margin-left: 6px; vertical-align: middle; }

/* Go live dialog */
.live-btn.is-live { background: var(--red); border-color: var(--red); color: #fff; animation: live-glow 1.6s infinite; }
@keyframes live-glow { 50% { box-shadow: 0 0 0 5px rgba(255,107,107,.25); } }
#live-status .notice { display: block; line-height: 1.6; }
.live-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.live-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.live-form [name="title"], .live-form [name="url"] { grid-column: 1 / -1; }
.live-form[hidden] { display: none; }
.live-go { font-size: 15px; padding: 12px 16px; }
.live-h3 { margin: 22px 0 4px; font-size: 16px; }
.live-list li { padding: 10px 12px; }
@media (max-width: 560px) { .live-form { grid-template-columns: 1fr; } }
