/* Select Media Financial Suite — UI */
:root {
  --page: #f4f6f9;
  --surface: #ffffff;
  --ink: #1b2330;
  --muted: #5a6575;
  --faint: #8a94a3;
  --line: #dde2e9;
  --line-soft: #ebeef3;
  --accent: #1f4fd1;
  --accent-ink: #163a9c;
  --accent-wash: #eaf0fd;
  --good: #0f7a4a;
  --good-wash: #e5f4ec;
  --bad: #b42318;
  --bad-wash: #fdecea;
  --warn: #9a5b00;
  --warn-wash: #fdf3e1;
  --entity: #1f4fd1;          /* overridden per company */
  --entity-wash: #eaf0fd;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
body.entity-SM { --entity: #0b7a75; --entity-wash: #e3f3f2; }
body.entity-SMMP { --entity: #7a3a96; --entity-wash: #f3eaf7; }
body.entity-ALL { --entity: #2f3a4a; --entity-wash: #eceff3; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: #1b2330; color: #c9d1dc; padding: 0 0 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; color: #fff; font-weight: 650; font-size: 15px; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--entity); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.nav-group { padding: 10px 10px 2px; }
.nav-group > span { display: block; padding: 0 8px 4px; font-size: 12px; color: #7f8ba0; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 5px; color: #c9d1dc; }
.nav a:hover { background: #263142; color: #fff; text-decoration: none; }
.nav a.active { background: #2c3a50; color: #fff; box-shadow: inset 3px 0 0 var(--entity); }
.nav .count { font-size: 11px; background: #33415a; color: #dfe5ee; padding: 0 6px; border-radius: 9px; }

.main { min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: stretch; gap: 16px; position: sticky; top: 0; z-index: 20; }
.entity-band { background: var(--entity); color: #fff; display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 20px; min-width: 0; }
.entity-band form { display: flex; align-items: center; gap: 8px; margin: 0; }
.entity-band label { font-size: 12px; color: rgba(255,255,255,.85); font-weight: 500; }
.entity-band select { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 5px; padding: 5px 8px; font: inherit; font-weight: 600; max-width: 330px; }
.entity-band select option { color: var(--ink); }
.entity-tag { font-size: 12px; background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; padding: 0 20px; }
.topbar-right form { margin: 0; }
.menu-toggle { display: none; }
.content { padding: 22px 28px 48px; max-width: 1280px; }

/* ---------- page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel, .panel + .grid, .grid + .panel, .grid + .grid, .kpis + .grid { margin-top: 16px; }
.grid > .panel, .grid > aside > .panel:first-child { margin-top: 0; }
aside > .panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.panel-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

/* KPI strip — figures first, labels quiet */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.kpi { padding: 14px 16px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.kpi:nth-child(4n) { border-right: 0; }
.kpi .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.kpi .s { font-size: 12px; color: var(--faint); }
.kpi a { color: inherit; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: #f8f9fb; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfd; }
tr.total td { font-weight: 650; border-top: 1px solid var(--line); background: #f8f9fb; }
tr.subtotal td { font-weight: 600; }
tr.group td { background: #f3f5f8; font-weight: 600; color: var(--muted); font-size: 12.5px; }
tr.muted-row td { color: var(--faint); }
td.indent { padding-left: 28px; }
.compact th, .compact td { padding: 5px 10px; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- badges, alerts */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.badge-gray { background: #eef0f3; color: #4b5563; }
.badge-blue { background: var(--accent-wash); color: var(--accent-ink); }
.badge-green { background: var(--good-wash); color: var(--good); }
.badge-red { background: var(--bad-wash); color: var(--bad); }
.badge-amber { background: var(--warn-wash); color: var(--warn); }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash-success { background: var(--good-wash); border-color: #b9e0cb; color: #0b5c38; }
.flash-error { background: var(--bad-wash); border-color: #f4c3bd; color: #8c1c13; }
.flash-info { background: var(--accent-wash); border-color: #c8d6f7; color: var(--accent-ink); }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { border-bottom: 1px solid var(--line-soft); }
.alerts li:last-child { border-bottom: 0; }
.alerts a { display: flex; gap: 10px; padding: 10px 16px; color: var(--ink); }
.alerts a:hover { background: #fafbfd; text-decoration: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; }
.dot-red { background: var(--bad); } .dot-amber { background: #d18a00; } .dot-blue { background: var(--accent); }
.note { background: #f8f9fb; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 10px 12px; color: var(--muted); font-size: 13px; }
.note-warn { background: var(--warn-wash); border-color: #f2dcae; color: #6b4300; }

/* posting banner: which books will this touch */
.posting-to { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: var(--radius); background: var(--entity-wash); border: 1px solid color-mix(in srgb, var(--entity) 30%, transparent); margin-bottom: 16px; }
.posting-to b { color: var(--entity); }
.posting-to .swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--entity); }

/* ---------- forms */
form { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span2 { grid-column: span 2; }
.field.span3 { grid-column: span 3; }
.field.span4 { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 550; color: #374151; }
.hint { font-size: 12px; color: var(--faint); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfd5de; border-radius: 5px; padding: 7px 9px; min-height: 36px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-wash); outline-offset: 0; }
input.amount { text-align: right; font-variant-numeric: tabular-nums; }
.field-error { color: var(--bad); font-size: 12.5px; margin: 0; }
.has-error input, .has-error select { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line-soft); background: #fbfbfc; border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap; }
.inline-form { display: inline; }
fieldset { border: 0; padding: 0; margin: 0; }

/* line items */
.lines td { padding: 6px 6px; vertical-align: middle; }
.lines th { padding: 6px; }
.lines input, .lines select { min-height: 34px; padding: 5px 7px; }
.lines .del { background: none; border: 0; color: var(--faint); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.lines .del:hover { color: var(--bad); }
.totals { margin-left: auto; width: min(360px, 100%); }
.totals td { border: 0; padding: 4px 12px; }
.totals tr.grand td { font-size: 16px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13.5px; padding: 7px 14px; border-radius: 5px; border: 1px solid #cfd5de; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; min-height: 36px; white-space: nowrap; }
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-post { background: var(--entity); border-color: var(--entity); color: #fff; }
.btn-post:hover { filter: brightness(.92); background: var(--entity); }
.btn-danger { color: var(--bad); border-color: #f0c2bd; }
.btn-danger:hover { background: var(--bad-wash); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* filters */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.filters .field { min-width: 140px; }
.filters input, .filters select { min-height: 34px; padding: 5px 8px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--entity); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* definition lists */
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 11px var(--font); fill: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { padding: 7px 16px; }
.bar-list .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bar-list .track { height: 6px; background: var(--line-soft); border-radius: 3px; margin-top: 5px; }
.bar-list .fill { height: 6px; background: var(--entity); border-radius: 3px; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; width: min(460px, 94vw); box-shadow: 0 18px 50px rgba(20,30,50,.22); }
dialog::backdrop { background: rgba(20,28,40,.45); }
dialog .panel-body { display: grid; gap: 12px; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 28px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card form { display: grid; gap: 14px; margin-top: 18px; }
.auth-entities { display: flex; gap: 6px; margin-bottom: 18px; }
.auth-entities span { height: 4px; flex: 1; border-radius: 2px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(4n) { border-right: 1px solid var(--line-soft); }
  .kpi:nth-child(2n) { border-right: 0; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 50; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-toggle { display: inline-flex; background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; padding: 0 4px; }
  .content { padding: 16px; }
  .topbar { flex-wrap: wrap; }
  .entity-band { flex: 1 1 100%; }
  .entity-band select { max-width: 60vw; }
  .topbar-right { padding: 6px 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field.span3, .field.span4 { grid-column: 1 / -1; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; }
  .lines td.desc { grid-column: 1 / -1; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--faint); }
}
@media (max-width: 520px) {
  .kpi { padding: 12px; }
  .kpi .v { font-size: 16px; }
  .kpi .s { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .field.span2 { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .sidebar, .topbar, .actions, .filters, .no-print, .form-foot { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .panel { border: 0; }
  body { background: #fff; }
}
