* { box-sizing: border-box; }
:root {
  --bg: #0f1117;
  --panel: #171b24;
  --panel-2: #1f2533;
  --border: #2a3142;
  --text: #eef1f7;
  --muted: #9aa3b5;
  --blue: #3b82f6;
  --blue-hover: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
}

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

.hidden { display: none !important; }
.full-width { width: 100%; }
.flex-1 { flex: 1; }
.w-auto { width: auto; }
.w-240 { width: 240px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.align-end { display: flex; align-items: flex-end; }
.muted { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }
.hint { color: var(--muted); font-size: 12px; }
.hint.ok { color: var(--green); }
.hint.err { color: #f87171; }
code { background: #10131b; border: 1px solid var(--border); padding: 2px 6px; border-radius: 5px; font-size: 12px; color: #93c5fd; }

/* Login Gate */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #1b2438 0%, #0f1117 65%);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.logo-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff; font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.logo-mark.sm { width: 34px; height: 34px; font-size: 17px; border-radius: 9px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-domain { font-size: 12.5px; color: #60a5fa; font-weight: 500; }
.login-desc { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.login-note { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.routing-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600;
}
.routing-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.routing-pill.free .dot { background: var(--green); }
.routing-pill.paid .dot { background: var(--amber); }

.user-chip {
  display: flex; align-items: center; gap: 6px;
  background: #121620; border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px;
}
.role-badge {
  background: rgba(59,130,246,0.2); color: #93c5fd;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
}

/* Tabs */
.tabs-bar {
  display: flex; gap: 6px; padding: 10px 24px 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  background: transparent; border: none; color: var(--muted);
  padding: 10px 16px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: #60a5fa; border-bottom-color: #3b82f6; }

/* Main */
.main-content { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; color: #fff; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.progress-track { height: 6px; background: #10131b; border-radius: 999px; margin-top: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--blue); border-radius: 999px; transition: width 0.3s; }
.progress-fill.green { background: var(--green); }
.progress-fill.warn { background: var(--amber); }

/* Cards & Grids */
.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card h3 { margin: 0; font-size: 15.5px; font-weight: 700; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Chart */
.chart-box {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 8px; height: 180px; padding: 16px 8px 6px;
  background: #12151e; border: 1px solid var(--border); border-radius: 10px;
  margin-top: 12px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-val { font-size: 11px; color: #cbd5e1; margin-bottom: 4px; }
.bar-stack { width: 100%; max-width: 38px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px 6px 2px 2px; overflow: hidden; background: #1c2230; min-height: 4px; }
.bar-paid { background: linear-gradient(180deg, #60a5fa, #2563eb); width: 100%; }
.bar-free { background: linear-gradient(180deg, #34d399, #059669); width: 100%; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; }

/* Routing Flow */
.flow-steps { display: flex; flex-direction: column; gap: 8px; }
.flow-step {
  display: flex; align-items: center; gap: 12px;
  background: #12151e; border: 1px solid var(--border); border-radius: 10px; padding: 12px;
}
.flow-step.active-tier { border-color: var(--green); background: rgba(16,185,129,0.08); }
.flow-step.active-paid { border-color: var(--amber); background: rgba(245,158,11,0.08); }
.flow-badge {
  background: rgba(16,185,129,0.2); color: #34d399;
  font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 6px;
}
.flow-badge.paid { background: rgba(245,158,11,0.2); color: #fbbf24; }
.flow-title { font-weight: 600; font-size: 13.5px; }
.flow-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.flow-arrow { text-align: center; font-size: 11.5px; color: var(--muted); }

/* Forms & Buttons */
.field-label { display: block; font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; background: #10131b; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font-size: 13px; font-family: inherit;
}
.textarea { resize: vertical; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; } }
.google-box { background: #12151e; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.google-status-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.switch-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 8px; padding: 9px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-lg { padding: 12px 18px; font-size: 14.5px; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #293142; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: #fff; }
.btn-danger { background: rgba(239,68,68,0.16); color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
.btn-danger:hover { background: rgba(239,68,68,0.28); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 6px; }

/* History Grid */
.history-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.hist-card {
  background: #12151e; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; display: flex; flex-direction: column;
}
.hist-thumb {
  width: 100%; height: 165px; object-fit: cover; cursor: pointer;
  background: #0b0d12;
}
.hist-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.hist-prompt {
  font-size: 12.5px; color: #e2e8f0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hist-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 5px; }
.tag-free { background: rgba(16,185,129,0.2); color: #34d399; }
.tag-paid { background: rgba(245,158,11,0.2); color: #fbbf24; }
.tag-meta { background: #1e2433; color: #94a3b8; }
.hist-foot { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 4px; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.84);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; padding: 24px;
}
.lightbox-inner { position: relative; max-width: 92vw; max-height: 92vh; text-align: center; }
.lightbox-inner img { max-width: 90vw; max-height: 78vh; border-radius: 10px; border: 1px solid var(--border); }
.lightbox-close {
  position: absolute; top: -14px; right: -14px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel); color: #fff; cursor: pointer;
}
.lightbox-caption { margin-top: 10px; color: #cbd5e1; font-size: 13px; max-width: 820px; }
