:root {
  color-scheme: dark;

  --bg:        #0b0d10;
  --surface:   #14181d;
  --surface-2: #1a1f26;
  --line:      #242b34;
  --line-soft: #1c222a;

  --text:      #e8eaed;
  --text-dim:  #9aa4b2;
  --text-mute: #6b7685;

  --accent:      #3b82f6;
  --accent-soft: #1d3a63;
  --ok:      #4ade80;
  --ok-bg:   #10331f;
  --warn:    #fbbf24;
  --warn-bg: #38300f;
  --err:     #f87171;
  --err-bg:  #3a1618;

  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand h1 { font-size: 17px; font-weight: 650; }

/* The connection dot is the single most useful pixel on this page: it tells you
   whether the dashboard is actually listening, or quietly showing you a stale view. */
.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: background 0.25s, box-shadow 0.25s;
  flex: none;
}
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.16); }
.dot.down { background: var(--err); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.16); }

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 13px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------- edit switch */
/* The one control on this page that changes what a physical tap does, so it
   gets to look like a switch rather than another ghost button. */
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mute);
  cursor: pointer;
  white-space: nowrap;
}
.switch-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px;
  display: block;
  transition: background 0.16s, border-color 0.16s;
  flex: none;
}
.switch-thumb {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: transform 0.16s, background 0.16s;
}
.switch.on { color: var(--ok); }
.switch.on .switch-track { background: var(--ok-bg); border-color: #2b5c3c; }
.switch.on .switch-thumb { transform: translateX(16px); background: var(--ok); }
.switch:hover .switch-track { border-color: var(--text-mute); }

@media (max-width: 620px) {
  /* On a phone the counts are the first thing to go -- the switch is why
     you opened the app. */
  .topbar-meta #stat-tags, .topbar-meta #stat-scans { display: none; }
}

/* --------------------------------------------------------------- banners */
#banner-area { padding: 0 24px; }
.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid transparent;
}
.banner.warn { background: var(--warn-bg); border-color: #574712; color: #fde68a; }
.banner.info { background: var(--accent-soft); border-color: #2c5490; color: #bfdbfe; }
/* A hard failure: the hub could not answer at all. Distinct from warn, which
   means "this works but something about it is wrong". */
.banner.err  { background: var(--err-bg); border-color: #6b2429; color: #fecaca; }
.banner strong { display: block; margin-bottom: 2px; color: inherit; }
.banner-icon { flex: none; font-size: 16px; line-height: 1.4; }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 48px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { font-size: 14px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.panel-actions { display: flex; gap: 8px; }
.hint { font-size: 13px; color: var(--text-mute); }

/* --------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter 0.12s, background 0.12s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { filter: brightness(0.94); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: #4a2226; color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-wide { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ------------------------------------------------------------------ feed */
.feed { max-height: 720px; overflow-y: auto; }

.scan {
  display: flex;
  gap: 13px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
}
.scan:last-child { border-bottom: 0; }

/* A new scan arriving is the payoff of the whole system. Make it land. */
@keyframes flash-in {
  from { background: var(--accent-soft); transform: translateY(-5px); opacity: 0; }
  to   { background: transparent; transform: none; opacity: 1; }
}
.scan.fresh { animation: flash-in 0.75s ease-out; }

.scan-icon {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 14px;
}
.scan-icon.ok      { background: var(--ok-bg);   color: var(--ok); }
.scan-icon.unknown { background: var(--warn-bg); color: var(--warn); }
.scan-icon.err     { background: var(--err-bg);  color: var(--err); }

.scan-main { min-width: 0; flex: 1; }
.scan-title { font-weight: 600; margin-bottom: 1px; }
.scan-sub { font-size: 13px; color: var(--text-mute); }
.scan-time {
  flex: none;
  font-size: 12px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-mute);
  border: 1px solid var(--line);
  margin-left: 6px;
  vertical-align: 1px;
}

/* "You" -- this scan carried your owner session, so it was your own phone
   rather than someone you handed a fob to. On a business-card tag that is the
   single most interesting fact in the row. */
.pill-you {
  background: var(--accent-soft);
  border-color: #2c5490;
  color: #bfdbfe;
}

/* ------------------------------------------------------ landing page links */
.link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 7px;
}
.link-row input[type=text] {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 8px 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
.link-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.link-primary-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-mute);
  cursor: pointer;
  user-select: none;
}
.link-primary-wrap input { accent-color: var(--accent); margin: 0; }

@media (max-width: 520px) {
  .link-row { grid-template-columns: minmax(0, 1fr) auto auto; }
  .link-row .link-url { grid-column: 1 / -1; }
}

/* ----------------------------------------------------------------- cards */
.cards { display: flex; flex-direction: column; }

.card-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background 0.1s;
}
.card-row:last-child { border-bottom: 0; }
.card-row:hover { background: var(--surface-2); }

.card-chip {
  flex: none;
  width: 38px; height: 26px;
  border-radius: 5px;
  background: linear-gradient(140deg, #2a3441, #171d24);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--text-mute);
}
.card-chip.written { border-color: #2b5c3c; color: var(--ok); }
.card-chip.stale   { border-color: #6b5410; color: var(--warn); }

.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 600; }
.card-sub {
  font-size: 12.5px;
  color: var(--text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-count {
  flex: none;
  font-size: 12px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ----------------------------------------------------------------- empty */
.empty { padding: 44px 28px; text-align: center; color: var(--text-mute); }
.empty-icon { font-size: 30px; margin-bottom: 12px; opacity: 0.7; }
.empty p { margin: 0 auto 8px; max-width: 46ch; font-size: 13.5px; }
.empty strong { color: var(--text-dim); }
.empty em { color: var(--text-dim); font-style: normal; font-weight: 600; }

/* ---------------------------------------------------------------- drawer */
.drawer-scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
  animation: fade-in 0.15s;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 21;
  overflow-y: auto;
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-inner { padding: 22px; }
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}
.drawer-head h2 { font-size: 20px; }
.drawer-head .card-id { font: 12px var(--mono); color: var(--text-mute); margin-top: 3px; }

.section { margin-bottom: 24px; }
.section > h3 {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  margin-bottom: 10px;
}

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.field-help { font-size: 12px; color: var(--text-mute); margin-top: 5px; }

/* The URL that gets physically written onto the card. It is the whole ballgame,
   so it gets to be the biggest thing in the drawer. */
.url-box {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 10px;
}
.url-box code {
  flex: 1;
  font: 13px var(--mono);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: #bfdbfe;
  word-break: break-all;
  line-height: 1.4;
}

.qr {
  display: block;
  width: 168px;
  height: 168px;
  margin: 14px auto 6px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}
.qr-caption { text-align: center; font-size: 12px; color: var(--text-mute); margin-bottom: 4px; }

.steps { counter-reset: step; padding: 0; margin: 0; list-style: none; }
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 30px;
  margin-bottom: 9px;
  font-size: 13.5px;
  color: var(--text-dim);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.steps strong { color: var(--text); font-weight: 600; }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.status-line.ok    { background: var(--ok-bg);   color: var(--ok); }
.status-line.warn  { background: var(--warn-bg); color: var(--warn); }
.status-line.idle  { background: var(--surface-2); color: var(--text-mute); }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 40;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
