/* COAT shared look. One file for every COAT tool (portal, Meta Ads, budgets later), served at /ui/coat-ui.css.
   Change a colour, font or component here and every tool follows. App-specific styles stay in each app's own style.css and
   must use these tokens (var(--...)), never their own colours.

   Themes: light (default) and dark, switched with <html data-theme="light|dark"> by coat-ui.js. The dark theme is the light
   one flipped: page #252525 with text #f7f8f2. */

/* ---------- fonts ---------- */
@font-face { font-family: "Editorial New"; src: url(/ui/fonts/EditorialNew-Ultralight.woff2) format("woff2"), url(/ui/fonts/EditorialNew-Ultralight.otf) format("opentype"); font-weight: 200; font-style: normal; font-display: swap; }
@font-face { font-family: "Editorial New"; src: url(/ui/fonts/EditorialNewItalics.woff2) format("woff2"), url(/ui/fonts/EditorialNewItalics.otf) format("opentype"); font-weight: 200; font-style: italic; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-Light.otf) format("opentype"); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-Regular.otf) format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-RegularItalic.otf) format("opentype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-Medium.otf) format("opentype"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-SemiBold.otf) format("opentype"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Roobert"; src: url(/ui/fonts/Roobert-Bold.otf) format("opentype"); font-weight: 700; font-style: normal; font-display: swap; }

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f7f8f2; --panel: #fcfcf8; --table: #d4d0c8; --ink: #252525; --muted: #5a5a54;
  --line: rgba(102,102,102,.30); --rule: #666666; --hover: rgba(101,106,94,.12); --shadow: rgba(0,0,0,.14);
  --accent: #656a5e; --accent-ink: #f7f8f2;
  --warn: #6e5210; --warn-bg: #ebe2c0; --bad: #9a3b2b; --good: #4a6b45; --base: #8b877d; --on-bad: #f7f8f2;
  --c1: #656a5e; --c2: #a0634a; --c3: #5b7f95; --c4: #8a7a9b; --c5: #b09440; --c6: #6f9a8f; --c7: #9a9e8f; --c8: #7a7a72;
  --serif: "Editorial New", Georgia, "Times New Roman", serif;
  --sans: "Roobert", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #252525; --panel: #2e2e2c; --table: #3b3b38; --ink: #f7f8f2; --muted: #a9a99f;
  --line: rgba(247,248,242,.20); --rule: #85857d; --hover: rgba(247,248,242,.09); --shadow: rgba(0,0,0,.45);
  --accent: #a3a994; --accent-ink: #252525;
  --warn: #e0c470; --warn-bg: #4a3f1e; --bad: #e58b78; --good: #92c28b; --base: #8b877d; --on-bad: #252525;
  --c1: #a3a994; --c2: #d8906f; --c3: #86b0c8; --c4: #b8a6cc; --c5: #d9bd6a; --c6: #8fc4b8; --c7: #b8bcae; --c8: #a9a99f;
}
@media (prefers-color-scheme: dark) {   /* only if coat-ui.js did not run */
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #252525; --panel: #2e2e2c; --table: #3b3b38; --ink: #f7f8f2; --muted: #a9a99f;
    --line: rgba(247,248,242,.20); --rule: #85857d; --hover: rgba(247,248,242,.09); --shadow: rgba(0,0,0,.45);
    --accent: #a3a994; --accent-ink: #252525;
    --warn: #e0c470; --warn-bg: #4a3f1e; --bad: #e58b78; --good: #92c28b; --base: #8b877d; --on-bad: #252525;
    --c1: #a3a994; --c2: #d8906f; --c3: #86b0c8; --c4: #b8a6cc; --c5: #d9bd6a; --c6: #8fc4b8; --c7: #b8bcae; --c8: #a9a99f;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14.5px/1.55 var(--sans); letter-spacing: .005em; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 200; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 26px; line-height: 1.1; } h2 { font-size: 22px; margin: 0 0 10px; } h3 { font-size: 18px; margin: 18px 0 8px; } h4 { font-size: 16px; }
em { font-family: var(--serif); font-style: italic; font-weight: 200; }
b, strong, th { font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); } .grow { flex: 1; } .small { font-size: 12.5px; }
.note { font-size: 12.5px; color: var(--muted); }
.sub { color: var(--muted); max-width: 110ch; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- page frame: header with tabs ---------- */
header { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 6; }
header h1 { font-size: 24px; margin-right: 6px; }
nav { display: flex; flex-wrap: wrap; gap: 2px; }
nav button { border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; background: transparent; padding: 7px 12px; color: var(--muted); }
nav button:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
nav button.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); background: transparent; }
main { padding: 8px 24px 64px; display: grid; gap: 20px; min-width: 0; max-width: 1760px; }
#msg { padding: 8px 24px 0; color: var(--bad); } #msg.ok { color: var(--good); } #msg:empty { padding: 0; }

/* ---------- form controls ---------- */
label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
label.inline { flex-direction: row; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-size: 13px; }
select, input, button, textarea { font: inherit; color: var(--ink); }
select, textarea, input[type=text], input[type=number], input[type=date], input[type=month], input[type=email], input[type=password], input:not([type]) {
  background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 7px 10px; min-width: 0; text-transform: none; letter-spacing: 0; font-size: 14px; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { border: 1px solid var(--rule); background: transparent; border-radius: 8px; padding: 7px 14px; cursor: pointer; transition: background .12s; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 500; }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 84%, var(--bg)); }
button.ghost { border-color: transparent; } button.ghost:hover:not(:disabled) { border-color: var(--line); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; } .seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
.stepper { display: flex; gap: 4px; align-items: stretch; } .stepper button { padding: 4px 10px; font-size: 16px; line-height: 1; }
.controls, .filters, .toolbar { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.controls, .filters { padding: 12px 24px; }
.toolbar { margin-bottom: 10px; align-items: center; }
.filters { align-items: center; padding-top: 0; }
.filters details { position: relative; }
.filters summary { list-style: none; cursor: pointer; padding: 5px 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--panel); font-size: 12.5px; }
.filters summary:hover { background: var(--hover); } .filters summary.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.filters .menu { position: absolute; z-index: 4; top: 34px; left: 0; min-width: 210px; max-height: 300px; overflow: auto; padding: 8px 10px; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 8px 24px var(--shadow); }
.filters .menu label { flex-direction: row; gap: 8px; align-items: center; color: var(--ink); font-size: 13px; padding: 3px 0; white-space: nowrap; text-transform: none; letter-spacing: 0; }

/* ---------- cards and panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.card, .panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; padding: 16px 18px; }
.card { cursor: pointer; text-align: left; } .card.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card .k { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.card .v { font: 200 32px/1.15 var(--serif); margin: 4px 0 4px; letter-spacing: -.01em; }
.card .d { font-size: 12.5px; color: var(--muted); }
.delta { font-size: 12px; } .delta.good, .pos { color: var(--good); } .delta.bad, .neg { color: var(--bad); } .delta.flat { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line); border-left: 4px solid var(--bad); background: var(--panel); }
.banner.warn { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.banner.ok { border-left-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--panel)); color: var(--good); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--bad); color: var(--on-bad); font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; }

/* ---------- tables ---------- */
.tablewrap { overflow: auto; border: 1px solid var(--rule); border-radius: 12px; background: var(--panel); max-height: calc(100vh - 220px); }
.panel .tablewrap { border: 0; border-radius: 0; background: transparent; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 14px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; z-index: 2; font-size: 12px; font-weight: 600; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--panel) 92%, var(--accent)); }
table.left th, table.left td { text-align: left; }
table.grid td, table.grid th { text-align: center; padding: 6px 8px; } table.grid td:first-child, table.grid th:first-child { text-align: left; }
td.name { max-width: 380px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- charts (drawn as SVG by each app; sized by the app to the real width, so nothing is stretched) ---------- */
svg { display: block; width: 100%; height: auto; }
svg text { fill: var(--muted); font: 11px var(--sans); } svg .grid { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; margin-top: 8px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

/* ---------- sign-in ---------- */
#login { position: fixed; inset: 0; background: var(--bg); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
#login .box { background: var(--panel); border: 1px solid var(--rule); border-radius: 14px; padding: 30px 32px; width: min(420px, 100%); }
#login label { margin-top: 14px; } #login input { width: 100%; } #login .primary { width: 100%; margin-top: 18px; padding: 10px; }
#login h2 { font-size: 30px; }

/* ---------- areas (portal tiles) ---------- */
.areas { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.area { display: block; text-decoration: none; color: inherit; border: 1px solid var(--rule); border-radius: 12px; padding: 20px 22px; background: var(--panel); }
.area:hover { border-color: var(--accent); background: color-mix(in srgb, var(--panel) 92%, var(--accent)); }
.area b { display: block; font: 200 24px/1.2 var(--serif); margin-bottom: 4px; } .area span { color: var(--muted); font-size: 13px; }
.form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

@media (max-width: 640px) {
  header { padding: 10px 14px; } main { padding: 4px 14px 48px; } .controls, .filters { padding: 10px 14px; } #msg { padding: 8px 14px 0; }
  .card .v { font-size: 26px; }
}

/* ---------- shared sidebar: opt in with <body class="shell" data-area="metaads"> ----------
   The tool's own <header> becomes the left panel: its <h1> is the brand, <nav> the menu, and everything after .grow sits at the bottom.
   coat-ui.js adds the area switcher under the brand and, on a phone, a Menu button that opens the panel as a drawer. */
body.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; align-items: start; }
body.shell > :not(header):not(#login):not(script):not(dialog):not(#shelltop):not(#shellscrim) { grid-column: 2; min-width: 0; }
body.shell > header { grid-column: 1; grid-row: 1 / span 60; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-direction: column; flex-wrap: nowrap; align-items: stretch;
  gap: 16px; padding: 26px 18px 18px; border-bottom: 0; border-right: 1px solid var(--line); background: var(--bg); }
body.shell > main { padding-top: 24px; }
body.shell > header h1 { font-size: 34px; margin: 0; letter-spacing: .01em; }
body.shell > header .grow { flex: 1 1 auto; }
body.shell > header nav { flex-direction: column; flex-wrap: nowrap; gap: 2px; margin: 0 -6px; }
body.shell > header nav button { text-align: left; border: 0; border-left: 3px solid transparent; border-radius: 8px; padding: 7px 12px; color: var(--ink); font-size: 15px; }
body.shell > header nav button:hover:not(:disabled) { background: var(--hover); }
body.shell > header nav button.on { background: var(--hover); border-left-color: var(--accent); font-weight: 600; }
body.shell > header nav button[hidden] { display: none; }
body.shell > header nav button.grp { margin-top: 14px; position: relative; }       /* a divider above a group of menu items */
body.shell > header nav button.grp::before { content: ""; position: absolute; left: 12px; right: 12px; top: -8px; border-top: 1px solid var(--line); }
body.shell > header > button, body.shell > header > .foot button { width: 100%; text-align: left; }
body.shell > header > .muted { font-size: 12.5px; }
body.shell .areaswitch { margin: 0; } body.shell .areaswitch select { width: 100%; }
body.shell > header .badge { margin-left: 6px; }
#shelltop, #shellscrim { display: none; }
@media (max-width: 960px) {
  body.shell { grid-template-columns: minmax(0, 1fr); }
  body.shell > :not(header):not(#login):not(script):not(dialog):not(#shelltop):not(#shellscrim) { grid-column: 1; }
  #shelltop { display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 30; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); grid-column: 1; }
  #shelltop .brand { font: 200 24px/1 var(--serif); }
  #shellscrim { position: fixed; inset: 0; z-index: 39; background: rgba(37, 37, 37, .4); }
  body.menu-open #shellscrim { display: block; }
  body.shell > header { position: fixed; z-index: 40; left: 0; top: 0; width: min(88vw, 320px); transform: translateX(-102%); transition: transform .2s ease; visibility: hidden; grid-column: 1; }
  body.menu-open > header { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(37, 37, 37, .25); }
}
