:root {
  --bg: #0f1720;
  --panel: #16212d;
  --panel-2: #1c2a39;
  --line: #273a4e;
  --text: #e8eef5;
  --muted: #93a6bb;
  --accent: #f2a541;
  --link: #6cb6ff;
  --ok: #3ddc97;
  --warn: #ffc857;
  --danger: #ff6b6b;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f1ec; --panel: #ffffff; --panel-2: #f7f5f0; --line: #e0dbd0;
    --text: #1f2a36; --muted: #637285; --accent: #c4741a; --link: #1666c5;
    --ok: #12855a; --warn: #9a6a00; --danger: #c53030;
  }
}

* { box-sizing: border-box; }
/* Component display rules below would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--link); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.logo { width: 28px; height: 28px; border-radius: 7px; }
.brand h1 { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.who { color: var(--muted); }

main { max-width: 680px; margin: 0 auto; padding: 14px 16px 40px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }

.list { list-style: none; margin: 0 -16px; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; min-height: 48px; color: var(--text);
}
.row:active { background: var(--panel-2); }
.row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.row > span:last-child:not(:first-child) { flex-shrink: 0; text-align: right; }

.code { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: 4px; }
.where { font-size: 17px; margin: 6px 0 2px; }

.crumbs { font-size: 14px; margin: 2px 0 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs .sep { color: var(--line); }

.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge-missing { color: var(--danger); }
.badge-out { color: var(--warn); }
.badge-cat { color: var(--accent); }

.notice { background: var(--panel-2); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 6px; font-size: 14px; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; }
.history li + li { border-top: 1px solid var(--line); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { padding: 8px 0; }
.error { color: var(--danger); }

button {
  font: inherit; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 10px 16px; cursor: pointer;
}
button.link { border: 0; background: none; color: var(--link); padding: 4px 0; }
input {
  font: inherit; width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}

.signin { max-width: 380px; margin: 40px auto; text-align: center; }
.signin h2 { margin-bottom: 8px; }
#gsi-button { display: flex; justify-content: center; margin: 22px 0; min-height: 44px; }
#dev-login { display: grid; gap: 8px; margin-top: 24px; text-align: left; }

/* Search */
.search { position: sticky; top: calc(53px + env(safe-area-inset-top)); z-index: 5; margin: -14px -16px 14px; padding: 12px 16px; background: var(--bg); }
.search input { font-size: 18px; padding: 14px 16px; border-radius: 12px; background: var(--panel); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.result { align-items: flex-start; }
.row > .result-main { flex: 1; text-align: left; }
.result-name { display: block; font-weight: 600; }
.result-where { display: block; font-size: 14px; color: var(--muted); }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.results-card .list:first-child { margin-top: -8px; }
.smart-note { display: flex; align-items: center; gap: 8px; margin: 10px 0 2px; }
.ask-ai { margin-top: 6px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.results-card > .section-label:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.results-card > .empty:first-child { margin: 0; padding: 4px 0; }

/* Actions and forms (M3) */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions.center { justify-content: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  font: inherit; font-size: 15px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 9px 16px; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a1205; font-weight: 600; }
.btn:disabled { opacity: .6; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.add-link { display: inline-block; font-size: 14px; padding: 10px 0 2px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.danger { color: var(--danger); }

.form h2 { margin-bottom: 12px; }
.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, .field legend { font-size: 14px; font-weight: 600; }
.field em { font-weight: 400; font-style: normal; color: var(--muted); }
.field small { font-size: 12px; }
textarea, select {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.toggle { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 15px; }
.toggle input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.entry { display: flex; gap: 8px; margin: 12px 0 4px; }
.entry input { flex: 1; font-size: 17px; }
.inline-form { display: flex; gap: 8px; }
.inline-form select { flex: 1; }

.added { margin-top: 6px; }
.added .row { min-height: 44px; }

.nudge {
  margin: 10px 0 4px; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.nudge p { margin: 0; }
.nudge .actions { margin-top: 10px; }

.answer { margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--panel-2); }
.answer.good { background: color-mix(in srgb, var(--ok) 12%, var(--panel)); }
.answer p { margin: 0 0 6px; }
.answer .btn { margin-top: 8px; }

.filter { margin: 10px 0 4px; }
.pick { width: 100%; border: 0; background: none; text-align: left; font: inherit; color: var(--text); cursor: pointer; border-radius: 0; }
.section-label.first { border-top: 0; padding-top: 0; }
.big-code { font-size: 72px; font-weight: 800; color: var(--accent); margin: 4px 0; line-height: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast .link { color: var(--accent); font-weight: 600; }

/* "You may already have this" warning on the add screen */
.dup { background: color-mix(in srgb, var(--warn) 14%, var(--panel)); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.dup-list { list-style: none; margin: 8px 0 0; padding: 0; }
.dup-list li { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-top: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.dup-list li > span { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.dup-list .result-where { width: 100%; }
.dup-list .link { align-self: flex-start; text-align: left; }
