:root {
  --ink: #101828;
  --muted: #667085;
  --line: #e7eaf0;
  --surface: #ffffff;
  --canvas: #f4f6f9;
  --nav: #0b1220;
  --nav-soft: #151f31;
  --blue: #155eef;
  --cyan: #0e9384;
  --violet: #7f56d9;
  --green: #039855;
  --orange: #dc6803;
  --red: #d92d20;
  --radius: 18px;
  --shadow: 0 8px 28px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }
html { background: var(--canvas); scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); font-family: "DM Sans", system-ui, sans-serif; }
button, select { font: inherit; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; border-radius: .6rem; color: #fff; background: var(--blue); }
.skip-link:focus { top: 1rem; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 10; display: flex; flex-direction: column; padding: 26px 18px 22px; color: #d0d5dd; background: var(--nav); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; color: #fff; background: linear-gradient(145deg, #2e90fa, #155eef); font-family: Manrope, sans-serif; font-size: .86rem; font-weight: 800; box-shadow: 0 7px 20px rgba(21, 94, 239, .35); }
.brand strong, .brand small { display: block; }
.brand strong { color: #fff; font: 700 .94rem/1.2 Manrope, sans-serif; }
.brand small { margin-top: 4px; color: #98a2b3; font-size: .75rem; }
.nav-list { display: grid; gap: 6px; }
.nav-list a { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border-radius: 11px; color: #98a2b3; text-decoration: none; font-size: .92rem; font-weight: 600; transition: .18s ease; }
.nav-list a > span:first-child { display: grid; place-items: center; width: 22px; font-weight: 700; }
.nav-list a:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-list a.active { color: #fff; background: #155eef; box-shadow: 0 8px 24px rgba(21, 94, 239, .24); }
.nav-group { display: grid; gap: 4px; }
.nav-parent i { margin-left: auto; color: #84adff; font-style: normal; }
.nav-children { display: grid; gap: 3px; margin: 0 0 3px 25px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.13); }
.nav-list .nav-children a { min-height: 38px; padding: 0 11px; font-size: .8rem; }
.nav-list .nav-children a > span:first-child { width: 17px; font-size: .72rem; }
.nav-list .nav-children a.active { color: #fff; background: rgba(21,94,239,.28); box-shadow: inset 2px 0 0 #84adff; }
.nav-list .nav-children a.nav-subitem { margin-left: 22px; border-radius: 9px; color: #b7c3d6; }
.nav-list .nav-children a.nav-subitem.active { color: #fff; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid rgba(255,255,255,.1); }
.api-mini { display: flex; align-items: center; gap: 10px; }
.api-mini strong, .api-mini small { display: block; }
.api-mini strong { color: #f2f4f7; font-size: .82rem; }
.api-mini small { margin-top: 2px; color: #98a2b3; font-size: .72rem; }
.sidebar-foot p { margin: 12px 0 0; color: #667085; font-size: .7rem; line-height: 1.45; }

.main { min-width: 0; margin-left: 248px; padding: 38px clamp(24px, 4vw, 58px) 26px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 28px; max-width: 1540px; margin: 0 auto 26px; }
.eyebrow, .section-kicker { margin: 0 0 7px; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: Manrope, sans-serif; letter-spacing: -.035em; }
h1 { font-size: clamp(1.8rem, 3vw, 2.7rem); line-height: 1.08; }
h2 { font-size: 1.18rem; line-height: 1.25; }
.intro { max-width: 660px; margin: 10px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.5; }
.header-actions { display: flex; align-items: center; gap: 12px; padding-top: 5px; }
.sync-state { display: flex; align-items: center; gap: 10px; min-width: 176px; }
.sync-state strong, .sync-state small { display: block; }
.sync-state strong { font-size: .82rem; }
.sync-state small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.status-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: #fdb022; box-shadow: 0 0 0 4px rgba(253,176,34,.12); }
.status-dot.online { background: #12b76a; box-shadow: 0 0 0 4px rgba(18,183,106,.12); }
.status-dot.offline { background: #f04438; box-shadow: 0 0 0 4px rgba(240,68,56,.12); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 700; }
.button.primary { color: #fff; background: var(--blue); box-shadow: 0 6px 18px rgba(21,94,239,.22); }
.button:hover { filter: brightness(.97); transform: translateY(-1px); }
.button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(21,94,239,.25); outline-offset: 2px; }
.button:disabled { cursor: wait; opacity: .62; transform: none; }
.button.syncing > span:first-child { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.control-bar { display: flex; align-items: end; gap: 14px; max-width: 1540px; margin: 0 auto 18px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.78); box-shadow: 0 4px 14px rgba(16,24,40,.035); backdrop-filter: blur(10px); }
.control-bar label { display: grid; gap: 6px; }
.control-bar label > span, .period-note span { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .055em; }
select { min-width: 250px; height: 42px; padding: 0 38px 0 12px; border: 1px solid #d0d5dd; border-radius: 9px; color: var(--ink); background: #fff; font-weight: 600; }
#periodSelect { min-width: 170px; }
.period-note { display: grid; gap: 6px; margin-left: auto; padding: 0 7px 3px; text-align: right; }
.period-note strong { font-size: .86rem; }
.delivery-state { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #fff; font-size: .72rem; }
.delivery-state .delivery-dot { width: 8px; height: 8px; border-radius: 50%; background: #98a2b3; }
.delivery-state.active .delivery-dot { background: #12b76a; box-shadow: 0 0 0 3px rgba(18,183,106,.11); }
.delivery-state.paused .delivery-dot, .delivery-state.not_in_ads .delivery-dot { background: #98a2b3; box-shadow: 0 0 0 3px rgba(152,162,179,.12); }

.notice { display: flex; gap: 10px; max-width: 1540px; margin: 0 auto 18px; padding: 12px 15px; border-radius: 10px; font-size: .86rem; }
.notice.error { color: #912018; border: 1px solid #fecdca; background: #fef3f2; }
.notice.error.warning { color: #93370d; border-color: #fec84b; background: #fffaeb; }
.notice[hidden] { display: none; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; max-width: 1540px; margin: 0 auto 18px; }
.kpi-card { position: relative; overflow: hidden; min-height: 136px; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: var(--shadow); }
.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.kpi-card::after { content: ""; position: absolute; width: 86px; height: 86px; right: -34px; top: -38px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 9%, transparent); }
.accent-blue { --accent: var(--blue); }.accent-cyan { --accent: var(--cyan); }.accent-violet { --accent: var(--violet); }.accent-green { --accent: var(--green); }.accent-orange { --accent: var(--orange); }
.kpi-label, .kpi-value, .kpi-foot { display: block; }
.kpi-label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.kpi-value { margin-top: 15px; font: 800 clamp(1.35rem, 2vw, 1.75rem)/1 Manrope, sans-serif; letter-spacing: -.04em; }
.kpi-foot { margin-top: 10px; color: var(--muted); font-size: .75rem; }

.leads-panel { max-width: 1540px; margin: 0 auto 18px; background: linear-gradient(135deg, #fff 0%, #f7fbff 100%); }
.leads-heading { align-items: flex-start; }
.panel-intro { margin: 7px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.leads-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.lead-result { position: relative; min-width: 0; padding: 17px 18px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.86); }
.lead-result::before { content: ""; position: absolute; inset: 16px auto 16px 0; width: 3px; border-radius: 0 3px 3px 0; background: var(--cyan); }
.lead-result.primary::before { background: var(--blue); }
.lead-result span, .lead-result strong, .lead-result small { display: block; }
.lead-result span { color: var(--muted); font-size: .74rem; font-weight: 700; }
.lead-result strong { margin-top: 11px; font: 800 1.55rem/1 Manrope, sans-serif; letter-spacing: -.04em; }
.lead-result small { margin-top: 7px; overflow: hidden; color: var(--muted); font-size: .69rem; text-overflow: ellipsis; white-space: nowrap; }
.leads-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: .7rem; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(310px, .75fr); gap: 18px; max-width: 1540px; margin: 0 auto 18px; }
.panel { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-heading .section-kicker { margin-bottom: 5px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: .74rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; }
.legend-cost { background: var(--blue); }.legend-clicks { background: var(--cyan); }
.chart-wrap { min-height: 252px; overflow: hidden; }
.chart-wrap svg { display: block; width: 100%; height: 252px; }
.chart-empty { display: grid; place-items: center; height: 252px; color: var(--muted); }
.pulse-list { display: grid; gap: 23px; padding: 5px 0 9px; }
.pulse-item > div:first-child { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 9px; }
.pulse-item span { color: var(--muted); font-size: .83rem; }.pulse-item strong { font-size: .88rem; }
.pulse-item span small { margin-left: 5px; padding: 2px 6px; border-radius: 999px; color: #b54708; background: #fffaeb; font-size: .58rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.progress { height: 8px; overflow: hidden; border-radius: 999px; background: #eef2f6; }
.progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #2e90fa, var(--blue)); transition: width .4s ease; }
.progress.budget i { background: linear-gradient(90deg, #fec84b, #f79009); }.progress.warning i { background: linear-gradient(90deg, #f97066, #d92d20); }.progress.violet i { background: linear-gradient(90deg, #b692f6, var(--violet)); }
.panel-note { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem; line-height: 1.45; }

.decisions-panel { max-width: 1540px; margin: 0 auto 18px; }
.data-chip { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; color: #175cd3; background: #eff8ff; font-size: .7rem; font-weight: 800; }
.decision-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.decision-card { min-width: 0; padding: 17px; border: 1px solid var(--line); border-top: 3px solid var(--decision-color); border-radius: 13px; background: #fbfcfd; }
.attention-access { width: 100%; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease; }
.attention-access:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(220,104,3,.12); }
.attention-access:focus-visible { outline: 3px solid rgba(220,104,3,.22); outline-offset: 3px; }
.attention-access .decision-title strong { display: flex; align-items: center; gap: 7px; }
.attention-access .decision-title em { padding: 3px 7px; border-radius: 999px; color: #b54708; background: #fffaeb; font-size: .58rem; font-style: normal; letter-spacing: .03em; text-transform: uppercase; }
.decision-card.spend { --decision-color: var(--blue); }.decision-card.efficient { --decision-color: var(--green); }.decision-card.attention { --decision-color: var(--orange); }
.decision-title { display: flex; align-items: center; gap: 11px; margin-bottom: 13px; }
.decision-title > span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: var(--decision-color); background: color-mix(in srgb, var(--decision-color) 10%, white); font-size: .7rem; font-weight: 800; }
.decision-title strong, .decision-title small { display: block; }.decision-title strong { font-size: .9rem; }.decision-title small { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.ranking-list { display: grid; }
.rank-row { display: grid; grid-template-columns: 22px minmax(0,1fr) auto; align-items: center; gap: 9px; min-height: 44px; border-top: 1px solid var(--line); }
.rank-row:first-child { border-top: 0; }
.rank-index { color: var(--muted); font-size: .72rem; font-weight: 700; }.rank-name { display: flex; min-width: 0; align-items: center; gap: 6px; overflow: hidden; font-size: .79rem; font-weight: 700; white-space: nowrap; }.rank-name > span:first-child { overflow: hidden; text-overflow: ellipsis; }.rank-value { color: var(--decision-color); font-size: .76rem; font-weight: 800; }
.delivery-tag { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 999px; color: #027a48; background: #ecfdf3; font-size: .56rem; font-weight: 800; line-height: 1.25; text-transform: uppercase; }
.delivery-tag i { width: 5px; height: 5px; border-radius: 50%; background: #12b76a; }
.delivery-tag.paused, .delivery-tag.not_in_ads { color: #667085; background: #f2f4f7; }.delivery-tag.paused i, .delivery-tag.not_in_ads i { background: #98a2b3; }
.empty { padding: 16px 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }

.lower-grid { grid-template-columns: minmax(0, 1.45fr) minmax(330px, .55fr); }
.detail-heading { align-items: end; }
.detail-tools { display: flex; align-items: end; justify-content: flex-end; gap: 9px; }
.detail-tools label { display: grid; gap: 4px; }
.detail-tools label > span { color: var(--muted); font-size: .6rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.detail-tools select { min-width: 145px; height: 34px; padding-left: 9px; font-size: .72rem; }
.detail-tools .data-chip { margin-bottom: 4px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; font-size: .78rem; white-space: nowrap; }
th { color: var(--muted); background: #f8fafc; font-size: .68rem; letter-spacing: .035em; text-transform: uppercase; }
th:first-child, td:first-child { width: 38%; text-align: left; white-space: normal; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbff; }
.table-name { display: block; font-weight: 700; }.table-sub { display: flex; align-items: center; gap: 7px; margin-top: 4px; color: var(--muted); font-size: .68rem; }
.terms-list { display: grid; gap: 4px; }
.term-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.term-row:last-child { border-bottom: 0; }.term-copy { min-width: 0; }.term-copy strong { display: block; overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }.term-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; }.term-cost { color: var(--blue); font-size: .78rem; font-weight: 800; }
.page-footer { display: flex; justify-content: space-between; gap: 18px; max-width: 1540px; margin: 0 auto; padding: 8px 2px; color: var(--muted); font-size: .7rem; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(390px, calc(100vw - 48px)); padding: 13px 16px; border-radius: 11px; color: #fff; background: #101828; box-shadow: 0 12px 34px rgba(16,24,40,.24); font-size: .84rem; }
.toast[hidden] { display: none; }
.access-modal[hidden] { display: none; }
.access-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.access-backdrop { position: absolute; inset: 0; background: rgba(11,18,32,.68); backdrop-filter: blur(4px); }
.access-dialog { position: relative; z-index: 1; width: min(420px, 100%); padding: 28px; border-radius: 18px; background: #fff; box-shadow: 0 28px 80px rgba(16,24,40,.3); }
.access-dialog > p:not(.section-kicker) { margin: 9px 0 20px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.access-icon { display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 18px; border-radius: 12px; color: #b54708; background: #fff4e8; font-weight: 800; }
.access-close { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border: 0; border-radius: 8px; color: var(--muted); background: #f2f4f7; cursor: pointer; font-size: 1.15rem; }
.access-dialog form { display: grid; gap: 9px; }
.access-dialog label { color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.access-dialog input { width: 100%; height: 46px; padding: 0 13px; border: 1px solid #d0d5dd; border-radius: 10px; font: 700 1rem DM Sans, sans-serif; letter-spacing: .15em; }
.access-dialog input:focus { border-color: var(--blue); outline: 3px solid rgba(21,94,239,.12); }
.access-error { min-height: 18px; color: var(--red); font-size: .74rem; font-weight: 700; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .leads-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid, .lower-grid { grid-template-columns: 1fr; }
}
@media (max-width: 880px) {
  .sidebar { position: sticky; top: 0; width: 100%; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .brand { flex: 0 0 auto; padding: 0 12px 0 0; }.brand-mark { width: 36px; height: 36px; }.brand > span:last-child { display: none; }
  .nav-list { display: flex; gap: 4px; }.nav-list a { min-height: 38px; padding: 0 11px; }.nav-list > a > span:last-child, .nav-parent > span:nth-child(2), .nav-parent i { display: none; }
  .nav-group { display: flex; align-items: center; }.nav-children { display: flex; margin: 0; padding: 0; border: 0; }.nav-list .nav-children a { min-height: 38px; padding: 0 10px; }.nav-list .nav-children a > span:last-child { display: none; }
  .sidebar-foot { display: none; }.main { margin-left: 0; padding: 26px 18px; }
  .page-header { align-items: stretch; }.header-actions { align-items: flex-end; }.sync-state { display: none; }
  .decision-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .page-header { flex-direction: column; gap: 18px; }.header-actions { align-items: stretch; }.button { width: 100%; }
  .control-bar { display: grid; grid-template-columns: 1fr; }.control-bar label, select { width: 100%; min-width: 0; }.period-note { margin-left: 0; text-align: left; }
  .delivery-state { justify-self: start; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }.kpi-card:last-child { grid-column: 1 / -1; }
  .leads-grid { grid-template-columns: 1fr; }.leads-foot { flex-direction: column; gap: 5px; }
  .panel { padding: 18px; }.panel-heading { align-items: flex-start; }.legend { flex-direction: column; gap: 5px; }
  .detail-heading, .detail-tools { align-items: stretch; }.detail-heading { flex-direction: column; }.detail-tools { display: grid; grid-template-columns: 1fr; width: 100%; }.detail-tools select { width: 100%; }
  .page-footer { flex-direction: column; gap: 5px; }
}
@media (max-width: 420px) {
  .main { padding-inline: 12px; }.kpi-grid { grid-template-columns: 1fr; }.kpi-card:last-child { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; } }
