/* Perket — "sorting-desk ledger".
   A parcel app should look like the paperwork that comes with a parcel: label stock, ink, a ruled ledger.
   Lists are hairline-ruled rows, not floating cards; status is a small dot + word, never a pill.
   The one loud thing is time: how many days a parcel still waits for you, set big in IBM Plex Mono —
   the same face used for everything that is printed on a label (tracking numbers, codes, carriers).
   One accent from the pear in the logo; red only means "too late" or "broken". Dark mode is a lamp-lit desk, not a negative. */

@font-face {
  font-family: "Plex Mono";
  src: url("vendor/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("vendor/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* paper & ink */
  --paper: #eceee7;        /* label stock, faintly green */
  --slip: #f9faf5;         /* a printed slip lying on the desk: inputs, sheets, the pickup slip */
  --wash: #e1e4da;         /* hover / selected rows */
  --rule: #cdd1c4;         /* hairlines between rows */
  --rule-strong: #23281e;  /* the one heavier rule under a section heading */
  --ink: #1d2219;
  --ink-2: #474e41;
  --ink-3: #5e6656;        /* still ≥ 4.5:1 on paper */
  /* signal */
  --accent: #3f6212;       /* pear, darkened for text and controls */
  --accent-ink: #f7fbe9;
  --pear: #a3d139;         /* the pear itself: dots, focus halo, selection */
  --pear-wash: #dfeec0;
  --late: #b3261e;         /* overdue / error only */
  --late-wash: #f6dcd8;
  --wait: #8a5300;         /* review needed */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 6px;
  --r-slip: 10px;
  --nav-h: 60px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151912;
    --slip: #1e231a;
    --wash: #262c21;
    --rule: #30372a;
    --rule-strong: #c9cfbd;
    --ink: #e7eadf;
    --ink-2: #b4baa8;
    --ink-3: #959c88;
    --accent: #b9de5c;      /* under a lamp the pear glows: lighter, still not neon */
    --accent-ink: #18200b;
    --pear: #a3d139;
    --pear-wash: #2c3a14;
    --late: #ff8f80;
    --late-wash: #3d1d18;
    --wait: #e6b25a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
::selection { background: var(--pear); color: #1d2219; }

a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { text-wrap: balance; }

.mono, .tn, .code, .carrier, .countdown b { font-family: var(--mono); }
.mono { font-size: 0.93em; letter-spacing: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13.5px; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
}
.topbar-inner { max-width: 660px; margin: 0 auto; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.topbar h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar.is-home h1 { font-size: 21px; font-weight: 700; letter-spacing: -0.015em; }
.topbar .back { display: none; margin-left: -10px; }
.topbar.has-back .back { display: inline-flex; }
.brand-logo { display: none; width: 28px; height: 28px; flex: none; }
.topbar.is-home .brand-logo { display: block; }

.view { max-width: 660px; margin: 0 auto; padding: 0 var(--gutter) 40px; }

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
.nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  text-decoration: none;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.active { color: var(--ink); font-weight: 650; }
.nav a.active::before {
  content: "";
  position: absolute;
  top: -1px; left: 28%; right: 28%;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}
.nav .badge {
  position: absolute;
  top: 7px;
  left: calc(50% + 7px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--wait);
  color: var(--slip);
  font: 600 11px/18px var(--mono);
  text-align: center;
}
.nav .badge:empty { display: none; }
.nav-search { display: none; }

@media (min-width: 760px) {
  body { padding-bottom: 0; padding-left: 220px; }
  .nav {
    top: 0; right: auto; bottom: 0;
    width: 220px;
    height: auto;
    border-top: 0;
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    gap: 0;
  }
  .nav::before {
    content: "Perket";
    display: block;
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.015em;
    padding: 4px 10px 18px 46px;
    min-height: 32px;
    background: url("logo.svg") 8px 0 / 30px 30px no-repeat;
    color: var(--ink);
  }
  .nav-search { display: block; padding: 0 0 12px; }
  .nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px 10px;
    font-size: 15px;
    border-radius: var(--r);
  }
  .nav a:hover { background: var(--wash); }
  .nav a svg { width: 19px; height: 19px; }
  .nav a.active::before { top: 9px; bottom: 9px; left: -14px; right: auto; width: 3px; height: auto; border-radius: 0 2px 2px 0; }
  .nav .badge { position: static; margin-left: auto; }
  .topbar { padding-top: 24px; }
  .topbar.is-home .brand-logo { display: none; }
}

/* ---------- Sections: a heading on a strong rule, rows on hairlines ---------- */

.section { margin-top: 30px; }
.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 0 6px;
  margin: 0;
  border-bottom: 1px solid var(--rule-strong);
}
.section-head h2 { margin: 0; font-size: 16px; font-weight: 650; color: var(--ink); }
.section-head .count { margin-left: auto; font: 400 13px var(--mono); color: var(--ink-3); }
.section-head .btn.xs { margin-left: auto; }
.section-head:has(.btn.xs) .count { margin-left: 0; }
.section-note { margin: 8px 0 0; color: var(--ink-2); font-size: 13.5px; }

details.section > summary { list-style: none; cursor: pointer; user-select: none; min-height: 40px; align-items: center; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary .count { margin-right: 2px; }
details.section > summary .chev { display: inline-flex; color: var(--ink-3); transition: transform 0.15s; }
details.section > summary .chev svg { width: 18px; height: 18px; }
details.section:not([open]) > summary .chev { transform: rotate(-90deg); }
details.section:not([open]) > summary { border-bottom-color: var(--rule); }
details.section:not([open]) > summary h2 { color: var(--ink-2); }

.block { border-bottom: 1px solid var(--rule); }
.block:last-child { border-bottom: 0; }
.list > * + * { border-top: 1px solid var(--rule); }

/* ---------- Day line on Home ---------- */

.dayline { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.dayline b { color: var(--ink); font-weight: 600; }

/* ---------- Status: dot + word ---------- */

.st { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink-2); white-space: nowrap; line-height: 1.3; }
.st i { width: 8px; height: 8px; border-radius: 50%; flex: none; border: 1.5px solid var(--ink-3); }
.st.s-out_for_delivery, .st.s-ready_for_pickup, .st.s-delivered_neighbour { color: var(--ink); font-weight: 600; }
.st.s-out_for_delivery i, .st.s-ready_for_pickup i, .st.s-delivered_neighbour i { background: var(--pear); border-color: var(--accent); }
.st.s-shipped i, .st.s-in_transit i { border-color: var(--accent); }
.st.s-delivered i, .st.s-picked_up i, .st.s-returned i { background: var(--ink-3); border-color: var(--ink-3); border-radius: 2px; }
.st.s-delivered, .st.s-picked_up, .st.s-returned { color: var(--ink-3); }
.st.s-exception { color: var(--late); font-weight: 600; }
.st.s-exception i { background: var(--late); border-color: var(--late); }

.carrier { font-size: 12.5px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.02em; white-space: nowrap; }

/* ---------- Countdown: the loud element ---------- */

.countdown { flex: none; width: 64px; line-height: 1; }
.countdown b { display: block; font-size: 38px; font-weight: 600; letter-spacing: -0.04em; color: var(--ink); }
.countdown span { display: block; margin-top: 4px; font-size: 12.5px; color: var(--ink-2); }
.countdown.soon b { color: var(--ink); text-decoration: underline 4px var(--pear); text-underline-offset: 5px; }
.countdown.late b, .countdown.late span { color: var(--late); }
.countdown.late span { font-weight: 600; }

/* ---------- Home: ready-for-pickup ledger ---------- */

.ready-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0 14px;
  color: inherit;
  text-decoration: none;
}
.ready-row + .ready-row { border-top: 1px solid var(--rule); }
.ready-row .body { flex: 1; min-width: 0; padding-top: 2px; }
.ready-row .title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ready-row .sub { display: flex; gap: 8px; align-items: baseline; min-width: 0; margin-top: 3px; color: var(--ink-2); font-size: 13.5px; }
.ready-row .sub > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ready-row .dist { flex: none; color: var(--ink-3); }
.ready-row .sub > .carrier { flex: none; overflow: visible; }
.ready-row .when { margin-top: 2px; font-size: 13.5px; color: var(--ink-2); }
.ready-row.overdue .when { color: var(--late); font-weight: 600; }

/* ---------- Ship rows (inside orders, loose list, today) ---------- */

.ship-row {
  display: grid;
  grid-template-columns: 3.6em minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px 10px;
  padding: 10px 0;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.ship-row .mid { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.ship-row .label { min-width: 0; font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ship-row.loose .mid { flex-direction: column; align-items: flex-start; gap: 2px; }
.ship-row.loose .label { max-width: 100%; }
.ship-row.loose .label { order: -1; color: var(--ink); font-size: 15px; font-weight: 600; }
.ship-row .eta { text-align: right; font-size: 14px; color: var(--ink-2); white-space: nowrap; line-height: 1.3; }
.ship-row .eta strong { color: var(--ink); font-weight: 600; }
.ship-row .eta .small { display: block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
.ship-row .eta.urgent strong { color: var(--late); }
.ship-row.none { grid-template-columns: 1fr; color: var(--ink-3); font-size: 13.5px; }
a.ship-row:hover, a.ready-row:hover, a.list-row:hover, a.mail-row:hover { background: var(--wash); box-shadow: -8px 0 0 var(--wash), 8px 0 0 var(--wash); }

/* ---------- Orders ---------- */

.order { padding: 14px 0 6px; }
.order-head { display: flex; align-items: baseline; gap: 10px; color: inherit; text-decoration: none; padding-bottom: 4px; }
.order-head .grow { flex: 1; min-width: 0; }
.order-head .shop { font-weight: 650; font-size: 16px; }
.order-head .items { color: var(--ink-2); font-size: 14px; margin-top: 1px; }
.order-head .when { color: var(--ink-3); font-size: 13.5px; white-space: nowrap; }
.order .ship-row { border-top: 1px dotted var(--rule); }

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

.detail-head { padding: 6px 0 4px; }
.detail-head .label-line { display: flex; align-items: center; gap: 6px; }
.detail-head h2 { margin: 0; flex: 1; min-width: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; overflow-wrap: anywhere; }
.detail-head .of-order { margin-top: 4px; font-size: 14px; }
.detail-head .tn-line { display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; margin-top: 14px; }
.detail-head .tn { font-size: 15px; color: var(--ink); letter-spacing: 0.02em; overflow-wrap: anywhere; }
.detail-head .tn-line .btn.icon { margin-left: -4px; }
.detail-head .status-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.detail-head .status-text { color: var(--ink-2); font-size: 14px; }
.detail-head .status-at { margin-top: 2px; color: var(--ink-3); font-size: 13px; }
.detail-head .fact { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.detail-head .fact b { color: var(--ink); font-weight: 600; }
.retour { font-size: 13px; color: var(--ink-2); border: 1px solid var(--rule); border-radius: 3px; padding: 0 5px; }
.untrusted { font-size: 12.5px; color: var(--ink-3); border-bottom: 1px dashed var(--ink-3); cursor: help; }

.inline-edit {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: var(--r);
  padding: 6px 10px;
  background: var(--slip);
  font-size: 20px;
  font-weight: 650;
}
.inline-edit.mono { font-size: 14px; font-weight: 400; }
.editable { cursor: text; border-radius: 3px; }
.editable:hover { background: var(--wash); box-shadow: 0 0 0 3px var(--wash); }
.on-line { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }

/* ---------- The pickup slip: the only "object" on the desk ---------- */

.slip {
  margin-top: 22px;
  background: var(--slip);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-slip);
  padding: 16px;
}
.slip.overdue { border-color: var(--late); box-shadow: inset 4px 0 0 var(--late); }
.slip .deadline { display: flex; align-items: flex-end; gap: 14px; }
.slip .deadline .countdown { width: auto; }
.slip .deadline .countdown b { font-size: 56px; }
.slip .deadline .txt { padding-bottom: 2px; }
.slip .deadline .txt b { display: block; font-size: 16px; font-weight: 650; }
.slip .deadline .txt span { color: var(--ink-2); font-size: 13.5px; }
.slip .tear { border: 0; border-top: 1px dashed var(--ink-3); margin: 16px -16px; }
.slip .kind { color: var(--ink-2); font-size: 13.5px; }
.slip .name { font-weight: 650; font-size: 17px; margin-top: 1px; }
.slip .addr { color: var(--ink-2); margin-top: 1px; }

.code-box { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.code-box .lbl { font-size: 13px; color: var(--ink-2); }
.code-box .code { font-size: 34px; font-weight: 600; letter-spacing: 0.14em; line-height: 1.15; }
.code-box .code.masked { color: var(--ink-3); letter-spacing: 0.3em; }
.code-box .actions { margin-left: auto; display: flex; gap: 6px; }

.hours { margin-top: 14px; }
.hours summary { cursor: pointer; color: var(--ink-2); font-size: 14px; min-height: 32px; display: flex; align-items: center; gap: 4px; }
.hours summary b { color: var(--ink); font-weight: 600; }
.hours table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hours td { padding: 3px 0; color: var(--ink-2); border-top: 1px dotted var(--rule); }
.hours td:last-child { text-align: right; font-family: var(--mono); font-size: 13px; }
.hours tr.today td { color: var(--ink); font-weight: 600; }

.map { margin-top: 14px; height: 210px; border-radius: var(--r); overflow: hidden; background: var(--wash); position: relative; z-index: 0; border: 1px solid var(--rule); }
@media (prefers-color-scheme: dark) { .map .leaflet-tile-pane { filter: grayscale(0.4) brightness(0.8) contrast(1.05); } }

/* ---------- Timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 4px 0 0; }
.timeline li { position: relative; padding: 10px 0 10px 22px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 17px; width: 7px; height: 7px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink-3); }
.timeline li:first-child::before { background: var(--pear); border-color: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 7px; top: 28px; bottom: -12px; width: 1px; background: var(--rule); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 13px; color: var(--ink-3); }
.timeline .desc { color: var(--ink); }
.timeline li:not(:first-child) .desc { color: var(--ink-2); }

/* ---------- Order detail ---------- */

.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--rule); }
.item-list li:first-child { border-top: 0; }
.item-list img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; background: var(--wash); flex: none; }
.item-list .img-ph { display: none; }
.item-list .name { flex: 1; min-width: 0; }
.item-list .qty { color: var(--ink-3); font-size: 13px; font-family: var(--mono); }
.item-list .price { white-space: nowrap; color: var(--ink-2); }
.item-list li.total { border-top: 1px solid var(--rule-strong); font-weight: 650; }
.item-list li.total .price { color: var(--ink); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 14px; margin: 14px 0 0; }
.kv dt { color: var(--ink-3); margin: 0; }
.kv dd { margin: 0; min-width: 0; }
.kv dd.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

textarea.notes {
  display: block;
  width: 100%;
  min-height: 84px;
  margin-top: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--slip);
  padding: 10px 12px;
  resize: vertical;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); background: var(--wash); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--late); border-color: transparent; padding-left: 0; padding-right: 0; }
.btn.danger:hover { background: transparent; text-decoration: underline; }
.btn.ghost { border-color: transparent; color: var(--accent); padding-left: 6px; padding-right: 6px; }
.btn.ghost:hover { background: var(--wash); }
.btn.icon { width: 40px; height: 40px; min-height: 40px; padding: 0; border-color: transparent; }
.btn.icon svg { width: 19px; height: 19px; }
.btn.icon:hover { background: var(--wash); }
.btn.xs { min-height: 30px; padding: 3px 8px; font-size: 13px; }
.btn.icon.xs { width: 32px; height: 32px; min-height: 32px; }
.btn.icon.xs svg { width: 15px; height: 15px; }
.btn.block { width: 100%; }
.btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.icon, .btn.icon.xs { width: 44px; height: 44px; min-height: 44px; }
  .btn.xs { min-height: 44px; }
}

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.btn-row.center { justify-content: flex-start; }
.danger-zone { margin-top: 36px; padding-top: 10px; border-top: 1px solid var(--rule); }

.fab {
  position: fixed;
  right: var(--gutter);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  z-index: 25;
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}
.fab svg { width: 24px; height: 24px; }
@media (min-width: 760px) { .fab { bottom: 28px; right: 28px; } }

/* ---------- Empty, error, loading, banners ---------- */

.empty { padding: 16px 0 6px; color: var(--ink-2); font-size: 14px; max-width: 46ch; }
.empty strong { display: block; color: var(--ink); font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.empty span { display: block; }
.empty .btn-row { margin-top: 12px; }

.error {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  padding: 8px 0 8px 12px;
  border-left: 3px solid var(--late);
  color: var(--late);
  font-size: 14px;
}
.error button { margin-left: auto; }

.loading { color: var(--ink-3); padding: 20px 0; font-size: 14px; }

.banner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 6px 0 14px;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 14px;
  background: var(--wash);
  color: var(--ink-2);
}
.banner b { color: var(--ink); }
.banner.danger { background: var(--late); color: #fff; }
.banner.danger b { color: #fff; }
@media (prefers-color-scheme: dark) { .banner.danger { background: var(--late-wash); color: var(--late); } .banner.danger b { color: var(--late); } }
.banner.warn { background: transparent; border-left: 3px solid var(--wait); border-radius: 0; padding: 4px 0 4px 12px; }

.offline {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 6px var(--gutter);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  text-align: center;
}

.skel-wrap { padding: 10px 0; }
.skel { background: var(--wash); border-radius: 3px; }
.skel.hero { height: 60px; width: 60%; margin-bottom: 18px; }
.skel.row { height: 14px; margin: 18px 0; }
.skel.row:nth-child(odd) { width: 82%; }
.skel.row i { display: none; }

/* ---------- Generic list rows ---------- */

.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; min-height: 52px; color: inherit; text-decoration: none; }
.list-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-row b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row small { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--rule); }
.section-head + .row, .section-head + * > .row:first-child, .row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .desc { color: var(--ink-2); font-size: 13.5px; margin-top: 1px; }
.row .desc + .desc { margin-top: 4px; }
.row.go { color: inherit; text-decoration: none; }
.row.go:hover { background: var(--wash); box-shadow: -8px 0 0 var(--wash), 8px 0 0 var(--wash); }
.row.go .chev { color: var(--ink-3); display: flex; transform: rotate(-90deg); }
.row.go .chev svg { width: 18px; height: 18px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; border: 1.5px solid var(--ink-3); vertical-align: 0; }
.dot.ok { background: var(--pear); border-color: var(--accent); }
.dot.bad { background: var(--late); border-color: var(--late); }
.err-txt { color: var(--late); font-size: 13.5px; }

/* ---------- Search ---------- */

.search-box { position: relative; display: flex; align-items: center; margin: 4px 0 14px; }
.search-box .ico { position: absolute; left: 12px; display: flex; color: var(--ink-3); pointer-events: none; }
.search-box .ico svg { width: 17px; height: 17px; }
.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 8px 44px 8px 38px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--slip);
  font-size: 15px;
  -webkit-appearance: none;
}
.search-box input::placeholder { color: var(--ink-3); }
.search-box input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-box .clear { position: absolute; right: 2px; width: 40px; height: 40px; min-height: 40px; }
.search-box .clear svg { width: 16px; height: 16px; }
.search-box.compact { margin: 0 0 12px; }
.search-box.compact input { min-height: 40px; font-size: 14px; }
.nav-search .search-box input { padding-left: 34px; }
.nav-search .search-box .ico { left: 11px; }

.search-results { margin: 0 0 8px; }
.search-results .group { margin-bottom: 18px; }
.search-results .group-head { display: flex; gap: 8px; align-items: baseline; padding-bottom: 4px; border-bottom: 1px solid var(--rule-strong); font-weight: 650; font-size: 14px; }
.search-results .group-head .count { margin-left: auto; color: var(--ink-3); font: 400 13px var(--mono); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field .lbl { font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.field .hint { font-size: 13px; color: var(--ink-3); }
.field input, .field select, select.prio {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--slip);
}
.field input::placeholder { color: var(--ink-3); }
.field select, select.prio {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.field input:focus, .field select:focus, select.prio:focus, textarea:focus, .inline-edit:focus, .search-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.field .static { min-height: 42px; display: flex; align-items: center; overflow-wrap: anywhere; color: var(--ink-2); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field .suffix { display: flex; align-items: center; gap: 8px; }
.field .suffix input { flex: 1; }
.field .suffix span { color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .field-grid.stack { grid-template-columns: 1fr; } }
.form-block { padding: 14px 0 4px; }
.form-block > .field + .field, .form-block > .field + .field-grid, .form-block > .field-grid + .field { margin-top: 14px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--paper); border: 1.5px solid var(--ink-3); transition: background 0.15s, border-color 0.15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: var(--ink-3); transition: transform 0.15s, background 0.15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (pointer: coarse) { .switch::before { content: ""; position: absolute; inset: -8px; } }

.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; color: var(--ink-2); font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
@media (pointer: coarse) { .check { min-height: 44px; } }

/* ---------- Sheets ---------- */

dialog.sheet {
  width: 100%;
  max-width: 100%;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--rule-strong);
  border-radius: var(--r-slip) var(--r-slip) 0 0;
  background: var(--slip);
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(20, 24, 16, 0.45); }
dialog.sheet .sheet-body { max-width: 660px; margin: 0 auto; padding: 20px var(--gutter) calc(20px + env(safe-area-inset-bottom)); }
dialog.sheet h3 { margin: 0 0 14px; font-size: 19px; font-weight: 700; }
dialog.sheet .field + .field { margin-top: 14px; }
dialog.sheet .field input, dialog.sheet .field select { background: var(--paper); }
dialog.sheet.login p { margin: 0 0 16px; }
dialog.sheet.login .error { margin: 12px 0 0; }
@media (min-width: 760px) {
  dialog.sheet { max-width: 460px; margin: auto; border: 1px solid var(--rule-strong); border-radius: var(--r-slip); }
}
.quick-head { display: flex; align-items: baseline; gap: 10px; margin: -8px 0 16px; color: var(--ink-2); }
.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-actions .btn { min-height: 48px; }

.pick-list { max-height: 50vh; overflow: auto; border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule); }
.pick-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; min-height: 52px; cursor: pointer; }
.pick-row + .pick-row { border-top: 1px solid var(--rule); }
.pick-row:has(input:checked) { background: var(--pear-wash); }
.pick-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.pick-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-row b { font-weight: 600; }
.pick-row small { color: var(--ink-2); font-size: 13px; }

/* ---------- Toast ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(calc(100vw - 32px), 420px);
  pointer-events: none;
}
.toast { padding: 10px 14px; border-radius: var(--r); background: var(--ink); color: var(--paper); font-size: 14px; animation: toast-in 0.16s ease-out; }
.toast.err { background: var(--late); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.err { color: #1d0d0a; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@media (min-width: 760px) { .toasts { bottom: 24px; left: calc(50% + 110px); } }

/* ---------- Mails ---------- */

.seg { display: flex; gap: 22px; margin: 2px 0 14px; border-bottom: 1px solid var(--rule); }
.seg a { display: flex; align-items: center; gap: 6px; min-height: 44px; margin-bottom: -1px; color: var(--ink-2); font-weight: 550; text-decoration: none; border-bottom: 3px solid transparent; }
.seg a.on { color: var(--ink); font-weight: 650; border-bottom-color: var(--accent); }
.seg .count { font: 600 12px/18px var(--mono); color: var(--wait); }
.seg .count:empty { display: none; }

.mail-row { display: block; padding: 12px 0; color: inherit; text-decoration: none; }
.mail-row + .mail-row { border-top: 1px solid var(--rule); }
.mail-row.review { box-shadow: inset 3px 0 0 var(--wait); padding-left: 13px; }
.mail-row.review:hover { box-shadow: inset 3px 0 0 var(--wait), -8px 0 0 var(--wash), 8px 0 0 var(--wash); }
.mail-row .subject { font-weight: 600; overflow-wrap: anywhere; }
.mail-row .from { color: var(--ink-2); font-size: 13.5px; overflow-wrap: anywhere; }
.mail-row .meta { margin-top: 4px; }
.meta-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-size: 13px; color: var(--ink-3); }
.meta-line .parser { color: var(--ink-2); }
.meta-line .parser b { font-weight: 600; color: var(--ink); }
.meta-line .parser.p-none b { color: var(--wait); }
.meta-line .conf-txt { font-family: var(--mono); }
.meta-line .conf-txt.lo { color: var(--late); }
.dot-sep::before { content: "·"; margin: 0 6px; color: var(--ink-3); }
.review-tag { color: var(--wait); font-weight: 600; }

.mail-text {
  margin: 10px 0 0;
  max-height: 60vh;
  overflow: auto;
  padding: 12px 14px;
  background: var(--slip);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink-2);
}
.kv.parse { gap: 8px 14px; }
.kv.parse dt { white-space: nowrap; }
.kv.parse dd { overflow-wrap: anywhere; }
.kv.parse.nested { font-size: 13px; gap: 4px 12px; margin: 0; }
.kv-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; list-style: none; }
.kv-list > li { border-left: 2px solid var(--rule); padding-left: 10px; }

/* ---------- Rules ---------- */

.lede { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; max-width: 60ch; }
.rule { padding: 14px 0; border-top: 1px solid var(--rule); }
.section-head + .rule { border-top: 0; }
.rule .head { display: flex; align-items: flex-start; gap: 14px; }
.rule .head .grow { flex: 1; min-width: 0; }
.rule .title { font-weight: 600; }
.rule .desc { color: var(--ink-2); font-size: 13.5px; }
.rule.off .title { color: var(--ink-2); font-weight: 500; }
.rule.off .rule-opts { display: none; }
.rule-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 8px; font-size: 14px; }
.rule-opts .field { flex-direction: row; align-items: center; gap: 8px; }
.rule-opts .field label { white-space: nowrap; font-weight: 400; }
.rule-opts .field input[type=number] { width: 68px; min-height: 36px; padding: 4px 8px; }
.rule-opts .field input[type=text] { width: 140px; min-height: 36px; padding: 4px 8px; }
select.prio { width: auto; min-height: 36px; padding: 4px 30px 4px 8px; }
@media (pointer: coarse) { .rule-opts .field input, select.prio { min-height: 44px !important; } }

/* ---------- Settings & mailbox ---------- */

.mb-status { display: flex; align-items: flex-start; gap: 14px; padding: 14px 0 4px; }
.mb-status .grow { flex: 1; min-width: 0; }
.mb-status .state { font-size: 18px; font-weight: 650; display: flex; align-items: center; gap: 2px; }
.mb-status .state.bad { color: var(--late); }
.mb-status .desc { color: var(--ink-2); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.source { font-size: 13px; color: var(--ink-2); white-space: nowrap; border: 1px solid var(--rule); border-radius: 3px; padding: 1px 6px; }
.source.none { color: var(--late); border-color: currentColor; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; padding: 0; border: 0; }
.presets legend { padding: 0; margin-bottom: 6px; font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.presets label { position: relative; }
.presets input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.presets span { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 12px; border: 1px solid var(--rule); border-radius: var(--r); font-size: 14px; font-weight: 550; color: var(--ink-2); background: var(--slip); }
.presets input:checked + span { border-color: var(--accent); color: var(--ink); background: var(--pear-wash); box-shadow: inset 0 0 0 1px var(--accent); }
.presets input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (pointer: coarse) { .presets span { min-height: 44px; } }
.server-line { margin-top: 8px; font-size: 13px; color: var(--ink-3); }

.help { margin: 16px 0 2px; padding: 12px 14px 12px 0; border-left: 0; font-size: 14px; color: var(--ink-2); }
.help ol { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.help ol li { counter-increment: step; position: relative; padding: 0 0 8px 30px; }
.help ol li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--ink-3); font: 600 11.5px/18px var(--mono); text-align: center; color: var(--ink); }
.help b { color: var(--ink); font-weight: 600; }
.help .note { margin: 4px 0 0 30px; padding-left: 10px; border-left: 2px solid var(--pear); }

details.adv { margin-top: 18px; border-top: 1px solid var(--rule); }
details.adv > summary { min-height: 44px; display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--ink-2); font-size: 14px; font-weight: 550; list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary svg { width: 16px; height: 16px; transform: rotate(-90deg); transition: transform 0.15s; }
details.adv[open] > summary svg { transform: none; }
details.adv .field-grid { margin-bottom: 8px; }

.test-result { margin-top: 14px; padding: 8px 0 8px 12px; font-size: 14px; border-left: 3px solid var(--rule); }
.test-result b { display: block; color: var(--ink); }
.test-result.ok { border-left-color: var(--accent); }
.test-result.ok b::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--pear); border: 1.5px solid var(--accent); margin-right: 7px; vertical-align: 1px; }
.test-result.fail { border-left-color: var(--late); color: var(--ink-2); }
.test-result.fail b { color: var(--late); }
.test-result.busy { color: var(--ink-3); }

.foot { margin-top: 36px; color: var(--ink-3); font-size: 13px; }

/* ---------- Motion / focus (keep last) ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
details.section > summary:focus-visible { outline-offset: 0; }
