/* ------------------------------------------------------------
   Workshop Stock - mobile first, glove friendly.

   Rules that hold everywhere:
   - Minimum 56px tap targets.
   - Status is never colour alone: icon + text + colour.
   - Main actions sit low on the screen, within thumb reach.
------------------------------------------------------------ */

:root {
  --bg: #10141a;
  --surface: #1a2029;
  --surface-2: #242c38;
  --line: #36404f;
  --text: #f2f5f9;
  --text-dim: #9fadc0;

  --accent: #2f81f7;
  --accent-press: #1f6fe0;

  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --info: #58a6ff;

  --tap: 56px;
  --radius: 12px;
  --gap: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --line: #d3dae4;
    --text: #12161c;
    --text-dim: #5a6577;
    --accent: #1660cc;
    --accent-press: #0f4ea8;
    --ok: #1a7f37;
    --warn: #9a6700;
    --bad: #cf222e;
    --info: #0a58ca;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------------- header ---------------- */

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

.topbar h1 {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .back {
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  margin-left: -8px;
  background: none;
  border: 0;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  border-radius: 8px;
}
.topbar .back:active { background: var(--surface-2); }

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

main {
  flex: 1;
  padding: 16px 14px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.muted { color: var(--text-dim); }
.small { font-size: 14px; }
.center { text-align: center; }
.spacer { flex: 1; }

h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 22px 0 8px;
  font-weight: 650;
}
h2:first-child { margin-top: 0; }

/* ---------------- home grid ---------------- */

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 104px;
  padding: 16px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
.tile:active { background: var(--surface-2); }
.tile .glyph { font-size: 28px; line-height: 1; }
.tile.wide { grid-column: 1 / -1; min-height: 76px; flex-direction: row; gap: 12px; }
.tile.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tile.primary:active { background: var(--accent-press); }
.tile[aria-disabled="true"] { opacity: 0.55; }

/* ---------------- cards and rows ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.row:active { background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 14px; color: var(--text-dim); }
.row .chev { color: var(--text-dim); font-size: 20px; }
.row.static { cursor: default; }
.row.static:active { background: var(--surface); }

/* ---------------- status: icon + text + colour ---------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.status .glyph { font-size: 13px; }
.status.ok   { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad  { color: var(--bad); }
.status.info { color: var(--info); }
.status.dim  { color: var(--text-dim); }

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

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field { margin-bottom: 14px; }
.field .hint { font-size: 13px; color: var(--text-dim); margin-top: 6px; font-weight: 400; }

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.auto { width: auto; }

.btn-row { display: flex; gap: var(--gap); }
.btn-row .btn { flex: 1; }

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

.note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid currentColor;
  font-size: 15px;
}
.note .glyph { font-size: 16px; line-height: 1.4; }
.note .text { flex: 1; color: var(--text); }
.note.bad  { color: var(--bad); }
.note.warn { color: var(--warn); }
.note.ok   { color: var(--ok); }
.note.info { color: var(--info); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 13px 18px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
  font-size: 15px;
  display: flex;
  gap: 9px;
  align-items: center;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.ok  { border-color: var(--ok);  color: var(--ok); }
.toast .text { color: var(--text); }

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

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 40px 0; color: var(--text-dim); }

.empty { text-align: center; padding: 36px 16px; color: var(--text-dim); }
.empty .glyph { font-size: 34px; display: block; margin-bottom: 10px; }

.kv { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-dim); font-size: 14px; }
.kv .v { text-align: right; font-weight: 600; }

code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (min-width: 640px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); }
  .tile.wide { grid-column: 1 / -1; }
  main { padding: 22px 18px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

.tile-note {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.tile.wide .tile-note { margin-left: auto; }
