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

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #222636;
  --border:   #2a2d3a;
  --accent:   #7b61ff;
  --accent2:  #00d2b4;
  --text:     #e2e4ef;
  --muted:    #8b8fa8;
  --danger:   #ff7a8a;
  --warn:     #ffb454;
  --radius:   8px;
  font-size:  16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 1rem 1rem 4rem;
}

.page { max-width: 760px; margin: 0 auto; }
.grow { flex: 1; min-width: 0; }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.logo {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
header h1 { font-size: 1.25rem; letter-spacing: -0.02em; line-height: 1.2; }
header p  { font-size: 0.8rem; color: var(--muted); }
.session { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); }
.session[hidden] { display: none; }

/* ── Cards / text ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card.narrow { max-width: 480px; margin-inline: auto; }
.card[hidden], [hidden] { display: none !important; }
h2 { font-size: 1.15rem; margin-bottom: 0.5rem; }
p + p, p + form, p + ol, p + ul, ol + .actions, form p { margin-top: 0.75rem; }
.actions + p { margin-top: 1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; }

/* ── Forms ── */
label { display: block; margin-top: 1rem; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
textarea { resize: vertical; min-height: 4.5rem; }
input[type="color"] { padding: 0.2rem; height: 2.75rem; width: 4rem; cursor: pointer; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.hint { margin-top: 0.3rem; font-size: 0.78rem; color: var(--muted); }
.field-row { display: flex; gap: 0.75rem; }
.field-row > * { flex: 1; min-width: 0; }
.field-row > .narrow-field { flex: 0 0 7rem; }
.swatch-field { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.35rem; }
.swatch-field input { margin: 0; }

/* ── Buttons ── */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
button.ghost { border-color: transparent; color: var(--muted); }
button.small { min-height: 2rem; padding: 0.25rem 0.7rem; font-size: 0.85rem; }
form button.primary:only-child, #login-form button.primary { width: 100%; margin-top: 1.25rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.actions .button { flex: 1; }

.code {
  margin: 1rem 0;
  padding: 0.75rem;
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--accent2);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
ol { padding-left: 1.25rem; }
li + li { margin-top: 0.35rem; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.tabs button { flex: 1; min-height: 2.5rem; padding: 0.4rem 0.8rem; border: 0; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--surface2); box-shadow: inset 0 -2px 0 var(--accent2); }

/* ── Toolbar / chips ── */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type="search"] { margin: 0; flex: 1 1 10rem; }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chip { min-height: 2.25rem; padding: 0.3rem 0.8rem; font-size: 0.85rem; border-radius: 999px; color: var(--muted); }
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 12%, transparent); }
.check { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.85rem; cursor: pointer; }
.check input { width: auto; margin: 0; }

/* ── Stock list ── */
.group { margin-bottom: 1.5rem; }
.group h3 { margin-bottom: 0.5rem; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.rows { display: flex; flex-direction: column; gap: 0.5rem; }
.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.row.low { border-color: color-mix(in srgb, var(--warn) 60%, var(--border)); }
.row.out { border-color: color-mix(in srgb, var(--danger) 60%, var(--border)); }
.swatch {
  flex: 0 0 auto;
  width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}
.info { flex: 1; min-width: 0; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.sub { font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.badge { display: inline-block; margin-left: 0.4rem; padding: 0 0.45rem; font-size: 0.7rem; font-weight: 700; border-radius: 999px; color: #111; background: var(--warn); vertical-align: 0.1em; }
.badge.out { background: var(--danger); }
.stepper { display: flex; align-items: center; gap: 0.25rem; flex: 0 0 auto; }
.stepper button { min-width: 2.75rem; padding: 0.4rem; font-size: 1.25rem; line-height: 1; }
.stepper .qty { min-width: 3rem; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.icon { min-width: 2.25rem; padding: 0.3rem; color: var(--muted); border-color: transparent; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ── Rolls ── */
.summary { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.summary .big { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.summary .big span { color: var(--accent2); }
.rolls { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.75rem; }
.roll { padding: 0.9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.roll.finished { opacity: 0.65; }
.roll-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.roll-head .title { font-size: 1.05rem; }
.remaining { margin-top: 0.35rem; font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.remaining small { font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.bar { height: 6px; margin: 0.5rem 0 0.75rem; overflow: hidden; background: var(--surface2); border-radius: 999px; }
.bar > div { height: 100%; background: var(--accent2); border-radius: 999px; }
.roll-actions { display: flex; gap: 0.5rem; }
.roll-actions button { flex: 1; min-height: 2.5rem; padding: 0.3rem 0.5rem; }
.roll-actions .icon { flex: 0 0 auto; }

/* ── History ── */
.log { display: flex; flex-direction: column; gap: 0.4rem; }
.entry { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.entry .delta { flex: 0 0 4.5rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.delta.plus { color: var(--accent2); }
.delta.minus { color: var(--warn); }

/* ── Settings ── */
.panel { padding: 1.25rem; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.links { list-style: none; display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.links a { display: block; padding: 0.55rem 0.9rem; color: var(--text); text-decoration: none; border: 1px solid var(--border); border-radius: var(--radius); }
.links a:hover { border-color: var(--accent); }
.links li + li { margin-top: 0; }
.ok { color: var(--accent2); font-size: 0.9rem; }

/* ── Dialog / toast ── */
dialog {
  width: calc(100% - 2rem);
  max-width: 440px;
  margin: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
dialog[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 1.5rem); }
dialog form { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 1.25rem; }
/* Only the fields scroll; the title and the buttons stay on screen. */
dialog .fields { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 0.25rem; }
dialog h2 { margin-bottom: 0.25rem; }
dialog .actions { justify-content: flex-end; }
dialog .actions button { flex: 0 1 auto; }
dialog .actions .spacer { flex: 1; }
.presets { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.presets button { min-height: 2.25rem; padding: 0.2rem 0.8rem; }
#toast {
  position: fixed;
  left: 50%; bottom: 1.25rem;
  max-width: calc(100% - 2rem);
  padding: 0.7rem 1rem;
  transform: translateX(-50%);
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 10;
}
#toast.error { border-color: var(--danger); }
#toast:empty { display: none; }

@media (max-width: 480px) {
  body { padding-inline: 0.75rem; }
  .row { flex-wrap: wrap; }
  .row .stepper { margin-left: auto; }
  .session #who { display: none; }
}
