:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1b1f1d;
  --muted: #66706b;
  --line: #dde1dc;
  --accent: #176b5b;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ed;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-soft: #fff4d6;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --card: #1b1f1d;
    --text: #e8ece9;
    --muted: #9aa49f;
    --line: #2e3532;
    --accent: #4fb89f;
    --accent-ink: #0d1412;
    --accent-soft: #1d3530;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --warn-soft: #3a3218;
  }
}

* { 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;
}
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
body.center main { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 20px 0 10px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
.card > h1:first-child, .card > h2:first-child { margin-top: 0; }
code { font-size: .9em; }
.wrap { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* Yläpalkki */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar form { margin: 0; }

/* Kortit ja asettelu */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { width: 100%; max-width: 440px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.grid.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stack-cards { display: grid; gap: 20px; }
@media (max-width: 900px) {
  .grid, .grid.settings { grid-template-columns: 1fr; }
}
.stack { display: grid; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Lomakkeet */
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text);
}
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[readonly] { opacity: .7; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, .button {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; text-decoration: none; color: var(--text); text-align: center;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.secondary, .button.secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 6px; }
button.icon { border: 0; background: none; font-size: 1.3rem; line-height: 1; padding: 4px 8px; color: var(--muted); }
button.icon:hover { color: var(--danger); }
button.big, .button.big { padding: 13px 24px; font-size: 1.1rem; }
button:disabled { opacity: .6; cursor: wait; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert.ok { background: var(--accent-soft); color: var(--accent); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); }
.err { color: var(--danger); }

/* Kuittilomake */
.lines { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.lines th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; padding: 0 4px 6px; }
.lines th.num { text-align: right; }
.lines td { padding: 3px 4px; vertical-align: middle; }
.lines td:nth-child(1) { width: 46%; }
.lines td:nth-child(2) { width: 10%; }
.lines td:nth-child(3) { width: 17%; }
.line-total { white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .lines thead { display: none; }
  .lines tr.line { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .lines tr.line td { padding: 0; width: auto !important; }
  .lines tr.line td:first-child { grid-column: 1 / -1; }
  .lines .line-total { align-self: center; }
}
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 0; margin-top: 10px; border-top: 2px solid var(--text); font-size: 1.1rem; }
.total-row strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

fieldset.payment { border: 0; padding: 0; margin: 8px 0 12px; display: flex; gap: 8px; flex-wrap: wrap; }
fieldset.payment legend { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.pill { display: block; }
.pill input { position: absolute; opacity: 0; }
.pill span { display: block; padding: 10px 18px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); font-size: 1rem; cursor: pointer; }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.inline-fields { display: flex; gap: 16px; align-items: end; margin-bottom: 12px; }
.inline-fields label { max-width: 200px; }
.change { padding-bottom: 10px; }
.email-field input { font-size: 1.1rem; }
details { margin: 12px 0; }
summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
details label { margin-top: 8px; }
.actions { margin-top: 18px; }
.actions button { width: 100%; }

.inline-form { display: flex; gap: 6px; margin: 0; }
.inline-form input { min-width: 160px; padding: 6px 8px; }
.inline-form button { padding: 6px 12px; white-space: nowrap; }

/* QR ja pino */
.qr-card { position: sticky; top: 16px; }
.qr { display: block; background: #fff; border-radius: 8px; padding: 8px; max-width: 230px; margin: 8px auto; }
.qr svg { display: block; width: 100%; height: auto; }
.qr-url { text-align: center; font-size: .875rem; margin: 4px 0 0; }
.live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 6px; animation: pulse 2s infinite; vertical-align: middle; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }
.inbox { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.inbox li { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
.inbox li.empty { border-style: dashed; padding: 10px 12px; font-size: .9rem; }
.inbox .pick { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 9px 12px; display: grid; }
.inbox .addr { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox .when { font-size: .8rem; color: var(--muted); }
.inbox li.fresh { animation: flash 2.5s ease-out; }
.inbox li.picked { border-color: var(--accent); background: var(--accent-soft); }
@keyframes flash { from { background: var(--warn-soft); } }

.qr-full { text-align: center; }
.qr-full h1 { font-size: 2.2rem; }
.qr-full p { font-size: 1.2rem; }
.qr.big { max-width: min(80vw, 60vh); padding: 16px; }

/* Listat */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.list td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: middle; }
table.list th.num { text-align: right; }
table.compact td { padding: 6px; }
.ua { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.big-total { font-size: 1.6rem; font-weight: 700; margin: 0 0 16px; }

/* Asiakkaan julkinen sivu – isot fontit puhelimelle */
body.public-body main { max-width: 560px; padding-top: 12vh; }
.public { width: 100%; text-align: center; }
.public h1 { font-size: 2rem; }
.public input[type=email] { font-size: 1.6rem; padding: 18px 14px; text-align: center; border-width: 2px; border-radius: 12px; }
.public button.huge { font-size: 1.5rem; padding: 18px; border-radius: 12px; width: 100%; }
.public.done p { font-size: 1.25rem; }
.check-mark { font-size: 4rem; color: var(--accent); line-height: 1; }
.center { text-align: center; }

/* Vakiotuotteiden pikapainikkeet */
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.product-btn {
  display: grid; gap: 2px; min-width: 112px; padding: 10px 14px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--accent-soft); color: var(--text);
}
.product-btn span { font-weight: 600; }
.product-btn small { color: var(--accent); font-variant-numeric: tabular-nums; }
.product-btn:hover { border-color: var(--accent); }
.product-btn:active { transform: scale(.97); }
tr.line.bump input { animation: flash 1.2s ease-out; }
.add-product { display: grid; grid-template-columns: minmax(0, 2fr) minmax(90px, 1fr) minmax(90px, 1fr) auto; gap: 10px; align-items: end; margin: 0 0 20px; }
@media (max-width: 640px) { .add-product { grid-template-columns: 1fr 1fr; } .add-product label:first-child { grid-column: 1 / -1; } }
table.products input, table.products select { padding: 6px 8px; }
table.products .sort { max-width: 80px; }
.row-actions form { display: flex; gap: 4px; margin: 0; white-space: nowrap; }
button.danger { color: var(--danger); }
table.products td:first-child { min-width: 180px; }
table.products td:nth-child(2) { min-width: 90px; }
table.products td:nth-child(3) select { min-width: 90px; }
@media (max-width: 760px) {
  table.products thead { display: none; }
  table.products tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.products td { border: 0; padding: 0; min-width: 0 !important; }
  table.products td:first-child, table.products td.row-actions { grid-column: 1 / -1; }
  table.products .sort { max-width: none; }
}
