:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-alt: #f8f9f6;
  --text: #1c1f1c;
  --muted: #5d655e;
  --border: #d9ddd6;
  --primary: #1f5130;
  --primary-text: #ffffff;
  --primary-pressed: #173d24;
  --done: #e3f1e6;
  --error: #a4262c;
  --error-bg: #fbeaea;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --surface: #1d201d;
    --surface-alt: #232723;
    --text: #eef0ec;
    --muted: #a3aba4;
    --border: #333833;
    --primary: #4c9a64;
    --primary-text: #0b140e;
    --primary-pressed: #3d8153;
    --done: #1f3325;
    --error: #ff8a8a;
    --error-bg: #3a1a1b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

code { font-size: 0.92em; }

/* --- Top bar ------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--primary); color: var(--primary-text);
}
.brand { display: flex; align-items: baseline; gap: 12px; margin-right: auto; }
.topbar h1 { margin: 0; font-size: 21px; font-weight: 650; }
.screen-name { font-size: 16px; opacity: 0.85; }
.context, .account { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.context-label { font-weight: 600; }
.topbar .btn-quiet { color: inherit; border-color: currentColor; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px;
}
.narrow { max-width: 520px; margin: 40px auto; }
#signInView { text-align: center; }
#signInView p { color: var(--muted); margin: 0 0 20px; }
.panel h2 { margin: 0 0 20px; font-size: 22px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-weight: 600; }
.field input, .field select { font-weight: 400; }

input, select {
  height: var(--tap); padding: 0 12px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.panel input, .panel select { background: var(--bg); }

.hint { color: var(--muted); font-size: 14px; margin: 16px 0 0; }

.status { color: var(--muted); font-size: 15px; margin: 8px 4px 12px; }
.status:empty { display: none; }
.status-error {
  color: var(--error); background: var(--error-bg);
  padding: 12px 14px; border-radius: var(--radius);
}

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  font: inherit; font-weight: 600; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:active:not(:disabled) { background: var(--primary-pressed); }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--border); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-large { min-height: 52px; padding: 0 28px; font-size: 18px; }

/* --- List --------------------------------------------------------------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 4px; }
.toolbar .btn { min-height: var(--tap); }
.search { flex: 1 1 260px; }
.search input { width: 100%; }
.filter { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filter select, .filter input { min-width: 130px; color: var(--text); }
#packBtn { min-width: 120px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.list {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--border);
}
.list th, .list td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.list th {
  position: sticky; top: 0; background: var(--surface-alt);
  font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.list .num { text-align: right; font-variant-numeric: tabular-nums; }
.list tbody tr:last-child td { border-bottom: none; }
#shipmentRows tr { cursor: pointer; }
#shipmentRows tr:hover, #shipmentRows tr:focus-visible { background: var(--surface-alt); outline: none; }
.list tr.done td { background: var(--done); }

/* --- Pack --------------------------------------------------------------- */

.pack-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.pager { display: flex; align-items: center; gap: 10px; margin: 0 auto; }
.position { min-width: 90px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.pack-actions { display: flex; gap: 10px; }
.pack-actions:empty { display: none; }

.shipment-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 16px;
}
.shipment-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.shipment-head h2 { margin: 0; font-size: 26px; }
.muted { color: var(--muted); margin: 2px 0 0; }
.badge {
  padding: 4px 12px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: var(--primary); border: 1px solid var(--primary); white-space: nowrap;
}
.badge:empty { display: none; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 24px; margin: 18px 0 0;
}
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; white-space: pre-line; overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .pager { margin: 0; }
  .shipment-card { padding: 16px; }
}
