/* Barry's Tracker — hand-written CSS, no build step, no framework.
   Light and dark are both supported via prefers-color-scheme. */

:root {
  --bg:          #f6f7f9;
  --surface:     #ffffff;
  --surface-alt: #f0f2f5;
  --border:      #dfe3e8;
  --text:        #1a1d21;
  --text-muted:  #646d7a;
  --accent:      #2563eb;
  --accent-soft: #e8effe;
  --good:        #0f7b45;
  --good-soft:   #e3f4ea;
  --warn:        #9a6400;
  --warn-soft:   #fdf3e0;
  --bad:         #b32020;
  --bad-soft:    #fceceb;
  --radius:      8px;
  --shadow:      0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #14161a;
    --surface:     #1c1f24;
    --surface-alt: #23272e;
    --border:      #2f343c;
    --text:        #e8eaed;
    --text-muted:  #9aa3af;
    --accent:      #5b8def;
    --accent-soft: #1e2a41;
    --good:        #4ac07f;
    --good-soft:   #16301f;
    --warn:        #e0a53a;
    --warn-soft:   #322612;
    --bad:         #f0736b;
    --bad-soft:    #35191a;
    --shadow:      0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------------------------------------------------------------- layout -- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 56px;
}

.brand { font-weight: 650; letter-spacing: -.01em; color: var(--text); }
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: 4px; flex: 1; }

.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
}
.nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.nav .badge-dot {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 9px;
  background: var(--bad);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 18px;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.mono  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ----------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h2 { margin: 0; }
.card-body { padding: 16px; }

/* Row under a table: the count on the left, the page-size control on the right.
   Mirrors .card-head so a card reads the same top and bottom. */
.list-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
/* margin-left:auto rather than justify-content:space-between on the parent. With
   space-between, a narrow screen wraps the control onto its own line — where it
   becomes the only item on that line and flex puts it back at the LEFT. Pushing
   it with auto margin keeps it right whether it wraps or not. */
.list-foot label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-bottom: 0;   /* the base `label` rule adds 5px, which misaligns the row */
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ------------------------------------------------------------ stat tiles -- */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat-label {
  font-size: 12px;
  font-weight: 550;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.stat-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.stat.is-bad  .stat-value { color: var(--bad); }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-good .stat-value { color: var(--good); }

/* ---------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ----------------------------------------------------------------- pills -- */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 550;
  background: var(--surface-alt);
  color: var(--text-muted);
  white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad  { background: var(--bad-soft);  color: var(--bad);  }
.pill.info { background: var(--accent-soft); color: var(--accent); }

/* ----------------------------------------------------------------- forms -- */

label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 5px; }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], input[type=search], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea { min-height: 70px; resize: vertical; }

.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }

.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }

.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; }
.filters input, .filters select { min-width: 170px; }

/* -------------------------------------------------------------- messages -- */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash.ok  { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.flash.err { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad); }

.notice {
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  color: var(--warn);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 20px;
}
.notice strong { font-weight: 650; }

/* ----------------------------------------------------------------- login -- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.login-card h1 { margin-bottom: 4px; }

/* ------------------------------------------------------------- utilities -- */

details.inline-form > summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 550;
  color: var(--accent);
  list-style: none;
  padding: 4px 0;
}
details.inline-form > summary::-webkit-details-marker { display: none; }
details.inline-form > summary::before { content: "+ "; }
details.inline-form[open] > summary::before { content: "− "; }
details.inline-form > div { padding-top: 12px; }

pre.payload {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0;
}

.stack > * + * { margin-top: 16px; }
.row-actions { display: flex; gap: 6px; align-items: center; }
