/* ============================================================
   TrackItDown — styles
   Light + dark via CSS variables and prefers-color-scheme.
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b2334;
  --muted: #5c6675;

  --accent: #2563eb;
  --accent-hover: #1d4fd7;
  --on-accent: #ffffff;
  --link: #2159cf;

  --nav-bg: rgba(255, 255, 255, 0.86);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);
  --ring: rgba(37, 99, 235, 0.25);

  --radius: 12px;
  --radius-sm: 8px;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  --ok-bg: #e3f4ea;   --ok-fg: #166d3c;
  --warn-bg: #fcf0d6; --warn-fg: #8a5b06;
  --bad-bg: #fde8e6;  --bad-fg: #b3251e;
  --gray-bg: #eceef2; --gray-fg: #566070;
  --info-bg: #e4edfd; --info-fg: #2156c8;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0e1320;
    --surface: #161d2e;
    --surface-2: #1d2537;
    --border: #2a3450;
    --text: #e6eaf2;
    --muted: #98a2b6;

    --accent: #4f83f7;
    --accent-hover: #6b97ff;
    --on-accent: #ffffff;
    --link: #8cb0ff;

    --nav-bg: rgba(14, 19, 32, 0.86);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    --ring: rgba(108, 152, 255, 0.35);

    --ok-bg: rgba(52, 199, 123, 0.16);   --ok-fg: #5ad191;
    --warn-bg: rgba(245, 185, 66, 0.16); --warn-fg: #f3c46e;
    --bad-bg: rgba(255, 99, 88, 0.16);   --bad-fg: #ff8b82;
    --gray-bg: rgba(148, 160, 180, 0.18); --gray-fg: #aab3c2;
    --info-bg: rgba(94, 142, 255, 0.18); --info-fg: #96b5ff;
  }
}

/* ---------------- base ---------------- */

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--link);
  text-decoration: none;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 0.4em;
}

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

main.container {
  flex: 1;
  padding-top: 28px;
  padding-bottom: 56px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.serial {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- top nav ---------------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.brand-mark { display: block; flex: none; }

.brand-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-accent { color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-links a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-links a.active {
  color: var(--info-fg);
  background: var(--info-bg);
}

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-outline {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-outline:hover:not(:disabled) { background: var(--info-bg); }

.btn-ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }

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

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

.card-title {
  font-size: 17px;
  margin-bottom: 14px;
}

.page > .card { margin-bottom: 20px; }
.page.narrow { max-width: 640px; margin: 0 auto; }

.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 26px; letter-spacing: -0.02em; }
.page-head p { margin: 0; }

.section-title {
  font-size: 17px;
  margin-bottom: 12px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.home-section { margin-top: 36px; }

/* ---------------- hero ---------------- */

.hero {
  text-align: center;
  padding: 52px 8px 12px;
}

.hero-title {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.hero-title .brand-accent { color: var(--accent); }

.tagline {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px;
}

.hero-sub {
  margin: 0 auto 26px;
  max-width: 480px;
}

.lookup {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto 18px;
}

.lookup-input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-transform: uppercase;
}

.lookup-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
  text-transform: none;
}

.lookup-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  outline: none;
}

.hero-ctas {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------------- stats ---------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.stat-card { text-align: center; padding: 18px 14px; }

.stat-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------------- item rows (recent list) ---------------- */

.list-card { padding: 0; overflow: hidden; }

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 18px;
  color: var(--text);
  border-top: 1px solid var(--border);
  transition: background 0.12s;
}

.item-row:first-child { border-top: 0; }
.item-row:hover { background: var(--surface-2); }

.item-row-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-row-main .serial { font-size: 12.5px; }

.item-row-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

/* ---------------- status badges ---------------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-active { background: var(--ok-bg); color: var(--ok-fg); }
.badge-lost { background: var(--warn-bg); color: var(--warn-fg); }
.badge-stolen { background: var(--bad-bg); color: var(--bad-fg); }
.badge-retired,
.badge-destroyed,
.badge-unknown { background: var(--gray-bg); color: var(--gray-fg); }

/* ---------------- item detail ---------------- */

.detail-title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.detail-title h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0;
}

.serial-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.serial-line-center { justify-content: center; }

.serial-big {
  font-size: 21px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
}

.detail-desc { margin: 0 0 16px; color: var(--muted); }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.meta-grid dt {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta-grid dd {
  margin: 2px 0 0;
  font-size: 15px;
  overflow-wrap: anywhere;
}

/* ---------------- timeline ---------------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 4px 0 0;
  position: relative;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: var(--border);
}

.tl-item {
  position: relative;
  padding: 0 0 22px 48px;
}

.tl-item:last-child { padding-bottom: 4px; }

.tl-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  border: 2px solid var(--surface);
}

.tl-good { background: var(--ok-bg); color: var(--ok-fg); }
.tl-warn { background: var(--warn-bg); color: var(--warn-fg); }
.tl-bad { background: var(--bad-bg); color: var(--bad-fg); }
.tl-info { background: var(--info-bg); color: var(--info-fg); }
.tl-gray { background: var(--gray-bg); color: var(--gray-fg); }

.tl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tl-type { font-weight: 700; }
.tl-time { font-size: 12.5px; }
.tl-note { margin: 4px 0 0; overflow-wrap: anywhere; }
.tl-meta { margin: 4px 0 0; font-size: 13px; }

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
}

.field-label em {
  font-style: normal;
  color: var(--bad-fg);
}

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

textarea { resize: vertical; }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  outline: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

.form-error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--bad-bg);
  color: var(--bad-fg);
  font-size: 13.5px;
  font-weight: 600;
}

/* ---------------- register confirmation ---------------- */

.confirm-panel {
  text-align: center;
  padding: 12px 4px;
}

.confirm-badge {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  background: var(--ok-bg);
  color: var(--ok-fg);
}

.confirm-panel h2 { font-size: 22px; }
.confirm-panel .serial-big { font-size: 24px; }

.hint {
  font-size: 13px;
  max-width: 420px;
  margin: 14px auto 18px;
}

.state-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ---------------- browse ---------------- */

.filters {
  display: grid;
  grid-template-columns: 1fr 190px 170px;
  gap: 10px;
  margin-bottom: 16px;
}

.result-count { margin: 0 0 10px; font-size: 13.5px; }

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

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

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

td .serial { font-size: 13px; font-weight: 600; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

/* ---------------- states (loading / error / empty) ---------------- */

.state {
  text-align: center;
  padding: 36px 20px;
  color: var(--muted);
}

.state h2 { color: var(--text); }
.state p { margin: 0 0 10px; }

.page-state {
  max-width: 520px;
  margin: 48px auto 0;
  padding: 40px 28px;
}

.state-error strong { color: var(--bad-fg); }

.spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 10px);
  z-index: 100;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-error { background: var(--bad-fg); color: #fff; }

/* ---------------- footer / misc ---------------- */

.footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  font-size: 13px;
  color: var(--muted);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.noscript {
  margin: 40px auto;
  max-width: 500px;
  text-align: center;
  color: var(--bad-fg);
}

.link { color: var(--link); font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------------- responsive ---------------- */

@media (max-width: 760px) {
  .hero { padding-top: 36px; }
  .hero-title { font-size: 36px; }
  .tagline { font-size: 17px; }

  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type="search"] { grid-column: 1 / -1; }
}

@media (max-width: 540px) {
  .nav-inner { padding: 8px 14px; }
  .brand-name { font-size: 17px; }
  .nav-links a { padding: 5px 9px; font-size: 13.5px; }

  .container { padding: 0 14px; }

  .lookup { flex-direction: column; }
  .lookup .btn { width: 100%; }

  .form-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }

  .card { padding: 16px; }

  .item-row-side .small { display: none; }

  .pager { flex-wrap: wrap; justify-content: center; }
}
