:root {
  color-scheme: light;
  --ink: #173039;
  --muted: #657b80;
  --line: #dce7e6;
  --surface: #ffffff;
  --canvas: #f2f6f5;
  --deep: #153b42;
  --deep-2: #204d52;
  --accent: #4f8f8a;
  --accent-soft: #dbecea;
  --gold: #b58a52;
  --danger: #a94f55;
  --warning: #9a7539;
  --shadow: 0 16px 42px rgba(21, 59, 66, .08);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 5;
  display: flex; flex-direction: column; padding: 26px 18px 20px;
  color: #e8f1f0;
  background:
    radial-gradient(circle at 15% 8%, rgba(99, 154, 149, .3), transparent 26%),
    linear-gradient(155deg, var(--deep-2), var(--deep) 55%, #102e34);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; padding: 0 9px 30px; }
.brand-mark { position: relative; width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.28); border-radius: 14px; background: rgba(255,255,255,.09); overflow: hidden; }
.brand-mark i { position: absolute; inset: -12px 14px 9px -13px; border: 8px solid rgba(122, 188, 181, .58); border-radius: 50%; }
.brand-mark b { position: relative; letter-spacing: -.08em; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: .01em; }
.brand small { color: #a9c4c3; font-size: 12px; }
nav { display: grid; gap: 6px; }
.nav-item { width: 100%; display: flex; gap: 12px; align-items: center; border: 0; border-radius: 12px; padding: 11px 13px; color: #bcd1d0; background: transparent; text-align: left; transition: .18s ease; }
.nav-item span { width: 19px; text-align: center; font-size: 18px; opacity: .85; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.12); box-shadow: inset 3px 0 #7eb5b0; }
.source-badge { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 13px; border: 1px solid rgba(255,255,255,.1); border-radius: 13px; background: rgba(0,0,0,.1); }
.source-badge > span { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #84bbb2; box-shadow: 0 0 0 5px rgba(132,187,178,.13); }
.source-badge strong, .source-badge small { display: block; }
.source-badge strong { font-size: 12px; }
.source-badge small { color: #a9c4c3; font-size: 11px; }

main { min-width: 0; }
.topbar { height: 76px; display: flex; align-items: center; gap: 18px; padding: 0 34px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.87); backdrop-filter: blur(16px); }
.tenant-control { min-width: 220px; }
.period-control { margin-left: auto; }
.tenant-control label, .period-control label { display: block; margin-bottom: 2px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.tenant-control select, .period-control select { min-width: 145px; border: 0; padding: 0 24px 0 0; color: var(--ink); background: transparent; font-weight: 700; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: var(--surface); }
#menu-button { display: none; }
.profile { display: flex; align-items: center; gap: 10px; padding-left: 12px; border-left: 1px solid var(--line); }
.profile > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: #eff8f7; background: var(--accent); font-weight: 800; font-size: 12px; }
.profile strong, .profile small { display: block; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile strong { font-size: 13px; }
.profile small { color: var(--muted); font-size: 11px; }
#sign-out-button { padding: 7px 10px; }

.notice { margin: 20px 34px -4px; padding: 13px 16px; border: 1px solid #e0cda7; border-radius: 12px; color: #73551f; background: #fff9eb; }
.notice.error { border-color: #e4bfc2; color: #813b41; background: #fff2f3; }
.notice.success { border-color: #bad9d3; color: #2c6861; background: #eef9f7; }
.view { display: none; padding: 34px; }
.view.active { display: block; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 27px; }
.page-heading h1 { margin: 2px 0 7px; font-size: clamp(25px, 3vw, 34px); line-height: 1.15; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--accent) !important; font-size: 10px; font-weight: 850; letter-spacing: .13em; }
.period-pill { align-self: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: 12px; }
.heading-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.primary, .secondary, .small-button { border-radius: 10px; padding: 10px 15px; border: 1px solid transparent; font-weight: 750; }
.primary { color: #fff; background: var(--accent); box-shadow: 0 8px 18px rgba(79,143,138,.18); }
.primary:hover { background: #417e7a; }
.secondary, .small-button { color: var(--ink); border-color: var(--line); background: var(--surface); }
.small-button { padding: 6px 10px; font-size: 12px; }
.small-button + .small-button { margin-left: 5px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metrics article { position: relative; padding: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 24px rgba(24,59,65,.04); }
.metrics article::after { content: ""; position: absolute; right: -22px; bottom: -34px; width: 85px; height: 85px; border: 16px solid var(--accent-soft); border-radius: 50%; opacity: .6; }
.metrics small, .metrics span, .metrics strong { position: relative; z-index: 1; display: block; }
.metrics small { color: var(--muted); font-weight: 650; }
.metrics strong { margin: 8px 0 7px; font-size: 27px; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metrics span { color: #7d9195; font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(270px, .65fr); gap: 18px; }
.panel { margin-bottom: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 8px; }
.panel-heading h2 { margin: 0 0 3px; font-size: 16px; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.legend { color: var(--muted); font-size: 11px; }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 3px; background: var(--accent); }
.chart { height: 260px; display: flex; align-items: stretch; gap: 5px; padding: 18px 24px 15px; }
.chart.empty { align-items: center; justify-content: center; color: var(--muted); }
.revenue-svg { width: 100%; height: 100%; overflow: visible; }
.chart-svg-bar { fill: #5c9792; transition: fill .2s ease; }
.revenue-svg g:hover .chart-svg-bar { fill: var(--gold); }
.revenue-svg text { fill: #829598; font: 24px Inter, ui-sans-serif, system-ui, sans-serif; }
.chart-column { position: relative; flex: 1; min-width: 3px; height: 100%; padding-bottom: 18px; text-align: center; }
.chart-bar { position: absolute; right: 0; bottom: 18px; left: 0; min-height: 3px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #659e99, #477f82); transition: .2s ease; }
.chart-column:hover .chart-bar { background: var(--gold); }
.chart-column small { position: absolute; right: 0; bottom: 0; left: 0; overflow: hidden; color: #829598; font-size: 8px; white-space: nowrap; }
.split-panel { padding-bottom: 16px; }
.split-visual { display: grid; place-items: center; padding: 11px 0 18px; }
.split-ring { --split: 0%; width: 128px; height: 128px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--accent) var(--split), #e8efee 0); }
.split-ring::before { content: ""; grid-area: 1/1; width: 94px; height: 94px; border-radius: 50%; background: #fff; }
.split-ring span { grid-area: 1/1; position: relative; text-align: center; }
.split-ring strong, .split-ring small { display: block; }
.split-ring strong { font-size: 23px; }
.split-ring small { color: var(--muted); font-size: 10px; }
.split-row { display: flex; justify-content: space-between; padding: 8px 22px; font-size: 12px; }
.split-row span { color: var(--muted); }
.split-row i { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 3px; }
.publisher-dot { background: var(--accent); }.zenx-dot { background: #d8e2e1; }
.wide-panel { grid-column: 1 / -1; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; border-bottom: 1px solid #e8efee; text-align: left; white-space: nowrap; }
th { color: #7a8f92; background: #fbfcfc; font-size: 10px; letter-spacing: .055em; text-transform: uppercase; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbfb; }
.empty-row { padding: 35px 20px; color: var(--muted); text-align: center; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; color: #3c716c; background: #e5f1ef; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.disabled, .status.failed, .status.error { color: var(--danger); background: #f8e7e8; }
.status.draft, .status.processing, .status.running { color: var(--warning); background: #f8f0df; }
.muted { color: var(--muted); }.money { font-variant-numeric: tabular-nums; font-weight: 750; }
.money.negative { color: #a24e55; }

dialog { width: min(570px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); box-shadow: 0 34px 100px rgba(10,38,43,.28); }
dialog::backdrop { background: rgba(13, 40, 45, .48); backdrop-filter: blur(5px); }
#dynamic-form { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.dialog-heading h2 { margin: 2px 0 0; }
.form-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.form-fields label.full { grid-column: 1 / -1; }
.form-fields input, .form-fields select, .form-fields textarea { width: 100%; padding: 10px 11px; border: 1px solid #cad9d8; border-radius: 9px; color: var(--ink); background: #fbfdfd; outline: none; }
.form-fields input:focus, .form-fields select:focus, .form-fields textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,143,138,.12); }
.form-fields textarea { min-height: 80px; resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 8px; color: #e9f4f2; background: radial-gradient(circle at 50% 35%, #315e62, #153b42); }
.loading.hidden { display: none; }
.loader-mark { width: 60px; height: 60px; display: grid; place-items: center; margin-bottom: 8px; border: 1px solid rgba(255,255,255,.3); border-radius: 19px; background: rgba(255,255,255,.08); font-weight: 900; letter-spacing: -.08em; animation: breathe 1.6s ease-in-out infinite; }
.loading span { color: #afc9c7; font-size: 12px; }
.demo-login { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 20%, #315e62, #153b42 65%); }
.login-card { width: min(440px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.18); border-radius: 24px; background: #fff; box-shadow: 0 34px 100px rgba(7,31,35,.35); }
.login-card h1 { margin: 5px 0 10px; font-size: 29px; letter-spacing: -.035em; }
.login-card > p:not(.eyebrow) { margin: 0 0 22px; color: var(--muted); }
.login-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 22px; border-radius: 17px; color: #f0f8f7; background: var(--accent); font-weight: 900; letter-spacing: -.08em; }
.login-card dl { display: grid; gap: 1px; margin: 0 0 22px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.login-card dl div { display: grid; grid-template-columns: 90px 1fr; gap: 12px; padding: 11px 13px; background: #f9fbfb; }
.login-card dt { color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.login-card dd { margin: 0; overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.login-card .primary { width: 100%; }
.login-error { display: block; margin-top: 12px; color: var(--danger); text-align: center; }
@keyframes breathe { 50% { transform: scale(.94); opacity: .7; } }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .wide-panel { grid-column: auto; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 242px; transition: left .2s ease; }
  body.menu-open .sidebar { left: 0; box-shadow: 16px 0 50px rgba(0,0,0,.25); }
  #menu-button { display: grid; }
  .topbar { height: auto; min-height: 70px; padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  .tenant-control { min-width: 160px; flex: 1; }.tenant-control select { width: 100%; }
  .period-control { display: none; }
  .profile { display: none; }
  .view { padding: 25px 16px; }
  .notice { margin-left: 16px; margin-right: 16px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metrics article { padding: 16px; }.metrics strong { font-size: 22px; }
  .form-fields { grid-template-columns: 1fr; }.form-fields label.full { grid-column: auto; }
}
@media (max-width: 440px) {
  .metrics { grid-template-columns: 1fr; }
  .page-heading h1 { font-size: 27px; }
}
