:root {
  --bg: #f5f4ef;
  --surface: #fffef9;
  --ink: #17211b;
  --muted: #66716a;
  --line: #dcded7;
  --brand: #126a4a;
  --brand-dark: #0b5138;
  --ok: #147a51;
  --warn: #a7620b;
  --bad: #b13c32;
  --shadow: 0 18px 45px rgba(34, 52, 42, .08);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; }
.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; gap: 28px; min-height: 66px; padding: 10px clamp(18px, 4vw, 58px); border-bottom: 1px solid rgba(220,222,215,.9); background: rgba(255,254,249,.92); backdrop-filter: blur(16px); }
.brand { display: flex; flex-direction: column; min-width: 170px; color: var(--brand-dark); font-weight: 800; text-decoration: none; letter-spacing: -.02em; }
.brand span { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
nav { display: flex; flex: 1; gap: 6px; overflow-x: auto; }
nav a { border-radius: 8px; padding: 8px 11px; color: #465149; text-decoration: none; white-space: nowrap; }
nav a:hover { color: var(--brand); background: #edf4ef; }
.shell { width: min(1240px, calc(100% - 36px)); margin: 34px auto 70px; }
footer { padding: 30px; color: var(--muted); text-align: center; font-size: 13px; }
h1, h2, h3 { margin-top: 0; line-height: 1.15; letter-spacing: -.025em; }
h1 { margin-bottom: 10px; font-size: clamp(32px, 5vw, 54px); }
h2 { margin-bottom: 20px; font-size: 21px; }
h3 { margin: 8px 0 4px; font-size: 18px; }
p { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin: 25px 0 30px; padding: clamp(28px, 5vw, 55px); overflow: hidden; border: 1px solid #c9d8cf; border-radius: 24px; background: radial-gradient(circle at 88% 5%, rgba(50,154,106,.22), transparent 34%), linear-gradient(135deg, #fafff9, #e9f3ec); box-shadow: var(--shadow); }
.hero p { max-width: 670px; margin-bottom: 0; font-size: 17px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin: 20px 0 28px; }
.page-head h1 { margin-bottom: 0; }
.page-head > p { max-width: 520px; text-align: right; }
.panel { margin-bottom: 22px; padding: 25px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 24px rgba(34,52,42,.045); }
.panel.narrow { max-width: 900px; }
.grid { display: grid; gap: 22px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.rate-summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.rate-summary-grid .metric.wide { grid-column: span 2; }
.dashboard-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-value { font-size: 13px !important; overflow-wrap: anywhere; }
.metric { min-height: 105px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.metric span { display: block; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.metric strong { font-size: 21px; }
.status-list { margin: 0 0 16px; }
.status-list div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid #ecece7; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; text-align: right; }
.ok { color: var(--ok) !important; }
.warn { color: var(--warn) !important; }
.bad { color: var(--bad) !important; }
.notice { margin: 0 0 18px; padding: 13px 16px; border: 1px solid; border-radius: 10px; }
.notice.success { color: #0d6241; border-color: #a8d6bf; background: #ebf8f0; }
.notice.error { color: #8f2923; border-color: #e1b2ae; background: #fff1ef; }
.error-copy { padding: 10px 12px; border-radius: 8px; color: var(--bad); background: #fff2ef; font-size: 13px; overflow-wrap: anywhere; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.actions.compact { gap: 7px; }
.actions.separated { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
button, input, select { font: inherit; }
button { min-height: 39px; padding: 8px 14px; border: 1px solid #cdd3ce; border-radius: 8px; color: #26312a; background: #fff; cursor: pointer; font-weight: 650; }
button:hover { border-color: #9eaaa2; background: #f7f9f7; }
button.primary { color: white; border-color: var(--brand); background: var(--brand); }
button.primary:hover { background: var(--brand-dark); }
button.danger-outline { color: var(--bad); border-color: #dfb1ac; }
.link-button { min-height: 0; padding: 4px; border: 0; color: var(--muted); background: transparent; }
.inline-form { margin: 0; }
.admin-login-link { flex: none; border: 1px solid #b8c9be; border-radius: 8px; padding: 7px 12px; color: var(--brand-dark); font-weight: 750; text-decoration: none; white-space: nowrap; }
.admin-login-link:hover { border-color: var(--brand); background: #edf4ef; }
.text-link { color: var(--brand); font-weight: 700; text-decoration: none; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-head h2 { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: 16px; }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 6px; color: #3c4740; font-size: 13px; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; }
label.check { display: flex; align-items: center; align-self: center; gap: 8px; min-height: 44px; }
label.check input { width: auto; }
input, select { width: 100%; min-height: 43px; padding: 9px 11px; border: 1px solid #cfd4cf; border-radius: 8px; color: var(--ink); background: white; }
input:focus, select:focus { outline: 3px solid rgba(18,106,74,.12); border-color: var(--brand); }
.form-action { display: flex; align-items: end; height: 100%; }
.filter-bar { display: grid; grid-template-columns: minmax(210px, 1.5fr) repeat(4, minmax(130px, 1fr)) auto; align-items: end; gap: 14px; }
.target-filter-bar { grid-template-columns: minmax(210px, 1.5fr) repeat(3, minmax(130px, 1fr)) auto; }
.filter-actions { display: flex; align-items: center; gap: 12px; min-height: 43px; white-space: nowrap; }
.compact-options { gap: 2px; }
.compact-options label.check { min-height: 34px; }
.proxy-note { margin: 18px 0 0; }
code { padding: 2px 5px; border-radius: 5px; background: #eef0ec; font-size: .92em; }
.rule-list { display: grid; gap: 12px; }
.rule-card { padding: 19px; border: 1px solid #d8ded9; border-left: 4px solid var(--brand); border-radius: 12px; background: #fff; }
.rule-card.disabled { opacity: .72; border-left-color: #9ca49e; }
.rule-summary { display: flex; justify-content: space-between; gap: 25px; }
.rule-summary p { margin: 0; }
.rate-triplet { display: flex; align-items: center; gap: 22px; }
.rate-triplet span { color: var(--muted); font-size: 11px; text-align: right; }
.rate-triplet strong { display: block; margin-top: 2px; color: var(--ink); font-size: 17px; }
details { margin-top: 14px; }
summary { color: var(--brand); cursor: pointer; font-weight: 700; }
.compact-form { margin-top: 15px; }
.badge { display: inline-block; padding: 3px 7px; border-radius: 99px; color: #4d5851; background: #edf0ed; font-size: 11px; font-weight: 800; }
.badge.synced, .badge.no_change { color: #0b6240; background: #e5f5ec; }
.badge.conflict, .badge.large_change, .badge.source_stale { color: #92550a; background: #fff0d7; }
.badge.error, .badge.source_missing { color: #992f28; background: #fde9e6; }
.badge.dry_run { color: #315e8d; background: #e8f1fa; }
.badge.active, .badge.first_seen { color: #0b6240; background: #e5f5ec; }
.badge.inactive, .badge.removed { color: #785f3b; background: #f2ede5; }
.badge.changed { color: #315e8d; background: #e8f1fa; }
.badge.snapshot { color: #59645d; background: #edf0ed; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 10px; border-bottom: 1px solid #e8e9e5; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
td.error-cell { max-width: 330px; white-space: normal; overflow-wrap: anywhere; }
.group-cell { min-width: 230px; max-width: 360px; white-space: normal; }
.group-cell strong, .group-cell small, .cell-note { display: block; }
.group-cell small, .cell-note { margin-top: 3px; color: var(--muted); font-weight: 400; }
.group-cell small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inactive-row { opacity: .68; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 22px; }
.pagination a { color: var(--brand); font-weight: 700; text-decoration: none; }
.pagination span { color: #9ba29d; }
.description-copy { color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { padding: 35px 10px; text-align: center; }
.muted { color: var(--muted); }
.login-page { display: grid; min-height: 100vh; place-items: center; background: radial-gradient(circle at top, #dfeee4, transparent 40%), var(--bg); }
.login-card { width: min(430px, calc(100% - 32px)); padding: 38px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.login-card h1 { font-size: 34px; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .rate-summary-grid, .dashboard-summary { grid-template-columns: repeat(3, 1fr); }
  .filter-bar { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; gap: 8px; }
  .brand { width: 100%; }
  nav { order: 3; width: 100%; }
  .shell { width: min(100% - 24px, 1240px); margin-top: 20px; }
  .hero, .page-head, .rule-summary { align-items: flex-start; flex-direction: column; }
  .grid.two, .form-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .rate-summary-grid, .dashboard-summary { grid-template-columns: repeat(2, 1fr); }
  .rate-summary-grid .metric.wide { grid-column: span 2; }
  .filter-bar { grid-template-columns: 1fr; }
  .rate-triplet { width: 100%; justify-content: space-between; }
  .page-head > p { text-align: left; }
}
