/* Gin Tattoo — Ads Report dashboard. Data-dense dark theme.
   Palette from dataviz skill (validated): blue #3987e5, aqua #199e70, amber #f5a623. */

:root {
  /* surfaces */
  --bg: #0d0f14;
  --surface: #14171e;
  --surface-2: #1a1e27;
  --surface-hover: #20242e;
  --border: #262b36;
  --border-soft: rgba(255, 255, 255, 0.06);
  /* ink */
  --text: #f2f3f5;
  --text-2: #a4abb8;
  --text-muted: #6b7280;
  /* brand + data */
  --accent: #f5a623;       /* gold — money/brand */
  --blue: #3987e5;         /* conversations */
  --aqua: #199e70;         /* replies (positive) */
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  /* chart chrome */
  --grid: #23272f;
  --axis: #383d48;
  /* geometry */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --sp: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; }

/* ---------- App shell (sidebar + main) ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100dvh; }
.sidebar {
  background: #0a0c11; border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 24px;
}
.side-brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--text); padding: 4px 8px; }
.side-mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #0d0f14; background: linear-gradient(135deg, var(--accent), #e08b1a); }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.side-brand-text b { font-size: 14px; }
.side-brand-text small { font-size: 11px; color: var(--text-muted); }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.side-link:hover { background: var(--surface); color: var(--text); }
.side-link.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.side-link.is-active svg { color: var(--accent); }
.main { min-width: 0; }
.main-inner { max-width: 1180px; margin: 0 auto; padding: 8px 28px 64px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num, .tabular { font-variant-numeric: tabular-nums; }

.app { max-width: 1240px; margin: 0 auto; padding: 0 24px 64px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0; margin-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; background: linear-gradient(var(--bg) 78%, transparent);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  color: #0d0f14;
  background: linear-gradient(135deg, var(--accent), #e08b1a);
  box-shadow: 0 2px 10px rgba(245,166,35,.25);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.topnav { display: flex; gap: 8px; }
.navlink {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--r-sm);
  color: var(--text-2); text-decoration: none; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface);
  transition: background .18s, color .18s, border-color .18s;
}
.navlink:hover { background: var(--surface-hover); color: var(--text); border-color: var(--axis); }

/* ---------- Filter bar ---------- */
.filterbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 20px 0 22px; flex-wrap: wrap;
}
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.seg {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  color: var(--text-2); font: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 14px; border-radius: 7px; transition: background .18s, color .18s;
}
.seg:hover { color: var(--text); }
.seg.is-active { background: var(--surface-hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.daterange { display: flex; align-items: center; gap: 8px; }
.daterange input[type="date"] {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 10px; font: inherit; font-size: 13px; color-scheme: dark;
}
.daterange .arrow { color: var(--text-muted); }
.btn-apply {
  appearance: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 16px; border-radius: var(--r-sm); border: 1px solid transparent;
  color: #0d0f14; background: var(--accent); transition: filter .18s, transform .05s;
}
.btn-apply:hover { filter: brightness(1.07); }
.btn-apply:active { transform: translateY(1px); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
}
.card-head h2 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.card-unit, .range-label { font-size: 12px; color: var(--text-muted); }

/* ---------- KPI cards ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px; position: relative; overflow: hidden;
  transition: border-color .18s, transform .18s;
}
.kpi:hover { border-color: var(--axis); transform: translateY(-1px); }
.kpi-top { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.kpi-icon {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.kpi-icon.blue  { color: var(--blue); background: color-mix(in srgb, var(--blue) 15%, transparent); }
.kpi-icon.aqua  { color: var(--aqua); background: color-mix(in srgb, var(--aqua) 16%, transparent); }
.kpi-icon.good  { color: var(--good); background: color-mix(in srgb, var(--good) 16%, transparent); }
.kpi-label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-value .unit { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 3px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ---------- Charts ---------- */
.charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px;
}
.chart-wrap { padding: 6px 14px 16px; height: 260px; position: relative; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.legend { display: flex; gap: 14px; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend .dot { width: 9px; height: 9px; border-radius: 3px; }

/* ---------- Table ---------- */
.tablewrap { overflow-x: auto; padding: 0 4px 6px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; background: var(--surface);
  color: var(--text-muted); font-weight: 600; font-size: 12px;
  text-align: right; padding: 10px 14px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
thead th.col-name { text-align: left; }
th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
th.sortable:hover { color: var(--text-2); }
th.is-sorted { color: var(--accent); }
th.is-sorted::after { content: " ↓"; }
tbody td { text-align: right; padding: 11px 14px; white-space: nowrap; border-bottom: 1px solid var(--border-soft); }
tbody td.col-name { text-align: left; white-space: normal; max-width: 260px; color: var(--text); font-weight: 500; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.muted { color: var(--text-muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.good { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.empty-row td { text-align: center; color: var(--text-muted); padding: 32px; }

/* skeleton shimmer */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 6px; color: transparent !important; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent); animation: sh 1.2s infinite; }
@keyframes sh { 100% { transform: translateX(100%); } }

/* ---------- Revenue section ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 34px 0 16px; }
.section-title { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.02em; display: flex; align-items: center; gap: 9px; }
.section-title::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); }
.month-select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 12px; font: inherit; font-size: 13px; color-scheme: dark; cursor: pointer;
}
.bysource { padding: 8px 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.src-row .src-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; }
.src-row .src-name { font-weight: 600; text-transform: capitalize; }
.src-row .src-name .src-cust { color: var(--text-muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.src-row .src-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.src-row .src-val .src-pct { color: var(--text-muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.src-bar { height: 9px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.src-bar > span { display: block; height: 100%; border-radius: 5px; }

.funnel { padding: 14px 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.fn-step { display: flex; align-items: center; gap: 12px; }
.fn-bar { flex: 1; height: 34px; border-radius: 8px; display: flex; align-items: center; padding: 0 12px; font-size: 13px; font-weight: 600; color: #06070a; }
.fn-meta { min-width: 108px; text-align: right; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.fn-label { position: absolute; }

.src-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.src-tag.ads { color: var(--blue); background: color-mix(in srgb, var(--blue) 16%, transparent); }
.src-tag.social { color: #d55181; background: color-mix(in srgb, #d55181 16%, transparent); }
.src-tag.walk { color: var(--text-2); background: var(--surface-2); }
.src-tag.artist { color: var(--aqua); background: color-mix(in srgb, var(--aqua) 16%, transparent); }
.src-tag.other { color: var(--text-muted); background: var(--surface-2); }
.chat-link { color: var(--blue); text-decoration: none; font-size: 12px; }
.chat-link:hover { text-decoration: underline; }
.rev-note { font-size: 12px; color: var(--warn); }

/* ---------- CMS form ---------- */
.form-card { padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.col-span-2 { grid-column: span 2; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field label .req { color: var(--crit); }
.field input, .field select, .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px 11px; font: inherit; font-size: 13px; color-scheme: dark; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent);
}
.field .hint { font-size: 11px; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.btn { appearance: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 9px 18px; border-radius: var(--r-sm); border: 1px solid transparent; transition: filter .15s, background .15s; }
.btn-primary { color: #0d0f14; background: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: transparent; color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); padding: 5px 10px; font-size: 12px; }
.btn-danger:hover { background: color-mix(in srgb, var(--crit) 14%, transparent); }
.btn-icon { background: transparent; border: 0; color: var(--text-muted); cursor: pointer; padding: 4px 8px; font-size: 13px; }
.btn-icon:hover { color: var(--text); }
.total-preview { margin-left: auto; font-size: 13px; color: var(--text-2); }
.total-preview b { color: var(--accent); font-size: 17px; font-variant-numeric: tabular-nums; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 11px 18px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.ok { border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.toast.err { border-color: color-mix(in srgb, var(--crit) 50%, transparent); }
.pin-gate { max-width: 360px; margin: 60px auto; text-align: center; }
.pin-gate h2 { font-size: 16px; }
.pin-gate input { text-align: center; letter-spacing: 4px; font-size: 18px; margin: 14px 0; }
.match-note { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.match-hit { color: var(--aqua); }

/* ---------- Chat viewer ---------- */
.chat-layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 16px;
  height: calc(100dvh - 150px); min-height: 420px;
}
.chat-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); display: flex; flex-direction: column; overflow: hidden; }
.chat-search { padding: 12px; border-bottom: 1px solid var(--border-soft); }
.chat-search input {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px 12px; font: inherit; font-size: 13px;
}
.chat-search input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background .12s; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-hover); box-shadow: inset 2px 0 0 var(--accent); }
.conv-item .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-item .name { font-weight: 600; font-size: 13px; }
.conv-item .time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.conv-item .snip { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.conv-item .cnt { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.chat-thread { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); display: flex; flex-direction: column; overflow: hidden; }
.thread-head { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); font-weight: 600; font-size: 14px; }
.thread-head .sub { font-weight: 400; font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.thread-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 72%; padding: 9px 13px; border-radius: 14px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.bubble.them { background: var(--surface-2); border: 1px solid var(--border-soft); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: color-mix(in srgb, var(--blue) 22%, var(--surface-2)); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .t { display: block; font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.chat-empty { color: var(--text-muted); text-align: center; margin: auto; padding: 40px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; overflow-x: auto; padding: 12px 14px; }
  .side-brand { flex-shrink: 0; }
  .side-brand-text { display: none; }
  .side-nav { flex-direction: row; gap: 4px; }
  .side-link span { display: none; }
  .side-link { padding: 10px; }
  .main-inner { padding: 8px 16px 48px; }
  .charts { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 42vh; }
  .chat-thread { min-height: 60vh; }
  .field.col-span-2 { grid-column: span 1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
