/* PaquetesKOI — plain, mobile-first stylesheet */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7783;
  --line: #e1e6ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --warn-bg: #fff5e6;
  --warn: #9a5b00;
  --ok: #15803d;
  --radius: 12px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111518;
    --surface: #1a2025;
    --text: #e6eaed;
    --muted: #9aa5af;
    --line: #2b333a;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --accent-soft: #123532;
    --warn-bg: #3a2a10;
    --warn: #f5c56b;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: .4rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 12px 16px; }

/* ---- top bar (desktop) / tab bar (mobile) ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand span { font-weight: 400; opacity: .85; }
.topnav { display: none; gap: 18px; }
.topnav a { color: inherit; text-decoration: none; opacity: .85; }
.topnav a[aria-current] { opacity: 1; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }

/* In a browser tab the tab bar sticks to the top: Safari on iPhone floats its own toolbar
   over the bottom of the page and would cover a bottom bar. */
.tabbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
/* Opened from the home-screen icon there is no browser toolbar: classic bottom tab bar. */
@media (display-mode: standalone), (display-mode: fullscreen) {
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-bottom: 0; border-top: 1px solid var(--line);
  }
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .75rem; color: var(--muted); text-decoration: none;
}
.tabbar .ico { font-size: 1.35rem; line-height: 1; }
.tabbar a[aria-current] { color: var(--accent); font-weight: 600; }

@media (min-width: 760px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 32px; }
  h1 { font-size: 1.6rem; }
}

/* ---- surfaces ---- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0;
}
details.panel > summary { cursor: pointer; font-weight: 600; }
details.panel[open] > summary { margin-bottom: 12px; }
.flash {
  background: var(--accent-soft); color: var(--text); border-left: 4px solid var(--accent);
  padding: 10px 12px; border-radius: 8px; margin: 4px 0 12px;
}
.alert {
  background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 8px; margin: 0 0 12px;
}
.alert-text { color: var(--warn); }
.ok { color: var(--ok); font-weight: 600; margin: 0 0 8px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head h1 { margin-bottom: .6rem; }
.back { text-decoration: none; font-size: .95rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }

/* ---- forms ---- */
label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; font-weight: 400; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 400; }
.grid2 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 480px) { .grid2 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 0; padding: 0; margin: 4px 0 12px; min-width: 0; }
legend { font-weight: 700; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-block { display: flex; width: 100%; }
.btn-big { min-height: 56px; font-size: 1.1rem; margin: 8px 0 12px; }

/* ---- home ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.stats strong { display: block; font-size: 1.5rem; }
.stats span { font-size: .78rem; color: var(--muted); }
.search { display: grid; gap: 8px; margin: 8px 0 4px; }
.search input, .search select { margin: 0; }
.hint { margin: 2px 0 8px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 4px; border-radius: 8px; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---- lists ---- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.cards > li { min-width: 0; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; color: inherit; text-decoration: none;
}
a.card:active { background: var(--accent-soft); }
.card.inactive { opacity: .55; }
.card form { margin: 0; }
.pkg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pkg-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit {
  flex: none; min-width: 64px; text-align: center; padding: 8px 6px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; font-variant-numeric: tabular-nums;
  text-decoration: none;
}
.unit.big { display: inline-block; font-size: 1.3rem; padding: 4px 10px; min-width: 0; }
.last4 { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.pill { flex: none; font-size: .75rem; font-weight: 700; padding: 4px 8px; border-radius: 999px; white-space: nowrap; background: var(--line); color: var(--text); }
.pill-received { background: var(--warn-bg); color: var(--warn); }
.pill-notified, .pill-sent, .pill-logged { background: var(--accent-soft); color: var(--accent); }
.pill-delivered { background: var(--line); color: var(--muted); }
.pill-failed { background: var(--warn-bg); color: var(--warn); }
.log { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: .9rem; }

/* ---- package detail ---- */
.label-photo { display: block; width: 100%; max-height: 360px; object-fit: contain; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.deliver h2 { margin-top: 0; }

/* ---- scan / review ---- */
.capture .row { align-items: stretch; }
.capture .row .btn { flex: 1; }
#preview { display: block; width: 100%; max-height: 260px; object-fit: contain; margin-top: 12px; border-radius: 10px; background: var(--bg); }
#preview[hidden] { display: none; }
.scan-status { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 12px 0 0; }
.scan-status[hidden] { display: none; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.picker { background: var(--bg); border-radius: 10px; padding: 12px; }
.choice { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice input { margin-top: 2px; }
.add-person summary { cursor: pointer; color: var(--accent); font-weight: 600; margin: 4px 0 10px; }
.suggest { margin: 0 6px 6px 0; }

/* ---- login ---- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { text-align: center; }

/* ---- htmx ---- */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-request.btn, .htmx-request .btn[type=submit] { opacity: .7; }
details.inline { display: inline-block; }
details.inline > summary { list-style: none; }
details.inline > summary::-webkit-details-marker { display: none; }

/* ---- notice channel choice ---- */
fieldset.via { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
fieldset.via legend { font-weight: 600; font-size: .9rem; margin: 0 0 6px; width: 100%; }
fieldset.via label.check { margin: 0; }
.search details.adv { margin: 4px 0 0; }
.search-summary { margin: 4px 0 8px; font-size: .95rem; }
