:root {
  color-scheme: dark;
  --canvas: #071019;
  --canvas-deep: #040a10;
  --surface: #0d1824;
  --surface-raised: #122131;
  --ink: #eaf2f8;
  --muted: #8fa3b7;
  --stroke: #22364a;
  --stroke-strong: #31506b;
  --signal: #4dd4c6;
  --signal-strong: #29bbae;
  --blue: #67aefc;
  --success: #5dd69a;
  --danger: #ff727c;
  --warning: #f5bd63;
  --shadow: 0 18px 48px rgba(0, 4, 10, .28);
  --radius: 10px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background:
    linear-gradient(rgba(77, 212, 198, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77, 212, 198, .025) 1px, transparent 1px),
    radial-gradient(circle at 82% -10%, rgba(52, 130, 177, .16), transparent 34rem),
    var(--canvas);
  background-size: 32px 32px, 32px 32px, auto, auto;
  font-family: "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid rgba(77, 212, 198, .42); outline-offset: 2px; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(49, 80, 107, .76);
  background: rgba(4, 10, 16, .9);
  backdrop-filter: blur(18px);
}

.topbar-inner {
  width: min(100% - 40px, 1400px);
  min-height: 78px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
}

.brand {
  min-width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}

.brand:hover { text-decoration: none; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(77, 212, 198, .42);
  background: linear-gradient(145deg, rgba(77, 212, 198, .13), rgba(103, 174, 252, .06));
  box-shadow: inset 0 0 24px rgba(77, 212, 198, .06);
  clip-path: polygon(12% 0, 88% 0, 100% 12%, 100% 88%, 88% 100%, 12% 100%, 0 88%, 0 12%);
}

.brand-mark svg { width: 30px; height: 30px; }
.brand-mark path:first-child { fill: none; stroke: var(--signal); stroke-width: 1.6; }
.brand-mark .signal { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
.brand-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; letter-spacing: .06em; }

nav { display: flex; align-items: center; gap: 4px; }
nav > a,
.nav-logout {
  position: relative;
  border: 0;
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

nav > a:hover,
.nav-logout:hover { color: var(--ink); background: rgba(143, 163, 183, .08); text-decoration: none; }
nav > a.active { color: var(--ink); }
nav > a.active::after {
  content: "";
  position: absolute;
  right: 11px;
  bottom: 3px;
  left: 11px;
  height: 2px;
  background: var(--signal);
  box-shadow: 0 0 10px rgba(77, 212, 198, .5);
}
.nav-logout { margin-left: 8px; border: 1px solid var(--stroke); }

.container {
  width: min(100% - 40px, 1400px);
  margin: 0 auto;
  padding: 34px 0 54px;
  flex: 1;
}

h1, h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 18px; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }

.card {
  position: relative;
  margin-bottom: 18px;
  padding: 22px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(18, 33, 49, .84), rgba(13, 24, 36, .96));
  box-shadow: var(--shadow);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 54px;
  height: 2px;
  background: var(--signal);
}

.narrow { max-width: 460px; margin: 7vh auto; }
.narrow button[type="submit"] { width: 100%; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.metric { min-height: 118px; display: flex; flex-direction: column; justify-content: center; }
.metric .label { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.metric strong { display: block; margin-top: 9px; font-size: clamp(20px, 2.1vw, 30px); font-weight: 620; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metric strong a { color: var(--ink); font-size: 16px; letter-spacing: 0; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-head h2 { margin-bottom: 0; }
.actions, .actions-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.inline-form { display: inline; margin: 0; }

button,
.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--signal-strong);
  border-radius: 7px;
  padding: 8px 13px;
  color: #021311;
  background: var(--signal);
  box-shadow: 0 5px 18px rgba(41, 187, 174, .14);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}

button:hover,
.button:hover { background: #64e1d4; text-decoration: none; transform: translateY(-1px); }
button:active,
.button:active { transform: translateY(0); }
.secondary { border-color: var(--stroke-strong); color: var(--ink); background: #162638; box-shadow: none; }
.secondary:hover { background: #1c3045; }
.danger { border-color: rgba(255, 114, 124, .5); color: #ffdce0; background: rgba(145, 38, 50, .52); box-shadow: none; }
.danger:hover { background: rgba(171, 47, 61, .7); }

.table-wrap { overflow-x: auto; border: 1px solid var(--stroke); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid rgba(34, 54, 74, .78); }
th { color: #adc0d0; background: rgba(4, 10, 16, .38); font-size: 11px; font-weight: 700; letter-spacing: .025em; white-space: nowrap; }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover { background: rgba(103, 174, 252, .035); }
tbody tr:last-child td { border-bottom: 0; }

.muted { color: var(--muted); font-size: 12px; }
.pill { display: inline-block; margin: 2px 3px 2px 0; padding: 3px 7px; border: 1px solid transparent; border-radius: 4px; font-size: 11px; font-weight: 700; }
.ok { border-color: rgba(93, 214, 154, .22); color: #84e7b5; background: rgba(39, 132, 88, .16); }
.bad { border-color: rgba(255, 114, 124, .24); color: #ff9ba3; background: rgba(160, 44, 57, .17); }
.muted-pill { border-color: rgba(143, 163, 183, .18); color: #b4c2cf; background: rgba(143, 163, 183, .09); }
.error-text { max-width: 380px; margin-top: 7px; color: #ff9ba3; }

.messages { margin-bottom: 18px; }
.message { margin-bottom: 9px; padding: 12px 14px; border: 1px solid var(--stroke); border-left-width: 3px; border-radius: 7px; background: var(--surface); }
.message.success { border-left-color: var(--success); }
.message.error { border-left-color: var(--danger); }
.message.warning { border-left-color: var(--warning); }

.form-grid { display: grid; gap: 17px; }
.form-grid label { display: grid; gap: 7px; color: #c8d6e2; font-size: 13px; font-weight: 600; }
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--stroke-strong);
  border-radius: 7px;
  padding: 10px 11px;
  color: var(--ink);
  background: rgba(4, 10, 16, .54);
  font: inherit;
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

input::placeholder,
textarea::placeholder { color: #62788b; }
input:hover,
select:hover,
textarea:hover { border-color: #426582; }
input:focus,
select:focus,
textarea:focus { outline: 0; border-color: var(--signal); background: rgba(4, 10, 16, .78); box-shadow: 0 0 0 3px rgba(77, 212, 198, .11); }
textarea { min-height: 120px; resize: vertical; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.hint { margin-bottom: 0; color: var(--muted); font-size: 12px; font-weight: 400; }

.form-grid label.check-row { display: block; margin: 6px 0; color: #c8d6e2; }
.check-row { color: #c8d6e2; font-size: 13px; }
.check-row input { width: auto; margin-right: 8px; accent-color: var(--signal); }
.period-fields { border: 1px solid var(--stroke); border-radius: 8px; padding: 14px 16px 16px; background: rgba(4, 10, 16, .18); }
.period-fields legend { padding: 0 7px; color: var(--muted); font-size: 12px; font-weight: 600; }
.days-field { max-width: 220px; display: grid; gap: 7px; margin-top: 11px; }
.file-input { width: min(100%, 540px); padding: 7px; }
.file-input::file-selector-button { margin-right: 10px; border: 0; border-radius: 5px; padding: 7px 10px; color: var(--ink); background: #1c3045; font-weight: 600; cursor: pointer; }

.manual-match { margin: 15px 0; padding: 13px 15px; border: 1px solid var(--stroke); border-left: 3px solid var(--signal); border-radius: 7px; background: rgba(4, 10, 16, .3); }
.manual-match p { margin: 6px 0 0; }
.comment, .comment-cell { white-space: pre-wrap; overflow-wrap: anywhere; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

code {
  border: 1px solid var(--stroke);
  border-radius: 4px;
  padding: 2px 5px;
  color: #a7ede6;
  background: var(--canvas-deep);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: .92em;
}

.ip-search { width: min(100%, 340px); }
.site-footer {
  width: min(100% - 40px, 1400px);
  margin: 0 auto;
  padding: 18px 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-top: 1px solid var(--stroke);
  color: #71879a;
  font-size: 11px;
}
.footer-meta { display: flex; align-items: center; gap: 12px; }
.version-badge {
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 3px 8px;
  color: #8fded6;
  background: rgba(73, 198, 185, .07);
  font-weight: 700;
  letter-spacing: .04em;
}

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

@media (max-width: 900px) {
  .topbar { position: static; }
  .topbar-inner { padding: 14px 0; align-items: flex-start; flex-direction: column; gap: 12px; }
  nav { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .nav-logout { margin-left: auto; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .grid-3, .two-col, .three-col { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar-inner, .container, .site-footer { width: min(100% - 24px, 1400px); }
  .container { padding-top: 22px; }
  .brand-copy small { display: none; }
  nav > a, .nav-logout { padding: 8px; font-size: 12px; white-space: nowrap; }
  .card { padding: 17px; }
  .grid-3 { gap: 10px; }
  .actions-cell { min-width: 180px; }
  .site-footer, .footer-meta { align-items: flex-start; flex-direction: column; gap: 6px; }
}

/* Feed policy and review pages use the existing dashboard palette. */
.warning-pill { border-color: rgba(245,189,99,.3); color: var(--warning); background: rgba(245,189,99,.1); }
details.manual-match summary { cursor: pointer; overflow-wrap: anywhere; }
details.manual-match .form-grid { margin: 16px 0; }
.history-detail, td { overflow-wrap: anywhere; }
pre { max-width: 100%; overflow-x: auto; }
.topbar-inner nav { flex-wrap: wrap; }
@media (max-width: 1100px) { .topbar-inner { flex-wrap: wrap; gap: 8px; padding: 12px 0; } }

/* A source refresh stays visible while the server completes and saves it. */
.source-run-status { position: relative; display: grid; gap: 6px; margin: 14px 0; padding: 14px 18px; border: 1px solid var(--stroke-strong); border-left: 3px solid var(--signal); border-radius: var(--radius); background: var(--surface-raised); }
.source-run-status[hidden] { display: none; }
.source-run-status > span { color: var(--muted); font-size: 13px; }
.source-run-status .run-elapsed { color: var(--signal); font-variant-numeric: tabular-nums; }
.source-run-status.is-error { border-left-color: var(--danger); }
.source-run-status.is-finished { border-left-color: var(--success); }
.source-running { background: rgba(77, 212, 198, .07); }
.source-running .source-run-form button::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 7px; border: 2px solid var(--stroke-strong); border-top-color: var(--signal); border-radius: 50%; animation: source-spin .8s linear infinite; }
.run-progress-track { height: 3px; overflow: hidden; background: var(--stroke); border-radius: 3px; margin-top: 6px; }
.run-progress-track::after { content: ""; display: block; width: 30%; height: 100%; background: var(--signal); animation: source-progress 1.6s ease-in-out infinite alternate; }
@keyframes source-spin { to { transform: rotate(360deg); } }
@keyframes source-progress { from { transform: translateX(0); } to { transform: translateX(233%); } }
@media (prefers-reduced-motion: reduce) { .source-running .source-run-form button::before, .run-progress-track::after { animation: none; } }
