:root {
  --ink: #18302b;
  --muted: #697973;
  --surface: #ffffff;
  --canvas: #f4f2eb;
  --line: #d9ded9;
  --brand: #173f36;
  --brand-2: #286c5c;
  --accent: #e8bd67;
  --accent-soft: #fbf0d8;
  --good: #2e725d;
  --good-soft: #e4f2ed;
  --warn: #99691b;
  --warn-soft: #fff3d7;
  --bad: #a3483f;
  --bad-soft: #f9e7e4;
  --shadow: 0 12px 36px rgba(30, 52, 46, .08);
  --radius: 18px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
a { color: var(--brand-2); text-underline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .55rem; font-size: clamp(2rem, 4.4vw, 3.5rem); line-height: 1.03; letter-spacing: -.045em; }
h2 { font-size: 1.25rem; letter-spacing: -.02em; }
h3 { letter-spacing: -.02em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -100px; left: 1rem; z-index: 100; background: white; padding: .75rem 1rem; border-radius: 8px; }
.skip-link:focus { top: 1rem; }

.topbar { height: 76px; display: flex; align-items: center; gap: 2rem; padding: 0 max(24px, calc((100vw - 1240px) / 2)); background: rgba(255,255,255,.92); border-bottom: 1px solid rgba(23,63,54,.1); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(15px); }
.brand { display: flex; align-items: center; gap: .75rem; color: var(--ink); text-decoration: none; margin-right: auto; }
.brand-mark, .login-mark { display: grid; place-items: center; background: var(--brand); color: white; font-family: Georgia, serif; font-weight: 700; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px 12px 5px 12px; font-size: 1.25rem; }
.brand span:last-child { display: grid; }
.brand strong { font-size: .98rem; }
.brand small { color: var(--muted); font-size: .72rem; }
.desktop-nav { display: flex; align-self: stretch; }
.desktop-nav a { display: grid; place-items: center; color: var(--muted); text-decoration: none; font-weight: 650; font-size: .9rem; padding: 0 .9rem; border-bottom: 3px solid transparent; }
.desktop-nav a:hover, .desktop-nav a.active { color: var(--brand); border-bottom-color: var(--accent); }
.logout-form { margin-left: .25rem; }

.page-shell { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 80px; }
.hero { color: white; background: var(--brand); border-radius: 28px; padding: clamp(30px, 5vw, 64px); box-shadow: var(--shadow); }
.compact-hero { min-height: 220px; display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; position: relative; overflow: hidden; }
.compact-hero::after { content: ""; width: 340px; height: 340px; border: 1px solid rgba(255,255,255,.18); border-radius: 50%; position: absolute; right: -90px; top: -170px; box-shadow: 0 0 0 38px rgba(255,255,255,.035), 0 0 0 76px rgba(255,255,255,.025); }
.compact-hero > * { position: relative; z-index: 1; }
.hero h1 { max-width: 780px; }
.hero-copy { max-width: 650px; margin: 0; color: #d6e5df; font-size: 1.05rem; }
.eyebrow { margin-bottom: .6rem; color: var(--accent); font-size: .74rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.eyebrow.dark { color: var(--brand-2); }
.hero-actions { display: flex; gap: .7rem; flex-wrap: wrap; justify-content: flex-end; }

.button { display: inline-flex; justify-content: center; align-items: center; gap: .35rem; min-height: 44px; border: 1px solid transparent; border-radius: 11px; padding: .7rem 1rem; font-weight: 750; text-decoration: none; cursor: pointer; transition: transform .15s ease, background .15s ease, border .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid rgba(232,189,103,.65); outline-offset: 2px; }
.button:disabled { opacity: .55; cursor: wait; }
.button.primary { background: var(--accent); color: #2e2617; border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: #f2cb7b; }
.button.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.hero .button.secondary { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.25); color: white; }
.button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.button.compact { min-height: 36px; padding: .4rem .75rem; font-size: .85rem; }
.button.wide { width: 100%; }

.notice, .alert { padding: .9rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.notice { background: var(--good-soft); border: 1px solid #b8d8cc; color: #245b4b; }
.alert.error { background: var(--bad-soft); border: 1px solid #ecc0bb; color: var(--bad); }
.alert.warning { background: var(--warn-soft); border: 1px solid #efdcae; color: #7e581b; }
.muted { color: var(--muted); }

.run-strip { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .8rem; margin: 18px 0; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; box-shadow: 0 5px 20px rgba(30,52,46,.04); }
.run-strip span:nth-child(2) { display: grid; }
.run-strip small { color: var(--muted); margin-top: .15rem; }
.run-result { background: var(--good-soft); color: var(--good); border-radius: 999px; padding: .35rem .7rem; font-weight: 750; font-size: .85rem; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: #a7b1ad; box-shadow: 0 0 0 4px #edf0ee; }
.status-dot.completed, .status-dot.checked, .status-dot.no_results { background: var(--good); box-shadow: 0 0 0 4px var(--good-soft); }
.status-dot.running { background: #d59c35; box-shadow: 0 0 0 4px var(--warn-soft); animation: pulse 1.4s infinite; }
.status-dot.failed, .status-dot.completed_with_errors, .status-dot.blocked, .status-dot.robots { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
.status-dot.manual { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
@keyframes pulse { 50% { transform: scale(.75); opacity: .65; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0 28px; }
.stat-card { display: flex; align-items: center; justify-content: space-between; min-height: 92px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); text-decoration: none; }
.stat-card strong { color: var(--ink); font-size: 1.9rem; letter-spacing: -.04em; }
.stat-card.accent { background: var(--accent-soft); border-color: #e9d09b; }
.stat-card.selected { border-color: var(--brand-2); box-shadow: inset 0 0 0 1px var(--brand-2); }

.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 220px 200px auto; gap: 10px; align-items: end; background: var(--surface); border: 1px solid var(--line); padding: 12px; border-radius: var(--radius); }
label { display: grid; gap: .4rem; color: var(--ink); font-size: .88rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #cbd3cf; border-radius: 9px; padding: .7rem .8rem; background: white; color: var(--ink); }
input, select { min-height: 44px; }
textarea { resize: vertical; line-height: 1.5; }
.search-field input { padding-left: 1rem; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; margin: 34px 0 14px; }
.section-heading h2 { margin: 0; }
.section-heading a, .back-link { font-weight: 700; font-size: .9rem; }

.listing-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.listing-card { display: flex; flex-direction: column; min-width: 0; padding: 19px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 22px rgba(30,52,46,.035); }
.card-topline { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.badge, .run-status { width: max-content; padding: .35rem .62rem; border-radius: 999px; font-size: .7rem; font-weight: 850; letter-spacing: .03em; text-transform: uppercase; }
.badge.match { color: var(--good); background: var(--good-soft); }
.badge.review { color: var(--warn); background: var(--warn-soft); }
.badge.excluded { color: var(--bad); background: var(--bad-soft); }
.seen { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.listing-title { color: var(--ink); text-decoration: none; }
.listing-title h3 { min-height: 2.8em; margin: 1rem 0 .45rem; font-size: 1.18rem; line-height: 1.28; }
.listing-title:hover { color: var(--brand-2); }
.location { min-height: 2.6em; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); margin: .7rem 0; padding: .75rem 0; border-top: 1px solid #edf0ee; border-bottom: 1px solid #edf0ee; }
.facts div { padding: 0 .55rem; border-right: 1px solid #edf0ee; }
.facts div:first-child { padding-left: 0; }
.facts div:last-child { border: 0; }
.facts dt { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
.facts dd { margin: .2rem 0 0; font-weight: 800; font-size: .93rem; white-space: nowrap; }
.missing { margin: .3rem 0 .7rem; color: var(--warn); font-size: .78rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; min-height: 29px; margin-bottom: .7rem; }
.chips span { border: 1px solid #d3ded9; border-radius: 999px; padding: .25rem .5rem; color: #49665d; font-size: .72rem; }
.decision-form { margin-top: auto; padding-top: .5rem; }
.decision-form label span { font-size: .74rem; color: var(--muted); }
.decision-form select { font-weight: 700; }
.empty-state { text-align: center; background: var(--surface); border: 1px dashed #c5cdc9; border-radius: var(--radius); padding: 60px 24px; }
.empty-icon { width: 66px; height: 66px; margin: 0 auto 1rem; display: grid; place-items: center; border-radius: 50%; background: var(--good-soft); font-size: 1.8rem; color: var(--good); }
.empty-state p { color: var(--muted); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 24px; }

.back-link { display: inline-block; margin-bottom: 22px; text-decoration: none; }
.detail-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 28px; }
.detail-header h1 { margin: .8rem 0 .5rem; font-size: clamp(2rem, 4vw, 3.2rem); }
.detail-header p { color: var(--muted); margin: 0; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.detail-main { display: grid; gap: 16px; }
.panel { padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { margin-bottom: 1.1rem; }
.detail-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 0; }
.detail-facts div { padding: 1rem; border-right: 1px solid #e5e9e7; border-bottom: 1px solid #e5e9e7; }
.detail-facts div:nth-child(3n) { border-right: 0; }
.detail-facts div:nth-last-child(-n+3) { border-bottom: 0; }
.detail-facts dt { color: var(--muted); font-size: .78rem; }
.detail-facts dd { margin: .35rem 0 0; font-weight: 800; }
.evaluation { border-left: 4px solid; padding: .8rem 1rem; margin-top: .7rem; border-radius: 0 9px 9px 0; }
.evaluation ul { margin: .5rem 0 0; padding-left: 1.2rem; }
.evaluation.positive { border-color: var(--good); background: var(--good-soft); }
.evaluation.warning { border-color: var(--warn); background: var(--warn-soft); }
.evaluation.negative { border-color: var(--bad); background: var(--bad-soft); }
.description { white-space: pre-line; line-height: 1.65; color: #42554f; }
.source-links { list-style: none; padding: 0; margin: 0; }
.source-links li { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 0; border-bottom: 1px solid #edf0ee; }
.source-links li:last-child { border: 0; }
.source-links a { font-weight: 750; }
.source-links span { color: var(--muted); font-size: .8rem; }
.sticky-panel { position: sticky; top: 96px; }
.stack-form { display: grid; gap: 1rem; }
.panel hr { height: 1px; border: 0; background: var(--line); margin: 1.5rem 0; }
.notification-count { margin-top: .75rem; text-align: right; }

.source-stats { margin-top: 18px; }
.source-list { display: grid; gap: 9px; margin-top: 24px; }
.source-row { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.source-row summary { display: grid; grid-template-columns: auto minmax(180px, 1fr) minmax(150px, auto) auto; align-items: center; gap: 1rem; padding: 15px 18px; cursor: pointer; list-style: none; }
.source-row summary::-webkit-details-marker { display: none; }
.source-row[open] { border-color: #aebdb7; }
.source-name { display: grid; }
.source-name small, table small { display: block; color: var(--muted); margin-top: .2rem; font-size: .74rem; }
.source-status { color: var(--muted); font-size: .8rem; }
.toggle-visual { width: 39px; height: 22px; border-radius: 999px; background: #c9cfcc; padding: 3px; }
.toggle-visual::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle-visual.on { background: var(--brand-2); }
.toggle-visual.on::after { margin-left: 17px; }
.source-editor { padding: 0 18px 18px 54px; border-top: 1px solid #edf0ee; }
.source-form { display: grid; gap: .9rem; max-width: 760px; padding-top: 18px; }
.checkbox { display: flex; align-items: center; gap: .55rem; }
.checkbox input { width: 18px; height: 18px; min-height: 0; }
.field-note { margin: 0; color: var(--muted); font-size: .8rem; }

.table-wrap { margin-top: 22px; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; text-align: left; }
th, td { padding: .9rem 1rem; border-bottom: 1px solid #e9ecea; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td a { font-weight: 800; }
.run-status.completed { color: var(--good); background: var(--good-soft); }
.run-status.completed_with_errors, .run-status.failed { color: var(--bad); background: var(--bad-soft); }
.run-status.running { color: var(--warn); background: var(--warn-soft); }
.status-with-dot { display: flex; align-items: center; gap: .6rem; min-width: 170px; }
.message-cell { max-width: 430px; color: var(--muted); word-break: break-word; }

.settings-form { display: grid; gap: 16px; margin-top: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-grid.textareas { grid-template-columns: repeat(3, 1fr); }
.form-actions { display: flex; justify-content: flex-end; }
.notification-panel { display: flex; align-items: center; justify-content: space-between; gap: 2rem; margin-top: 16px; }
.notification-panel > div { max-width: 760px; }
.notification-panel h2 { margin-bottom: .5rem; }
.push-status { margin: .7rem 0 0; color: var(--brand-2); font-weight: 700; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--brand); position: relative; overflow: hidden; }
.login-body::before { content: ""; position: fixed; width: 540px; height: 540px; right: -260px; top: -250px; border-radius: 50%; border: 1px solid rgba(255,255,255,.15); box-shadow: 0 0 0 55px rgba(255,255,255,.025), 0 0 0 110px rgba(255,255,255,.018); }
.login-card { width: min(440px, 100%); padding: clamp(28px, 6vw, 46px); border-radius: 25px; background: white; box-shadow: 0 30px 80px rgba(0,0,0,.22); position: relative; }
.login-mark { width: 56px; height: 56px; border-radius: 17px 17px 7px 17px; font-size: 1.7rem; margin-bottom: 1.5rem; }
.login-card h1 { font-size: 2.3rem; }
.login-card .muted { line-height: 1.55; margin-bottom: 1.7rem; }
.mobile-nav { display: none; }

@media (max-width: 960px) {
  .desktop-nav { display: none; }
  .listing-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .detail-layout { grid-template-columns: 1fr; }
  .sticky-panel { position: static; }
  .form-grid, .form-grid.textareas { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar { height: 64px; padding: 0 16px; }
  .brand small, .logout-form { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .page-shell { width: min(100% - 28px, 620px); padding-top: 18px; padding-bottom: 32px; }
  .compact-hero { min-height: 250px; padding: 25px; align-items: flex-start; flex-direction: column; justify-content: flex-end; border-radius: 21px; }
  .compact-hero h1 { font-size: 2.25rem; }
  .hero-actions { width: 100%; justify-content: stretch; }
  .hero-actions > * { flex: 1; }
  .hero-actions .button { width: 100%; }
  .run-strip { grid-template-columns: auto 1fr; }
  .run-result { grid-column: 2; justify-self: start; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card { min-height: 78px; padding: 14px; }
  .stat-card strong { font-size: 1.55rem; }
  .filter-bar { display: grid; grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .listing-grid { grid-template-columns: 1fr; }
  .listing-title h3 { min-height: 0; }
  .detail-header { align-items: stretch; flex-direction: column; }
  .detail-header .button { width: 100%; }
  .detail-facts { grid-template-columns: repeat(2, 1fr); }
  .detail-facts div:nth-child(3n) { border-right: 1px solid #e5e9e7; }
  .detail-facts div:nth-child(2n) { border-right: 0; }
  .detail-facts div:nth-last-child(-n+3) { border-bottom: 1px solid #e5e9e7; }
  .detail-facts div:nth-last-child(-n+2) { border-bottom: 0; }
  .panel { padding: 18px; }
  .source-row summary { grid-template-columns: auto 1fr auto; gap: .7rem; }
  .source-status { grid-column: 2; }
  .toggle-visual { grid-column: 3; grid-row: 1 / span 2; }
  .source-editor { padding-left: 18px; }
  .form-grid, .form-grid.textareas { grid-template-columns: 1fr; }
  .notification-panel { align-items: stretch; flex-direction: column; gap: 1rem; }
  .notification-panel .button { width: 100%; }
  .section-heading { align-items: flex-start; }
  .mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid var(--line); backdrop-filter: blur(14px); }
  .mobile-nav a { display: grid; place-items: center; gap: 1px; color: var(--muted); text-decoration: none; font-size: .65rem; font-weight: 700; }
  .mobile-nav a span { font-size: 1.2rem; line-height: 1; }
  .mobile-nav a.active { color: var(--brand); }
  table { min-width: 760px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
