:root {
  --ink: #151615;
  --muted: #73766f;
  --paper: #f4f2ed;
  --panel: #fbfaf7;
  --line: #dfddd5;
  --lime: #caff48;
  --lime-dark: #71920e;
  --violet: #7b61ff;
  --orange: #ff8a4c;
  --blue: #48a6ff;
  --shadow: 0 18px 50px rgba(35, 37, 32, 0.07);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 4%, rgba(202, 255, 72, .16), transparent 25rem),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 30px 22px;
  display: flex; flex-direction: column; background: #171916; color: white;
}
.brand { color: white; text-decoration: none; font-weight: 850; font-size: 21px; letter-spacing: -.7px; display: flex; align-items: center; gap: 10px; }
.brand > span:last-child span { color: var(--lime); }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--lime); color: var(--ink); }
nav { margin-top: 52px; display: grid; gap: 7px; }
nav a { color: #9b9e96; text-decoration: none; padding: 12px 13px; border-radius: 12px; display: flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 650; }
nav a:hover, nav a.active { color: white; background: #292c27; }
nav a.active span { color: var(--lime); }
.sidebar-note { margin-top: auto; padding: 15px; border: 1px solid #33372f; background: #22241f; border-radius: 14px; display: flex; align-items: center; gap: 10px; }
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note strong { font-size: 12px; }
.sidebar-note small { color: #858980; margin-top: 2px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 5px rgba(202,255,72,.12); }

main { width: min(1440px, 100%); margin: 0 auto; padding: 38px 42px 70px; overflow: hidden; }
header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(31px, 4vw, 52px); letter-spacing: -2.5px; line-height: .98; max-width: 670px; }
h2 { margin-bottom: 0; font-size: 21px; letter-spacing: -.55px; }
.eyebrow, .section-kicker { color: var(--lime-dark); font-weight: 850; letter-spacing: 1.7px; font-size: 10px; margin-bottom: 9px; }
.subtitle, .muted { color: var(--muted); }
.subtitle { margin: 0; }
.header-actions { display: flex; align-items: end; gap: 10px; }
.period-control { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 750; }
select, .primary-button, .secondary-button { border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; background: var(--panel); color: var(--ink); }
.primary-button { background: var(--ink); color: white; border-color: var(--ink); font-weight: 750; display: flex; gap: 8px; }
.primary-button:hover { background: #30322d; }
.secondary-button { font-weight: 750; }

.status-banner { padding: 13px 16px; border-radius: 13px; margin-bottom: 18px; font-size: 13px; background: #fff4d8; color: #725710; border: 1px solid #f1d88c; }
.status-banner.error { background: #ffebe7; border-color: #ffc5ba; color: #8e3022; }
.hidden { display: none !important; }

.account-workspace { display: flex; gap: 12px; align-items: stretch; margin-bottom: 14px; min-height: 88px; }
#account-list { display: flex; gap: 10px; flex: 1; min-width: 0; }
.account-option { flex: 1; min-width: 0; text-align: left; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: flex; align-items: center; gap: 13px; box-shadow: var(--shadow); }
.account-option:hover { border-color: #b9b7af; }
.account-option.active { border-color: var(--lime-dark); box-shadow: 0 0 0 2px rgba(113,146,14,.12), var(--shadow); }
.account-option.error { border-color: #e2a99e; }
.account-avatar { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; font-weight: 900; font-size: 17px; background: var(--lime); overflow: hidden; }
.account-avatar.secondary { background: #d9d1ff; }
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-copy { min-width: 0; }
.account-copy strong, .account-copy span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-copy span { color: var(--muted); margin-top: 4px; font-size: 13px; }
.account-badge { margin-left: auto; padding: 7px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--muted); }
.account-option.active .account-badge { background: var(--lime); border-color: var(--lime); color: var(--ink); font-weight: 800; }
.add-account-button { flex: 0 0 145px; border: 1px dashed #aaaDA4; border-radius: 18px; background: rgba(251,250,247,.55); color: var(--muted); font-weight: 750; }
.add-account-button:hover:not(:disabled) { background: var(--panel); border-color: var(--lime-dark); color: var(--ink); }
.add-account-button:disabled { cursor: not-allowed; opacity: .6; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric-card, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.metric-card { padding: 19px; min-height: 152px; position: relative; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; width: 90px; height: 90px; border-radius: 50%; right: -40px; bottom: -45px; background: rgba(202,255,72,.22); }
.metric-label { color: var(--muted); text-transform: uppercase; letter-spacing: 1.1px; font-size: 10px; font-weight: 800; }
.metric-value { font-size: 31px; letter-spacing: -1.5px; font-weight: 850; margin: 16px 0 13px; }
.metric-note { color: var(--muted); font-size: 11px; }
.compare-row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.compare-row strong { color: var(--ink); }
.compare-bar { height: 5px; border-radius: 9px; background: #e9e7e0; margin-top: 7px; overflow: hidden; display: flex; }
.compare-bar span:first-child { background: var(--lime-dark); }
.compare-bar span:last-child { background: var(--violet); }

.panel { padding: 23px; margin-bottom: 14px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-heading.compact { margin-bottom: 15px; }
.segmented { border: 1px solid var(--line); border-radius: 11px; padding: 3px; background: #efede7; }
.segmented button { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 7px 11px; font-size: 12px; }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.chart-legend { display: flex; gap: 18px; font-size: 12px; margin-bottom: 8px; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.chart-wrap { min-height: 295px; overflow: hidden; }
.chart-svg { width: 100%; height: 295px; display: block; }
.chart-grid { stroke: #deddd6; stroke-width: 1; stroke-dasharray: 3 5; }
.chart-label { fill: #898c84; font-size: 10px; }
.chart-line-a { stroke: var(--lime-dark); }
.chart-line-b { stroke: var(--violet); }
.chart-area-a { fill: url(#areaA); }
.chart-area-b { fill: url(#areaB); }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

.split-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; }
.mix-row { display: grid; grid-template-columns: 115px 1fr 45px; gap: 12px; align-items: center; margin: 16px 0; font-size: 12px; }
.mix-track { height: 9px; border-radius: 9px; background: #eceae4; overflow: hidden; }
.mix-fill { height: 100%; border-radius: inherit; }
.mix-row strong { text-align: right; }
.insight-item { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.insight-item:last-child { border-bottom: 0; }
.insight-icon { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 10px; background: var(--lime); display: grid; place-items: center; }
.insight-item p { margin: 3px 0 0; color: var(--muted); line-height: 1.45; font-size: 12px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { text-align: left; color: var(--muted); font-size: 10px; letter-spacing: .9px; text-transform: uppercase; padding: 0 12px 11px; }
td { padding: 13px 12px; border-top: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
.post-cell { display: flex; align-items: center; gap: 10px; max-width: 390px; }
.post-thumb { width: 40px; height: 40px; border-radius: 10px; background: #e5e2d9; object-fit: cover; flex: 0 0 auto; display: grid; place-items: center; color: #95988f; }
.post-copy { overflow: hidden; }
.post-copy a { color: var(--ink); font-weight: 700; text-decoration: none; display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.post-copy small { color: var(--muted); }
.format-pill { background: #edebe5; border-radius: 999px; padding: 6px 8px; font-size: 10px; font-weight: 750; }
.account-indicator { display: inline-flex; align-items: center; gap: 6px; }
.account-indicator::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--account-color); }

.api-panel { background: #1c1f1a; color: white; border-radius: 18px; padding: 23px; display: grid; grid-template-columns: 1fr auto; gap: 12px 24px; align-items: center; }
.api-panel p { color: #999e94; margin-bottom: 0; }
.api-panel .section-kicker { color: var(--lime); margin-bottom: 8px; }
.api-panel .secondary-button { background: var(--lime); border-color: var(--lime); }
#test-result { grid-column: 1 / -1; font-size: 12px; color: #c6cabf; }
.test-list { display: flex; flex-wrap: wrap; gap: 8px; }
.test-chip { border: 1px solid #3f443a; border-radius: 999px; padding: 6px 9px; }
.test-chip.ok { border-color: #6e8b27; color: var(--lime); }
.test-chip.bad { border-color: #894c40; color: #ff9d8c; }

dialog { width: min(500px, calc(100% - 28px)); border: 0; border-radius: 20px; padding: 0; color: var(--ink); background: var(--panel); box-shadow: 0 30px 90px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(15,17,14,.62); backdrop-filter: blur(4px); }
#oauth-form { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: white; font-size: 20px; }
.form-note { color: var(--muted); font-size: 12px; line-height: 1.5; padding: 11px 13px; background: #efede7; border-radius: 11px; }
#oauth-form label { display: grid; gap: 7px; margin: 14px 0; font-size: 12px; font-weight: 750; }
#oauth-form input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); }
#oauth-form input:focus { outline: 2px solid rgba(113,146,14,.25); border-color: var(--lime-dark); }
.callback-box { padding: 11px 13px; border: 1px dashed #aaaDA4; border-radius: 11px; background: white; overflow: hidden; }
.callback-box span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 6px; }
.callback-box code { display: block; font-size: 11px; white-space: nowrap; overflow-x: auto; padding-bottom: 2px; }
.form-error { color: #8e3022; background: #ffebe7; border: 1px solid #ffc5ba; border-radius: 10px; padding: 10px 12px; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

.loading-card { background: linear-gradient(90deg, #ebe9e3 25%, #f8f7f2 50%, #ebe9e3 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 18px; }
.skeleton { background: linear-gradient(90deg, #ebe9e3 25%, #f8f7f2 50%, #ebe9e3 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 25px 13px; align-items: center; }
  .brand > span:last-child, nav a:not(.active) { font-size: 0; }
  nav a { justify-content: center; }
  nav a span { font-size: 18px; }
  .sidebar-note div { display: none; }
  .sidebar-note { padding: 13px; }
  main { padding: 30px 24px 60px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .split-grid { grid-template-columns: 1fr; }
  .account-workspace { align-items: stretch; }
  #account-list { flex-direction: column; }
}

@media (max-width: 660px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px 18px; flex-direction: row; justify-content: space-between; }
  .brand > span:last-child { display: block; }
  nav { display: none; }
  .sidebar-note { margin: 0; }
  main { padding: 25px 15px 48px; }
  header { align-items: flex-start; flex-direction: column; }
  h1 { letter-spacing: -1.8px; }
  .header-actions { width: 100%; }
  .period-control { flex: 1; }
  select { width: 100%; }
  .account-workspace { flex-direction: column; }
  #account-list { width: 100%; }
  .add-account-button { flex-basis: 58px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .panel { padding: 18px 14px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .api-panel { grid-template-columns: 1fr; }
  .api-panel .secondary-button { width: 100%; }
  #test-result { grid-column: 1; }
}
