:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7480;
  --line: #e3e7ec;
  --accent: #2b6cb0;
  --accent-ink: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 600; }
.nav { display: flex; align-items: center; gap: 16px; }
.nav a { color: var(--accent); text-decoration: none; }
.nav .who { color: var(--muted); font-size: 13px; }
.nav .logout { color: var(--muted); }

.content { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.placeholder { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.muted { color: var(--muted); }

.flash {
  max-width: 1100px; margin: 12px auto 0; padding: 10px 14px;
  background: #fdecea; border: 1px solid #f5c6c0; color: #8a1c14; border-radius: 8px;
}

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: 320px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; box-shadow: 0 6px 24px rgba(0,0,0,.06);
}
.login-card h1 { margin: 0 0 2px; font-size: 20px; }
.login-card .sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.login-card input {
  width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 15px;
}
.login-card button {
  width: 100%; margin-top: 6px; padding: 10px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 15px; cursor: pointer;
}
.login-card .flash { margin: 0 0 14px; }

/* ---- Global controls ---- */
.controls {
  max-width: 1100px; margin: 16px auto 0; padding: 0 20px;
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
}
.ctrl-group { display: flex; align-items: center; gap: 6px; }
#brand-tabs .tab {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
#brand-tabs .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.date-ctrl .arrow {
  border: 1px solid var(--line); background: var(--card); width: 30px; height: 30px;
  border-radius: 8px; cursor: pointer; font-size: 18px; line-height: 1;
}
#date-picker { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.date-note { color: var(--muted); font-size: 12px; }

/* ---- States ---- */
.state { padding: 14px 4px; color: var(--muted); font-size: 14px; }
.state.error { color: #8a1c14; }
.state.loading { color: var(--muted); }
.neg { color: #e03131; } .pos { color: #2f9e44; }
.muted { color: var(--muted); }

/* ---- P&L strip ---- */
.pnl-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 20px; }
.pnl-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.pnl-card.no-data { opacity: .85; }
.pnl-top { display: flex; align-items: center; justify-content: space-between; }
.pnl-brand { font-weight: 600; }
.pnl-hero { font-size: 34px; font-weight: 700; line-height: 1.1; margin: 6px 0 2px; }
.pnl-sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.pnl-sub strong { color: var(--ink); }
.pnl-mtd { margin-top: 10px; color: var(--muted); font-size: 12px; }
.pending-note { margin-top: 6px; font-size: 12px; color: #b8860b; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.metric .m-k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.metric .m-v { font-size: 14px; font-weight: 600; }

/* ---- Badges & chips ---- */
.badge { display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: 999px; margin-left: 6px; }
.badge.posture { font-weight: 600; }
.posture-off { background: #fde2e1; color: #b02a1e; }
.posture-hold { background: #fff3cd; color: #8a6d00; }
.posture-on { background: #d3f9d8; color: #2b8a3e; }
.badge.src { background: #eef1f5; color: #566; }
.src-live { background: #e7f5ff; color: #1971c2; }
.src-backfill { background: #f3f0ff; color: #6741d9; }
.applied-yes { background: #d3f9d8; color: #2b8a3e; }
.applied-no { background: #eef1f5; color: #667; }
.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.act-scale { background: #d3f9d8; color: #2b8a3e; }
.act-trim { background: #fff3cd; color: #8a6d00; }
.act-pause { background: #fde2e1; color: #b02a1e; }
.act-watch { background: #e7f5ff; color: #1971c2; }
.act-none { background: #eef1f5; color: #667; }

/* ---- Panels ---- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.group-toggle { font-size: 13px; color: var(--muted); }

/* ---- Board table ---- */
.ads-board { overflow-x: auto; }
table.board { width: 100%; border-collapse: collapse; font-size: 13px; }
table.board th, table.board td { padding: 7px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.board th { color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--card); }
table.board th.l, table.board td.l { text-align: left; }
table.board th.sorted { color: var(--accent); }
table.board tr.ad-row:hover { background: #f8fafc; cursor: pointer; }
.group-row td { background: #f1f3f5; font-size: 12px; text-align: left; }
.group-row .g-name { font-weight: 600; }
.group-row .g-count { color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; }
.cpm-arrow.up { color: #e03131; } .cpm-arrow.down { color: #2f9e44; } .cpm-arrow.flat { color: var(--muted); }
.copy-chip { border: 1px dashed var(--line); background: transparent; color: var(--accent); font: inherit; font-size: 12px; padding: 1px 6px; border-radius: 6px; cursor: pointer; }
.copy-chip.copied { color: #2b8a3e; border-color: #2b8a3e; }

/* row expand — creative */
.expand-row td { background: #f8fafc; text-align: left; white-space: normal; }
.creative { display: flex; gap: 14px; padding: 6px 2px; }
.creative .thumb { width: 130px; height: 130px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.creative-body { font-size: 13px; }
.cf { margin: 2px 0; } .cf-k { color: var(--muted); } .cf-v { }

/* ---- Recs ---- */
.rec-block { border-bottom: 1px solid var(--line); padding: 12px 0; }
.rec-block:last-child { border-bottom: 0; }
.rec-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.rec-brand { font-weight: 600; }
.rec-counts { color: var(--muted); font-size: 12px; margin-left: 6px; }
.rec-headline { margin: 8px 0; font-size: 13px; }
.rec-actions { list-style: none; padding: 0; margin: 6px 0 0; }
.rec-actions li { padding: 8px 0; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rec-actions .budget { font-size: 12px; color: var(--muted); }
.rec-detail { flex-basis: 100%; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- Nav active + freshness banner ---- */
.nav a.on { font-weight: 700; text-decoration: underline; }
.freshness-banner {
  max-width: 1100px; margin: 12px auto 0; padding: 9px 14px;
  background: #fff4e6; border: 1px solid #ffd8a8; color: #b8860b; border-radius: 8px; font-size: 13px;
}

/* ---- Range bar + charts (Trends) ---- */
.range-bar { max-width: 1100px; margin: 4px auto 8px; display: flex; align-items: center; gap: 12px; }
.range-label { color: var(--muted); font-size: 13px; }
.chart-wrap { position: relative; height: 320px; }
.ad-picker { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; max-width: 360px; }

/* ---- Recs log expand ---- */
.recs-log { overflow-x: auto; }
.rec-expand { padding: 8px 2px; }
.expand-row td { background: #f8fafc; text-align: left; white-space: normal; }
