@font-face {
  font-family: "Archivo";
  src: url("/assets/archivo-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: oklch(0.18 0.006 45);
  --ink-soft: oklch(0.38 0.008 45);
  --ink-muted: oklch(0.48 0.008 45);
  --black: oklch(0.12 0.004 45);
  --black-raised: oklch(0.17 0.005 45);
  --canvas: oklch(0.965 0.002 45);
  --surface: oklch(1 0 0);
  --surface-muted: oklch(0.945 0.003 45);
  --line: oklch(0.86 0.004 45);
  --line-strong: oklch(0.72 0.006 45);
  --brand: oklch(0.7 0.19 47);
  --brand-hover: oklch(0.65 0.19 47);
  --brand-soft: oklch(0.95 0.035 47);
  --success: oklch(0.55 0.14 145);
  --success-soft: oklch(0.95 0.025 145);
  --warning: oklch(0.62 0.14 80);
  --warning-soft: oklch(0.96 0.04 80);
  --danger: oklch(0.55 0.19 27);
  --danger-soft: oklch(0.96 0.03 27);
  --paused: oklch(0.48 0.008 45);
  --focus: oklch(0.73 0.19 47);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --z-sticky: 20;
  --z-toast: 50;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--canvas);
  color: var(--ink);
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 16px;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
}

button, input, select { font: inherit; }
button, summary, select { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: calc(var(--z-toast) + 1);
  padding: 10px 14px;
  color: var(--black);
  background: var(--brand);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 8px max(20px, calc((100vw - 1380px) / 2));
  color: var(--surface);
  background: var(--black);
  border-bottom: 1px solid var(--black-raised);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  overflow: hidden;
  place-items: center;
  background: var(--black-raised);
  border-radius: var(--radius-sm);
}

.brand-mark img { width: 38px; height: 38px; object-fit: contain; }
.brand strong { display: block; font-size: 0.92rem; line-height: 1.2; }
.brand small { display: block; margin-top: 2px; color: oklch(0.72 0.006 45); font-size: 0.74rem; }

.header-actions { display: flex; gap: 12px; align-items: center; }
.privacy-label { color: oklch(0.72 0.006 45); font-size: 0.78rem; }
.privacy-label::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px; background: var(--success); border-radius: 50%; vertical-align: 1px; }

.button {
  display: inline-flex;
  min-height: 42px;
  padding: 0 16px;
  gap: 8px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background-color 180ms ease-out, color 180ms ease-out, opacity 180ms ease-out;
}
.button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { color: var(--black); background: var(--brand); }
.button-primary:hover { background: var(--brand-hover); }
.button-quiet { color: var(--ink); background: transparent; }
.button-quiet:hover { background: var(--surface-muted); }
.button-on-dark { color: var(--surface); }
.button-on-dark:hover { background: var(--black-raised); }
.button:disabled { opacity: 0.52; cursor: not-allowed; }
.button.is-loading svg { animation: rotate 900ms linear infinite; }

.page-shell {
  width: min(1380px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0 72px;
}

.page-heading {
  display: flex;
  gap: 28px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 24px;
}

.breadcrumb { margin: 0 0 8px; color: var(--ink-muted); font-size: 0.78rem; }
.breadcrumb span { margin: 0 4px; }
h1, h2, h3, p { text-wrap: pretty; }
h1 { margin: 0; font-size: 1.75rem; letter-spacing: -0.025em; line-height: 1.15; }
h2 { margin: 0; font-size: 1.08rem; letter-spacing: -0.012em; }
h3 { margin: 0; font-size: 0.95rem; }
.last-update { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.82rem; }

.refresh-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.refresh-controls > label,
.custom-period label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.context-switcher label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.context-switcher select { width: 100%; }
.client-switcher { min-width: 190px; }
.account-switcher { min-width: 260px; }

select, input {
  min-height: 40px;
  padding: 0 36px 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
input { padding-right: 12px; }
.custom-period { display: flex; gap: 8px; }
.custom-period[hidden] { display: none; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.45;
}
.notice svg { flex: 0 0 auto; width: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.notice-info { color: var(--ink-soft); background: var(--surface); }
.notice-warning { color: oklch(0.38 0.08 80); background: var(--warning-soft); border-color: oklch(0.83 0.08 80); }

.account-section,
.diagnostics-section,
.hierarchy-section {
  margin-top: 24px;
  background: var(--surface);
  border-radius: var(--radius-md);
}

.account-section { overflow: hidden; border: 1px solid var(--line); }
.account-section.is-refreshing { opacity: 0.68; }
.section-heading {
  display: flex;
  min-height: 64px;
  padding: 14px 18px;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.section-heading p { margin: 3px 0 0; color: var(--ink-muted); font-size: 0.8rem; }
.account-heading { background: var(--black); color: var(--surface); border-bottom: 0; }
.account-heading p { color: oklch(0.74 0.006 45); }
.heading-line { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.period-chip, .count-badge {
  display: inline-flex;
  min-height: 28px;
  padding: 0 10px;
  align-items: center;
  color: var(--ink-soft);
  background: var(--surface-muted);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 650;
}
.account-heading .period-chip { color: oklch(0.88 0.004 45); background: var(--black-raised); }

.status {
  display: inline-flex;
  min-height: 26px;
  padding: 0 9px;
  gap: 6px;
  align-items: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-delivering { color: oklch(0.36 0.12 145); background: var(--success-soft); }
.status-paused { color: var(--paused); background: var(--surface-muted); }
.status-attention { color: oklch(0.39 0.1 80); background: var(--warning-soft); }
.status-problem { color: oklch(0.43 0.16 27); background: var(--danger-soft); }

.overview-strip,
.metric-strip,
.detail-metrics,
.evidence-row {
  display: grid;
  margin: 0;
}
.overview-strip { grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.overview-strip > div { min-height: 112px; padding: 22px 20px; }
.overview-strip > div + div { border-left: 1px solid var(--line); }
.overview-strip dt,
.metric-strip dt,
.detail-metrics dt,
.evidence-row dt { margin: 0 0 8px; color: var(--ink-muted); font-size: 0.72rem; }
.overview-strip dd { margin: 0; font-size: 1.05rem; font-weight: 720; letter-spacing: -0.012em; }
.overview-strip small { display: block; margin-top: 7px; color: var(--ink-muted); font-size: 0.68rem; line-height: 1.35; }

.metric-strip { grid-template-columns: repeat(6, 1fr); }
.metric-strip > div { padding: 16px 20px; }
.metric-strip > div + div { border-left: 1px solid var(--line); }
.metric-strip dd, .detail-metrics dd { margin: 0; font-weight: 680; }
.account-foot {
  display: flex;
  padding: 12px 20px;
  gap: 8px 18px;
  flex-wrap: wrap;
  color: var(--ink-muted);
  background: var(--surface-muted);
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
}

.diagnostics-section,
.hierarchy-section { border: 1px solid var(--line); }
.diagnostics-section > .section-heading,
.hierarchy-section > .section-heading { min-height: 56px; padding: 11px 16px; }
.diagnostics-section > summary { list-style: none; cursor: pointer; transition: background-color 180ms ease-out; }
.diagnostics-section > summary::-webkit-details-marker { display: none; }
.diagnostics-section > summary:hover { background: var(--surface-muted); }
.diagnostics-heading-main { display: flex; min-width: 0; gap: 10px; align-items: center; }
.diagnostics-heading-copy { min-width: 0; }
.diagnostics-chevron { flex: 0 0 auto; }
.diagnostics-section[open] > summary .diagnostics-chevron { transform: rotate(90deg); }
.diagnostics-collapsed-summary { display: none; overflow: hidden; max-width: min(80vw, 90ch); text-overflow: ellipsis; white-space: nowrap; }
.diagnostics-section:not([open]) .diagnostics-intro { display: none; }
.diagnostics-section:not([open]) .diagnostics-collapsed-summary { display: block; }
.count-badge[data-severity="attention"] { color: oklch(0.39 0.1 80); background: var(--warning-soft); }
.count-badge[data-severity="problem"] { color: oklch(0.43 0.16 27); background: var(--danger-soft); }
.diagnostics-list { padding: 0 16px 12px; }
.diagnostic { padding: 12px 0; border-bottom: 1px solid var(--line); }
.diagnostic:last-child { border-bottom: 0; padding-bottom: 0; }
.diagnostic > header { display: flex; gap: 12px; align-items: flex-start; }
.diagnostic > header p { margin: 3px 0 0; color: var(--ink-muted); font-size: 0.74rem; }
.diagnostic > p { max-width: 72ch; margin: 8px 0; color: var(--ink-soft); font-size: 0.82rem; line-height: 1.4; }
.evidence-row { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 860px; background: var(--surface-muted); border-radius: var(--radius-sm); }
.evidence-row > div { padding: 9px 12px; }
.evidence-row > div + div { border-left: 1px solid var(--line); }
.evidence-row dd { margin: 0; font-size: 0.78rem; font-weight: 620; }
.diagnostic footer { margin-top: 7px; color: var(--ink-muted); font-size: 0.72rem; }

.hierarchy-key { display: flex; gap: 8px; flex-wrap: wrap; }
.hierarchy-key span { color: var(--ink-muted); font-size: 0.68rem; }
.tree-header {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) repeat(4, 120px);
  padding: 10px 16px;
  gap: 8px;
  color: var(--ink-muted);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
  font-size: 0.68rem;
  text-align: right;
}
.tree-header span:first-child { text-align: left; }
.object-tree { overflow: clip; padding: 12px; background: var(--surface); }
.tree-object { background: var(--surface); }
.object-tree > .tree-campaign { overflow: clip; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.object-tree > .tree-campaign + .tree-campaign { margin-top: 16px; }
.tree-children > .tree-object { border-bottom: 1px solid var(--line); }
.tree-object summary {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(500px, auto);
  min-height: 76px;
  padding: 12px 16px;
  gap: 16px;
  align-items: center;
  list-style: none;
  cursor: pointer;
  transition: background-color 180ms ease-out;
}
.tree-object summary::-webkit-details-marker { display: none; }
.tree-object summary:hover { background: var(--surface-muted); }
.tree-object[open] > summary { background: var(--surface-muted); }
.object-main { display: flex; min-width: 0; gap: 10px; align-items: center; }
.object-main > div { min-width: 0; }
.object-main strong { display: block; overflow: hidden; font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
.object-main small { display: block; margin-top: 4px; color: var(--ink-muted); font-size: 0.66rem; }
.chevron { color: var(--ink-muted); font-size: 1.3rem; line-height: 1; transition: transform 180ms ease-out; }
.tree-object[open] > summary .chevron { transform: rotate(90deg); }
.level-symbol { display: grid; flex: 0 0 auto; width: 24px; height: 24px; place-items: center; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line); border-radius: 50%; font-size: 0.65rem; font-weight: 760; }
.summary-metrics { display: grid; grid-template-columns: repeat(4, 120px); gap: 8px; }
.summary-metric { min-width: 0; text-align: right; }
.summary-metric span { display: block; color: var(--ink-muted); font-size: 0.62rem; }
.summary-metric strong { display: block; margin-top: 3px; overflow: hidden; font-size: 0.76rem; text-overflow: ellipsis; white-space: nowrap; }

.object-detail { padding: 18px 20px 20px 60px; border-top: 1px solid var(--line); }
.configuration-lines { margin-bottom: 16px; }
.configuration-lines p { margin: 6px 0; color: var(--ink-soft); font-size: 0.78rem; line-height: 1.5; }
.configuration-lines strong { color: var(--ink); }
.adset-configuration { display: grid; grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.6fr); margin-bottom: 16px; gap: 18px; }
.configuration-block + .configuration-block { padding-left: 18px; border-left: 1px solid var(--line); }
.configuration-block h4 { margin: 0 0 7px; font-size: 0.72rem; }
.configuration-block p { margin: 0; color: var(--ink-soft); font-size: 0.76rem; line-height: 1.45; }
.placement-groups { display: flex; margin: 0; gap: 8px 18px; flex-wrap: wrap; }
.placement-groups > div { min-width: 140px; }
.placement-groups dt { margin: 0 0 3px; color: var(--ink-muted); font-size: 0.64rem; }
.placement-groups dd { margin: 0; color: var(--ink-soft); font-size: 0.74rem; line-height: 1.4; }
.automatic-placement { max-width: 62ch; }
.detail-metrics { grid-template-columns: repeat(8, minmax(96px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.detail-metrics > div { min-width: 0; padding: 12px; }
.detail-metrics > div + div { border-left: 1px solid var(--line); }
.detail-metrics dd { overflow: hidden; font-size: 0.76rem; text-overflow: ellipsis; white-space: nowrap; }
.technical-details { margin-top: 14px; }
.technical-details > summary { display: inline-flex; min-height: auto; padding: 4px 0; gap: 5px; align-items: center; color: var(--ink-soft); background: none; font-size: 0.74rem; font-weight: 650; }
.technical-details[open] > summary { background: none; }
.technical-chevron { display: inline-block; font-size: 0.72rem; line-height: 1; transition: transform 180ms ease-out; }
.technical-details[open] > summary .technical-chevron { transform: rotate(90deg); }
.technical-details dl { display: flex; margin: 8px 0 0; gap: 8px 18px; flex-wrap: wrap; }
.technical-details dl > div { min-width: 150px; }
.technical-details dt { color: var(--ink-muted); font-size: 0.64rem; }
.technical-details dd { margin: 3px 0 0; font-size: 0.7rem; overflow-wrap: anywhere; }
.tree-children { margin: 18px -20px -20px -20px; padding-left: 26px; background: oklch(0.975 0.002 45); border-top: 1px solid var(--line); }
.tree-adset > summary, .tree-ad > summary { min-height: 68px; }
.tree-adset .tree-children { background: var(--surface); }
.tree-ad .object-detail { padding-left: 60px; }
.child-empty { margin: 0; padding: 20px; color: var(--ink-muted); font-size: 0.78rem; }

.creative-preview { display: flex; margin-bottom: 16px; gap: 14px; align-items: center; }
.creative-preview img, .thumbnail-empty { width: 84px; height: 84px; flex: 0 0 auto; object-fit: cover; background: var(--surface-muted); border-radius: var(--radius-sm); }
.thumbnail-empty { display: grid; place-items: center; color: var(--ink-muted); font-size: 0.64rem; text-align: center; }
.creative-preview p { margin: 3px 0; font-size: 0.78rem; }
.creative-preview a { display: inline-block; margin-top: 5px; color: oklch(0.48 0.15 47); font-size: 0.72rem; font-weight: 650; }

.empty-state { display: grid; min-height: 360px; margin-top: 24px; padding: 48px 20px; place-items: center; align-content: center; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); }
.empty-state[hidden] { display: none; }
.empty-symbol { display: grid; width: 44px; height: 44px; margin-bottom: 18px; place-items: center; color: var(--black); background: var(--brand); border-radius: var(--radius-sm); font-weight: 850; }
.empty-state p { max-width: 50ch; margin: 8px 0 0; color: var(--ink-muted); font-size: 0.84rem; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: var(--z-toast); max-width: min(400px, calc(100vw - 40px)); padding: 13px 16px; color: var(--surface); background: var(--black); border-radius: var(--radius-sm); font-size: 0.82rem; }
.toast[data-tone="error"] { background: var(--danger); }

.login-page { display: grid; min-height: 100vh; color: var(--surface); background: var(--black); place-items: center; }
.login-shell { width: min(920px, calc(100% - 40px)); display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 70px; align-items: center; }
.login-brand { display: flex; gap: 26px; align-items: center; }
.login-logo { width: 210px; height: 170px; object-fit: contain; }
.login-brand h1 { font-size: 2rem; }
.login-brand p { max-width: 34ch; margin: 10px 0 0; color: oklch(0.72 0.006 45); line-height: 1.5; }
.login-form { display: grid; gap: 10px; padding: 28px; background: var(--black-raised); border-radius: var(--radius-md); }
.login-form label { color: oklch(0.78 0.006 45); font-size: 0.76rem; font-weight: 650; }
.login-form input { width: 100%; color: var(--surface); background: var(--black); border-color: oklch(0.35 0.006 45); }
.login-form .button { margin-top: 8px; }
.form-error { margin: 0; color: oklch(0.82 0.08 27); font-size: 0.76rem; }

@keyframes rotate { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .page-heading { align-items: flex-start; }
  .refresh-controls { flex-wrap: wrap; justify-content: flex-end; }
  .context-switcher { flex: 1 1 220px; }
  .overview-strip { grid-template-columns: repeat(2, 1fr); }
  .overview-strip > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .overview-strip > div:nth-child(4) { border-top: 1px solid var(--line); }
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .metric-strip > div:nth-child(4) { border-left: 0; border-top: 1px solid var(--line); }
  .metric-strip > div:nth-child(n+5) { border-top: 1px solid var(--line); }
  .tree-header { display: none; }
  .tree-object summary { grid-template-columns: 1fr; gap: 10px; }
  .summary-metrics { padding-left: 44px; grid-template-columns: repeat(4, 1fr); }
  .summary-metric { text-align: left; }
  .detail-metrics { grid-template-columns: repeat(4, 1fr); }
  .detail-metrics > div:nth-child(5n) { border-left: 0; }
  .detail-metrics > div:nth-child(n+5) { border-top: 1px solid var(--line); }
  .adset-configuration { grid-template-columns: 1fr; gap: 12px; }
  .configuration-block + .configuration-block { padding: 12px 0 0; border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 760px) {
  .app-header { min-height: 58px; padding: 8px 16px; }
  .privacy-label { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-mark img { width: 32px; height: 32px; }
  .brand small { display: none; }
  .page-shell { width: min(100% - 24px, 1380px); padding: 28px 0 48px; }
  .page-heading { display: block; }
  h1 { font-size: 1.45rem; }
  .refresh-controls { margin-top: 20px; align-items: stretch; flex-wrap: wrap; }
  .refresh-controls > select { flex: 1 1 180px; }
  .refresh-controls > button { flex: 1 1 180px; }
  .custom-period { width: 100%; }
  .custom-period input { width: 50%; }
  .section-heading { min-height: 56px; padding: 11px 14px; }
  .overview-strip { grid-template-columns: 1fr; }
  .overview-strip > div { min-height: auto; padding: 16px; }
  .overview-strip > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric-strip > div { padding: 14px 16px; }
  .metric-strip > div:nth-child(odd) { border-left: 0; }
  .metric-strip > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .account-foot { display: grid; padding: 12px 16px; gap: 5px; }
  .diagnostics-list { padding: 0 14px 10px; }
  .evidence-row { grid-template-columns: 1fr; }
  .evidence-row > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .hierarchy-key { display: none; }
  .tree-object summary { min-height: 72px; padding: 12px; }
  .object-main { align-items: flex-start; }
  .object-main .status { margin-left: auto; }
  .summary-metrics { padding-left: 34px; grid-template-columns: repeat(2, 1fr); row-gap: 10px; }
  .object-detail, .tree-ad .object-detail { padding: 16px 14px 16px 34px; }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }
  .detail-metrics > div:nth-child(odd) { border-left: 0; }
  .detail-metrics > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .tree-children { margin: 16px -14px -16px -34px; padding-left: 12px; }
  .object-tree { padding: 8px; }
  .object-tree > .tree-campaign + .tree-campaign { margin-top: 12px; }
  .creative-preview { align-items: flex-start; }
  .login-shell { display: block; width: min(440px, calc(100% - 32px)); }
  .login-brand { display: block; margin-bottom: 32px; text-align: center; }
  .login-logo { width: 150px; height: 110px; }
  .login-brand h1 { font-size: 1.5rem; }
  .login-brand p { margin-left: auto; margin-right: auto; }
  .login-form { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
