:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --ink: #14213d;
  --muted: #62708c;
  --line: #dfe5f0;
  --accent: #1d4ed8;
  --accent-dark: #1739a8;
  --accent-soft: #e8efff;
  --ok: #11703f;
  --ok-soft: #e6f6ec;
  --warn: #9a5b06;
  --warn-soft: #fdf3e0;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .05), 0 8px 24px rgba(20, 33, 61, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.015em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: .3em 0 .8em; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: .7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .82rem;
  letter-spacing: .02em;
}
.brand-text { font-weight: 700; font-size: 1rem; display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 500; font-size: .72rem; color: var(--muted); letter-spacing: .02em; }
.nav { margin-left: auto; display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav > a, .link-button {
  padding: .42rem .7rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: .86rem;
}
.nav > a:hover, .link-button:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav > a.active { background: var(--accent-soft); color: var(--accent-dark); }
.inline-form { display: inline; margin: 0; }
.link-button {
  border: 0;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

/* ------------------------------------------------------------------ page */
.page { max-width: 1180px; margin: 0 auto; padding: 1.6rem 1.25rem 3rem; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .09em;
  font-size: .7rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 .25rem;
}

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .6rem;
}
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat { display: flex; flex-direction: column; gap: .15rem; margin: 0; }
.stat-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.stat-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; }
.stat-value.small { font-size: 1rem; line-height: 1.35; }
.stat-note { font-size: .78rem; color: var(--muted); }
.stat.ok { border-left: 4px solid var(--ok); }
.stat.bad { border-left: 4px solid var(--bad); }

/* --------------------------------------------------------------- buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem .95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.button:hover { background: var(--surface-2); text-decoration: none; }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button.ghost { background: transparent; }
.button.danger { color: var(--bad); border-color: #f3c9c4; background: #fff; }
.button.danger:hover { background: var(--bad-soft); }
.button.small { padding: .3rem .55rem; font-size: .78rem; border-radius: 7px; }
.button.large { padding: .7rem 1.3rem; font-size: .95rem; }
.button.wide { width: 100%; margin-top: 1rem; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid #b9cbff;
  outline-offset: 2px;
}
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: 1.2rem 0 .4rem; }

/* ----------------------------------------------------------------- forms */
label { display: block; font-weight: 600; font-size: .84rem; margin: .6rem 0 .3rem; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], select {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .92rem;
}
input[type="text"]:focus, input[type="password"]:focus, input[type="email"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}
.form-row {
  display: flex;
  align-items: flex-end;
  gap: .8rem;
  flex-wrap: wrap;
}
.form-row .field { flex: 1 1 190px; margin: 0; }
.form-row .field label { margin-top: 0; }
.form-row .button { margin-bottom: 1px; }
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-weight: 500;
  font-size: .86rem;
  margin: 0;
  white-space: nowrap;
}
.checkbox input { width: auto; }

.auth-wrap { max-width: 430px; margin: 4vh auto 0; }
.auth-card { padding: 1.6rem; }
.auth-card h1 { margin-bottom: .2rem; }
.auth-card .muted { margin-bottom: 1rem; }

/* ---------------------------------------------------------------- upload */
.upload-form { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.dropzone {
  flex: 1 1 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  padding: 1.3rem 1rem;
  border: 2px dashed #c8d4ea;
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone-icon { font-size: 1.5rem; }
.dropzone-title { font-weight: 700; }
.dropzone-hint { font-size: .82rem; color: var(--muted); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.table-wrap.tall { max-height: 460px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  white-space: nowrap;
  z-index: 1;
}
.table tbody tr:hover { background: #fbfcff; }
.table tbody tr:last-child td { border-bottom: none; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table.compact th, .table.compact td { padding: .42rem .6rem; }
.table.compact { font-size: .84rem; }
.actions-cell { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.actions-cell form { margin: 0; }

.tag {
  display: inline-block;
  padding: .05rem .45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .03em;
  vertical-align: middle;
}
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.badge {
  display: inline-block;
  padding: .12rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

code { font-family: var(--mono); font-size: .82rem; }

/* ---------------------------------------------------------------- panels */
.panel { border-radius: var(--radius-sm); padding: .9rem 1.1rem; }
.panel h2 { font-size: 1rem; }
.panel-error { background: var(--bad-soft); border: 1px solid #f5cdc8; }
.panel-error h2 { color: var(--bad); }
.panel-warn { background: var(--warn-soft); border: 1px solid #f2dcae; }
.panel-warn h2 { color: var(--warn); }
.list { margin: .2rem 0 0; padding-left: 1.1rem; }
.list li { margin: .18rem 0; }
.ticks { list-style: none; margin: .2rem 0 0; padding: 0; }
.ticks li { position: relative; padding-left: 1.5rem; margin: .35rem 0; font-size: .88rem; color: #2b3a58; }
.ticks li::before { content: "✓"; position: absolute; left: 0; color: var(--ok); font-weight: 700; }

.status-pill {
  padding: .5rem .9rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: .82rem;
  white-space: nowrap;
}
.status-pill.ok { background: var(--ok-soft); color: var(--ok); }
.status-pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ----------------------------------------------------------------- flash */
.flashes { margin-bottom: 1rem; display: grid; gap: .5rem; }
.flash {
  padding: .65rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .89rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: #c4e8d2; }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: #f5cdc8; }
.flash-info { background: var(--accent-soft); color: var(--accent-dark); border-color: #cbdaff; }
.flash-detail { background: var(--surface); color: var(--muted); border-color: var(--line); }

/* ---------------------------------------------------------------- checks */
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.check-list li { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .7rem; border-radius: var(--radius-sm); background: var(--surface-2); }
.check-list li.pass .check-mark { background: var(--ok); }
.check-list li.fail .check-mark { background: var(--bad); }
.check-list li.fail { background: var(--bad-soft); }
.check-list span { display: block; }
.check-mark {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  background: var(--muted);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  margin-top: .1rem;
}

/* --------------------------------------------------------------- details */
details.reset { flex-basis: 100%; }
details.reset summary {
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent);
  padding: .2rem 0;
}
.reset-form { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: .3rem; }
.reset-form input[type="password"] { width: 210px; padding: .35rem .5rem; font-size: .8rem; }
.reset-form .checkbox { font-size: .76rem; }

.error-code { font-size: 2.6rem; font-weight: 800; color: var(--accent); margin: 0; letter-spacing: -.03em; }

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.2rem 1.25rem 2rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .76rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .page { padding: 1.1rem .8rem 2.5rem; }
  .grid-stats { grid-template-columns: 1fr; }
  .nav { width: 100%; }
  .card { padding: 1rem; }
  h1 { font-size: 1.35rem; }
  .table-wrap.tall { max-height: 62vh; }
}
