/* Kotivara: bright, happy, grim. Our own 1950s civil-defence poster look.
   No inline styles anywhere (strict CSP); widths come in as --w via the CSSOM. */

:root {
  --paper: #fff4dc;
  --paper-2: #fbe7bd;
  --ink: #2a1e14;
  --ink-soft: #6b5847;
  --sun: #ffc83d;
  --sun-soft: #ffe39a;
  --sky: #7fd3ee;
  --sky-deep: #2e8fb8;
  --cherry: #e5483b;
  --cherry-soft: #ffd2c9;
  --mint: #3fae7c;
  --mint-soft: #cdeedb;
  --orange: #f2862e;
  --line: #e2c48d;
  --display: "Futura", "Futura PT", "Century Gothic", "Avenir Next", "Trebuchet MS", sans-serif;
  --type: "American Typewriter", "Courier New", monospace;
  --body: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  --shadow: 4px 4px 0 var(--ink);
  --tabs-h: 64px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--body);
}

/* Halftone dots, only inside the app (the login stays plain). */
body.themed {
  background-image: radial-gradient(rgba(242, 134, 46, 0.13) 1.2px, transparent 1.6px);
  background-size: 14px 14px;
}

a { color: var(--sky-deep); }
h1, h2, h3 { font-family: var(--display); margin: 0; }
.loading { text-align: center; margin-top: 30vh; font: 700 28px var(--display); color: var(--ink-soft); }

/* ---------------------------------------------------------------- login (neutral) */

.login {
  max-width: 360px;
  margin: 0 auto;
  padding: 18vh 24px 40px;
  text-align: center;
}
.login-title { font-size: 44px; letter-spacing: 0.02em; }
.login-sub { color: var(--ink-soft); margin: 4px 0 28px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-msg { color: var(--cherry); min-height: 1.4em; }

/* ---------------------------------------------------------------- shell */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--sun);
  border-bottom: 3px solid var(--ink);
}
.brand {
  font: 800 20px var(--display);
  letter-spacing: 0.12em;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  font-size: 17px;
  line-height: 1;
}
.pill {
  font: 700 12px var(--type);
  padding: 3px 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
}
.pill-offline { background: var(--cherry-soft); }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 3px solid var(--ink);
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink-soft);
  text-decoration: none;
  font: 700 11px var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab.active { color: var(--ink); background: var(--sun-soft); }
.tab.active .tab-icon { transform: scale(1.12); }
.tab-dot {
  position: absolute;
  top: 8px;
  right: calc(50% - 20px);
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--sun);
}
.tab-dot.overdue { background: var(--cherry); }
.tab-count {
  position: absolute;
  top: 5px;
  right: calc(50% - 26px);
  min-width: 20px;
  padding: 0 5px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--cherry);
  color: #fff;
  font: 700 11px/16px var(--body);
}
.tab-count:empty { display: none; }

/* ---------------------------------------------------------------- building blocks */

.card {
  background: #fffaf0;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-sun { background: var(--sun-soft); }
.card-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }

.stamp {
  font: 800 14px var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  display: inline-block;
  align-self: flex-start;
  padding: 3px 10px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  transform: rotate(-1.2deg);
}
summary.stamp { cursor: pointer; }

.small { font-size: 14px; margin: 0; }
.muted { color: var(--ink-soft); font-size: 14px; }
.warn { color: var(--cherry); font-weight: 700; }
.empty { text-align: center; color: var(--ink-soft); padding: 18px 8px; margin: 0; }
.more { align-self: flex-end; font-weight: 700; }
.bullets { margin: 0; padding-left: 20px; font-size: 14px; display: grid; gap: 4px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 6px; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 700 15px var(--display);
  letter-spacing: 0.03em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--cherry); color: #fff; }
.btn-ok { background: var(--mint); color: #fff; }
.btn-danger { background: var(--ink); color: var(--paper); }
.btn-ghost { background: transparent; box-shadow: none; border-style: dashed; }
.btn-small { min-height: 34px; padding: 4px 12px; font-size: 13px; border-width: 2px; }
.btn-big { min-height: 56px; font-size: 18px; }
.btn-round { width: 44px; padding: 0; font-size: 22px; }
.icon-btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--paper);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  cursor: pointer;
}

input[type="text"], input[type="search"], input[type="password"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 16px var(--body); /* 16px: iOS does not zoom */
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .row.clickable:focus-visible {
  outline: 3px solid var(--sky-deep);
  outline-offset: 2px;
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--cherry); flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field[hidden] { display: none; }
.field-label { font: 700 13px var(--display); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); }
.field-hint { font-size: 12px; color: var(--ink-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; min-height: 36px; }
.form { display: flex; flex-direction: column; gap: 12px; }

.bar {
  display: block;
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
}
.bar-big { height: 16px; }
.bar-fill {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  background: var(--sun);
}
.tone-green .bar-fill { background: var(--mint); }
.tone-red .bar-fill { background: var(--cherry); }
/* A requirement's own bar follows its own score, not its category's colour. */
.bar-fill.fill-green { background: var(--mint); }
.bar-fill.fill-yellow { background: var(--sun); }
.bar-fill.fill-red { background: var(--cherry); }

/* ---------------------------------------------------------------- chips and lists */

.chip {
  font: 700 12px var(--type);
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper);
  white-space: nowrap;
}
.chip-expired { background: var(--ink); color: var(--paper); }
.chip-red { background: var(--cherry); color: #fff; }
.chip-yellow { background: var(--sun); }
.chip-ok { background: var(--mint-soft); }
.chip-unchecked { background: var(--sky); }
.chip-zero { background: var(--cherry-soft); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 2px dotted var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-main strong { overflow-wrap: anywhere; }
.row.clickable { cursor: pointer; border-radius: 8px; }
.row.clickable:active { background: var(--sun-soft); }
.row.zero strong { color: var(--ink-soft); }

.req { display: grid; grid-template-columns: 1fr 90px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 2px dotted var(--line); }
.req:last-child { border-bottom: 0; }
.req-off { opacity: 0.5; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar > input[type="search"] { flex: 1 1 200px; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg-btn { appearance: none; border: 0; background: var(--paper); padding: 8px 14px; font: 700 13px var(--display); color: var(--ink); min-height: 40px; cursor: pointer; }
.seg-btn.on { background: var(--ink); color: var(--paper); }
.groups { display: flex; flex-direction: column; gap: 16px; }

.notice {
  display: block;
  padding: 10px 14px;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--sky);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

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

.poster {
  position: relative;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  background: var(--sky);
}
.art-scene { display: block; width: 100%; height: auto; }
.bubble {
  margin: 0;
  padding: 10px 14px;
  background: #fff;
  border-top: 3px solid var(--ink);
  font: 700 16px/1.35 var(--type);
}
.celebrate .bubble { border: 3px solid var(--ink); border-radius: 12px; }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gauge-card, .vova-card { align-items: center; text-align: center; padding: 12px 10px; }
.gauge-card .stamp, .vova-card .stamp { align-self: center; font-size: 11px; letter-spacing: 0.1em; }
.art-gauge { width: 100%; max-width: 220px; height: auto; }
.gauge-label { font-family: var(--type); }
.big-pct { margin: -6px 0 0; font: 800 34px/1 var(--display); }
.small-pct { font-size: 22px; margin: 0; }
.tone-red .big-pct { color: var(--cherry); }
.tone-green .big-pct { color: var(--mint); }
.art-putin { width: 100%; max-width: 130px; height: auto; }
.vova-card { background: #fdf0f0; }

.banner {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--mint-soft);
}
.banner-soon { background: var(--sky); }
.banner-due { background: var(--sun); }
.banner-overdue {
  background: repeating-linear-gradient(-45deg, var(--cherry), var(--cherry) 14px, #d63a2d 14px, #d63a2d 28px);
  color: #fff;
}
.banner-overdue .btn-primary { background: var(--paper); color: var(--ink); }
.banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.banner-title { font: 800 18px var(--display); letter-spacing: 0.06em; }

.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
}
.cat.tone-green { background: var(--mint-soft); }
.cat.tone-yellow { background: var(--sun-soft); }
.cat.tone-red { background: var(--cherry-soft); }
.cat.tone-off { opacity: 0.6; }
.cat-name { font: 700 14px var(--display); }
.cat-pct { font: 800 22px/1 var(--display); }
.cat-warn { position: absolute; top: 8px; right: 10px; font: 700 12px var(--type); }

/* ---------------------------------------------------------------- inventory */

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  appearance: none;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  padding: 6px 12px;
  min-height: 36px;
  font: 700 13px var(--display);
  color: var(--ink);
  cursor: pointer;
}
.chip-btn.on { background: var(--ink); color: var(--paper); }
.checks { display: flex; flex-direction: column; gap: 12px; }
.check-card {
  background: #fffaf0;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.check-card.open { background: var(--sun-soft); }
.check-card p { margin: 0; }
.check-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.check-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.check-edit { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.stepper { display: flex; gap: 8px; align-items: center; }
.qty-input { max-width: 110px; text-align: center; font-weight: 700; }
.done-list summary { font: 700 15px var(--display); cursor: pointer; }
.finish { align-items: flex-start; }
.finish p { margin: 0; }

.celebrate-art { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; justify-items: center; }
.art-mascot-badge { width: 100%; max-width: 150px; height: auto; }

/* ---------------------------------------------------------------- shopping */

.shop-row .tick { display: flex; align-items: center; }
.shop-row.ticked strong { text-decoration: line-through; color: var(--ink-soft); }
.pick { display: flex; flex-direction: column; gap: 4px; }
.req-group { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.req-group h3 { font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; }

/* ---------------------------------------------------------------- dialogs, toast, scanner */

.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 var(--ink);
  background: var(--paper);
  color: var(--ink);
}
.modal::backdrop { background: rgba(42, 30, 20, 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; background: var(--sun); border-bottom: 3px solid var(--ink); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 14px 16px; overflow-y: auto; max-height: calc(100vh - 190px); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-top: 2px dotted var(--line); }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.details dt { font-weight: 700; }
.details dd { margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translate(-50%, 30px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { background: var(--mint-soft); }
.toast-error { background: var(--cherry-soft); }

.scan { display: flex; flex-direction: column; gap: 10px; }
.scan-frame { position: relative; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; background: var(--ink); aspect-ratio: 4 / 3; }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-line { position: absolute; left: 8%; right: 8%; top: 50%; height: 3px; background: var(--cherry); box-shadow: 0 0 10px var(--cherry); }
.scan-status { margin: 0; font-size: 14px; }
.scan-manual { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- print */

.print-sheet { background: #fff; border: 3px solid var(--ink); border-radius: var(--radius); padding: 16px; }
.print-head h1 { font-size: 22px; }
.print-head p { margin: 2px 0 12px; color: var(--ink-soft); }
.print-group { margin-bottom: 14px; }
.print-group h2 { font-size: 16px; border-bottom: 2px solid var(--ink); margin-bottom: 4px; }
.print-group table { width: 100%; border-collapse: collapse; font-size: 13px; }
.print-group th { text-align: left; font: 700 11px var(--display); text-transform: uppercase; color: var(--ink-soft); }
.print-group td, .print-group th { padding: 3px 6px; border-bottom: 1px solid #ddd; }
.print-group .box { width: 22px; font-size: 16px; }
.print-foot { font-size: 11px; color: var(--ink-soft); margin-top: 8px; }

@media print {
  @page { margin: 12mm; }
  body, body.themed { background: #fff; }
  .topbar, .tabs, .no-print, .toast { display: none !important; }
  .view { padding: 0; max-width: none; }
  .print-sheet { border: 0; padding: 0; }
  .print-group { break-inside: avoid; }
}

/* ---------------------------------------------------------------- small and large screens */

@media (max-width: 380px) {
  .duo { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .tab-label { font-size: 10px; }
}

@media (min-width: 720px) {
  .cats { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
