/* Keeper — one stylesheet, mobile first, light and dark. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14161a;
  --muted: #666d78;
  --line: #d9dde3;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --warn-bg: #fff4e0;
  --warn-line: #e0a94a;
  --warn-text: #6d4a06;
  --danger: #c0362f;
  --radius: 10px;
  --gap: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2126;
    --surface-2: #262a31;
    --text: #e8eaee;
    --muted: #9aa2ad;
    --line: #333941;
    --accent: #5b91e8;
    --accent-text: #0e1116;
    --warn-bg: #3a2f18;
    --warn-line: #a5791f;
    --warn-text: #f0d49a;
    --danger: #e2695f;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

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

h1 { font-size: 1.35rem; margin: 0; }
h2.section { font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 10px; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* --- chrome --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; color: var(--text); letter-spacing: -.02em; }

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--muted);
  white-space: nowrap;
  font-size: .92rem;
}
.tab:hover { background: var(--surface-2); text-decoration: none; }
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.topbar-end { display: flex; align-items: center; gap: 8px; }

.scanbtn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
}
.scanbtn:hover { background: var(--surface-2); text-decoration: none; }

.inline { display: inline; margin: 0; }

/* One small button per language we are not currently reading in. */
.langswitch { display: flex; align-items: center; gap: 2px; }
.langswitch .linkish {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  letter-spacing: .04em;
}

.linkish {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
  padding: 6px 4px;
}
.linkish:hover { color: var(--text); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 16px 14px 64px; }

.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.pagehead-actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }

input[type=text], input[type=search], input[type=password], input[type=number],
input[type=file], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
textarea { min-height: 80px; resize: vertical; }

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

button, .btn {
  display: inline-block;
  padding: 10px 16px;
  font: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }

button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }

button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius);
  margin: 0 0 14px;
}

.empty { color: var(--muted); font-style: italic; padding: 18px 0; }
.hint { color: var(--muted); font-size: .85rem; }

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

.loginbox {
  max-width: 340px;
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.loginbox h1 { margin-bottom: 2px; }
.loginbox .sub { margin: 0 0 20px; color: var(--muted); font-size: .9rem; }
.loginbox button { width: 100%; }
/* The switcher sits under the hint, centred, and keeps its own button width. */
.loginbox .langswitch { justify-content: center; margin-top: 14px; }
.loginbox .langswitch button { width: auto; }

/* --- dashboard ------------------------------------------------------------ */

.bigsearch { display: flex; gap: 8px; margin-bottom: 16px; }
.bigsearch input { margin-top: 0; font-size: 1.05rem; padding: 13px 14px; }

.quickrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.quick {
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: .92rem;
}
.quick:hover { background: var(--surface-2); text-decoration: none; }

.notice {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-text);
  padding: 11px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: .92rem;
}
.notice:hover { text-decoration: none; filter: brightness(1.03); }
.notice-go { margin-left: auto; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  color: var(--text);
}
.stat:hover { background: var(--surface-2); text-decoration: none; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* --- item grid ------------------------------------------------------------ */

.itemgrid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  height: 100%;
}
.card:hover { text-decoration: none; border-color: var(--accent); }

.thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-blank { color: var(--muted); font-size: .78rem; }

.swatch {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .2);
}

.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.card-title { font-weight: 600; font-size: .95rem; }
.qty { color: var(--muted); font-weight: 400; font-size: .85rem; }
.card-cat { font-size: .78rem; color: var(--muted); }
.card-where { font-size: .8rem; color: var(--muted); }

/* --- badges and hints ----------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }

.hint {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
}

/* --- rows (racks, boxes) -------------------------------------------------- */

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
}
.row:hover { border-color: var(--accent); text-decoration: none; }

.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub, .row-meta { font-size: .82rem; color: var(--muted); }
.row-meta { text-align: right; white-space: nowrap; display: flex; align-items: center; gap: 6px; }

/* --- forms: inline row, and stacked ---------------------------------------- */

.rowform {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.rowform label { margin-bottom: 0; }
.rowform .grow { flex: 1; min-width: 160px; }
.rowform .narrow { width: 110px; flex: none; }
.rowform button { white-space: nowrap; }

.stack {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 620px;
}
.pair { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.pair .grow { flex: 1; min-width: 160px; }
.pair .narrow { width: 120px; flex: none; }

.actions { display: flex; gap: 8px; margin-top: 8px; }
.dangerzone { margin-top: 42px; padding-top: 16px; border-top: 1px dashed var(--line); }

.lead { max-width: 62ch; margin-top: -6px; }
.note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 10px 14px;
  white-space: pre-wrap;
}

/* --- box page ------------------------------------------------------------- */

.boxhead { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.boxhead .hint { font-size: 1.5rem; padding: 4px 12px; }
.boxhead-main { flex: 1; min-width: 200px; }
.boxhead-sub { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: .88rem; margin-top: 3px; }
.boxhead-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.boxcode { background: var(--surface-2); border-radius: 5px; padding: 1px 6px; letter-spacing: .08em; }

/* --- sub tabs and pick lists ---------------------------------------------- */

.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .9rem;
}
.subtab:hover { text-decoration: none; background: var(--surface-2); }
.subtab.active { border-color: var(--accent); color: var(--text); font-weight: 600; }
.subtab .count {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0 7px;
  font-size: .78rem;
  font-weight: 600;
}

.row.pick { cursor: pointer; }
.row.pick input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.selectall { display: flex; align-items: center; gap: 8px; margin: 6px 2px 10px; color: var(--muted); font-size: .88rem; }
.selectall input { width: 16px; height: 16px; accent-color: var(--accent); }

/* --- category picker ------------------------------------------------------ */

.catpicker { margin-bottom: 12px; }
.catresults { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.catresults:empty { display: none; }

.catresult {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: .92rem;
}
.catresult:hover { background: var(--surface-2); border-color: var(--accent); }
.catresult .count { color: var(--muted); font-size: .8rem; }

.catcreate {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: .9rem;
  color: var(--muted);
}
.catcreate select { width: auto; margin-top: 0; padding: 6px 8px; }
.catcreate button { padding: 6px 12px; }

.catchosen { margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: .9rem;
}
.chipx {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}
.chipx:hover { color: var(--danger); }
.inline-error { margin: 0; padding: 4px 10px; font-size: .85rem; }

.catrow { gap: 8px; }
.catrow .indent { color: var(--muted); white-space: pre; font-family: ui-monospace, monospace; }
.catrow input[type=text] { margin-top: 0; }
.catrow select { margin-top: 0; width: auto; max-width: 180px; }
.catrow button { padding: 8px 12px; }

/* --- colour swatches ------------------------------------------------------ */

.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.swatchpick { margin: 0; cursor: pointer; }
.swatchpick input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatchpick .dot {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 2px var(--surface);
}
.swatchpick.none .dot {
  background: linear-gradient(135deg, transparent 45%, var(--muted) 45%, var(--muted) 55%, transparent 55%);
}
.swatchpick input:checked + .dot { border-color: var(--accent); border-width: 3px; }
.swatchpick input:focus-visible + .dot { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.inline { position: static; display: inline-block; vertical-align: -2px; margin-right: 6px; }

/* --- search --------------------------------------------------------------- */

.searchform {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
}
.searchbox { font-size: 1.1rem; padding: 13px 14px; margin-top: 0; }
.filters { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.filters .grow { flex: 1 1 260px; }
.filters select[multiple] { height: auto; }
.filtercol { flex: 1 1 260px; display: flex; flex-direction: column; gap: 8px; }
.filterlabel { color: var(--muted); font-size: .9rem; }
.searchform .actions { margin-top: 12px; }

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

.itemview { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.itemphoto { flex: 0 1 380px; }
.itemphoto img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
}
.itemfacts { flex: 1 1 260px; }
.itemfacts dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 12px; }
.itemfacts dt { color: var(--muted); font-size: .85rem; }
.itemfacts dd { margin: 0; }

.currentphoto { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.currentphoto img { width: 90px; border-radius: 8px; border: 1px solid var(--line); display: block; }

/* --- scanner -------------------------------------------------------------- */

.scanner {
  position: relative;
  max-width: 480px;
  aspect-ratio: 3 / 4;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner.unsupported { aspect-ratio: auto; background: var(--surface); }
.scanner.unsupported video { display: none; }

.scanstatus {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .9rem;
}
.scanstatus.ok { background: rgba(30, 120, 60, .8); }
.scanstatus.warn { background: rgba(160, 100, 10, .85); }
.scanner.unsupported .scanstatus { position: static; background: none; color: var(--muted); }

/* --- history -------------------------------------------------------------- */

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.history li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: .86rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.hist-action { font-weight: 600; }
.hist-detail { color: var(--muted); flex: 1; min-width: 0; }
.hist-meta { color: var(--muted); font-size: .8rem; margin-left: auto; white-space: nowrap; }

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 8px; }
  .rowform .narrow { width: 90px; }
  .row-meta { text-align: left; }
}
