:root {
  --bg: #090b10;
  --surface: #111520;
  --surface-2: #171d2c;
  --card: #151b29;
  --card-hover: #1b2336;
  --border: #263149;
  --text: #eef2ff;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.14);
  --indigo: #6366f1;
  --indigo-bg: rgba(99, 102, 241, 0.16);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.15);
  --cyan: #06b6d4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #93c5fd;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.text-emerald { color: var(--emerald); }
.text-amber { color: var(--amber); }
.text-rose { color: var(--rose); }
.text-muted { color: var(--text-muted); }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 24px;
  background: rgba(9, 11, 16, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

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

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-sub {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

.brand-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 12px var(--emerald);
}

.badge-v2 {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--indigo-bg);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tab.active {
  background: var(--indigo);
  color: #fff;
}

.kpi-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  display: flex;
  flex-direction: column;
  min-width: 78px;
}

.kpi-pill.kpi-money {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.06);
}

.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.kpi-pill strong {
  font-size: 14px;
  font-weight: 700;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text);
  background: var(--surface-2);
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--indigo);
  color: #fff;
}

.btn-emerald {
  background: var(--emerald);
  color: #032318;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-danger {
  background: var(--rose-bg);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fda4af;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}

.scan-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
}

.scanning .scan-dot {
  animation: pulse 1s infinite;
  background: var(--amber);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.4; }
}

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--indigo);
}

/* Banners & Main */
.banner {
  margin: 14px 24px 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.banner-amber {
  background: var(--amber-bg);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.banner-indigo {
  background: var(--indigo-bg);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #e0e7ff;
}

.banner-actions {
  display: flex;
  gap: 8px;
}

.main-content {
  padding: 20px 24px 48px;
  max-width: 1520px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge-emerald { background: var(--emerald-bg); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.3); }
.badge-indigo { background: var(--indigo-bg); color: #a5b4fc; border-color: rgba(99, 102, 241, 0.3); }
.badge-amber { background: var(--amber-bg); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }
.badge-rose { background: var(--rose-bg); color: #fda4af; border-color: rgba(244, 63, 94, 0.3); }
.badge-neutral { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.25); }

/* Filter Bar */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr repeat(6, minmax(120px, 1fr));
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 18px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Signals Grid & Cards */
.signals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.signal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.signal-card:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.55);
  background: var(--card-hover);
}

.card-thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0d111a;
  overflow: hidden;
}

.card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: linear-gradient(135deg, #131a2b, #1d253b);
  color: #a5b4fc;
  font-weight: 700;
  font-size: 15px;
}

.thumb-top-left {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
}

.thumb-top-right {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.outlier-pill {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(6, 78, 59, 0.92);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.55);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.outlier-pill.hot {
  background: rgba(124, 45, 18, 0.94);
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.65);
}

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title a {
  color: var(--text);
}

.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: rgba(9, 11, 16, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.metric-cell {
  display: flex;
  flex-direction: column;
}

.metric-cell span {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.metric-cell strong {
  font-size: 12px;
  font-weight: 700;
}

.card-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 4px;
}

/* Panels & Layouts */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2, .panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Arbitrage */
.arb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}

.arb-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.arb-card.untapped {
  border-color: rgba(16, 185, 129, 0.45);
}

.region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip-toggle.selected {
  background: var(--indigo-bg);
  border-color: var(--indigo);
  color: #c7d2fe;
}

/* Pipeline Kanban */
.pipeline-summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.stat-box span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-box strong {
  display: block;
  font-size: 20px;
  margin-top: 2px;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(230px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
}

.kanban-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.kanban-card h4 {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
}

.kanban-hook {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  border-left: 2px solid var(--indigo);
  padding: 5px 8px;
  border-radius: 4px;
}

.kanban-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 4px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 60;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(580px, 96vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 70;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.drawer-header h2 {
  margin: 6px 0 0;
  font-size: 17px;
  line-height: 1.35;
}

.drawer-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.drawer-box h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #c7d2fe;
}

.code-box {
  background: #06080d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--emerald);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 360px;
}

.toast.error {
  border-left-color: var(--rose);
}

.empty-state {
  text-align: center;
  padding: 46px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

@media (max-width: 1024px) {
  .filter-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }
  .main-content {
    padding: 14px 14px 40px;
  }
  .filter-bar {
    grid-template-columns: 1fr;
  }
}

/* Reel Studio (LiveAV / LiveGPU / FFmpeg) */
.studio-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 18px;
  align-items: start;
}

.shot-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shot-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
}

.shot-preview-box {
  width: 140px;
  aspect-ratio: 9 / 16;
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.shot-preview-box img,
.shot-preview-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.shot-code-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(9, 11, 16, 0.85);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.vertical-master-wrap {
  width: min(320px, 100%);
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  background: #06080d;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.vertical-master-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.auth-box {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

@media (max-width: 1024px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shot-card {
    grid-template-columns: 1fr;
  }
  .shot-preview-box {
    width: 180px;
    margin: 0 auto;
  }
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* LAN Auth Screen & User Pill */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.16), transparent 55%), var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--rose-bg);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fecdd3;
  font-size: 12px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.user-pill strong {
  margin-right: 4px;
}
