/* Code Logistic Tech palette: brand green #2C967D, deep green #1C5F4F, slate #2B3432 (from code-logistic-tech.co.uk).
   --accent is a deeper cut of the brand green so white button text passes WCAG AA (5.2:1). */
:root {
  color-scheme: light;
  --brand: #2c967d;
  --brand-deep: #1c5f4f;
  --brand-hero: linear-gradient(160deg, #1a5b41 0%, #1c5f4f 45%, #2c967d 100%);
  --on-brand: #ffffff;
  --bg: #f2f6f5;
  --surface: #ffffff;
  --surface-2: #e9f0ee;
  --text: #2b3432;
  --muted: #5a6b67;
  --border: #d7e2df;
  --accent: #217a65;
  --accent-text: #ffffff;
  --accent-soft: #e0f1ec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1a7f4b;
  --bar: #2c967d;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(28 95 79 / 6%), 0 1px 3px rgb(28 95 79 / 10%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-hero: linear-gradient(160deg, #0b2620 0%, #123d33 55%, #1c5f4f 100%);
    --bg: #0d1513;
    --surface: #15201d;
    --surface-2: #1c2a26;
    --text: #e6efec;
    --muted: #9db0aa;
    --border: #26352f;
    --accent: #5cc9ab;
    --accent-text: #06201a;
    --accent-soft: #173a31;
    --danger: #ff8a80;
    --danger-soft: #3a1b1a;
    --ok: #5fd39a;
    --bar: #4fb999;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-hero: linear-gradient(160deg, #0b2620 0%, #123d33 55%, #1c5f4f 100%);
  --bg: #0d1513;
  --surface: #15201d;
  --surface-2: #1c2a26;
  --text: #e6efec;
  --muted: #9db0aa;
  --border: #26352f;
  --accent: #5cc9ab;
  --accent-text: #06201a;
  --accent-soft: #173a31;
  --danger: #ff8a80;
  --danger-soft: #3a1b1a;
  --ok: #5fd39a;
  --bar: #4fb999;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
.shell { max-width: 640px; margin: 0 auto; padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
/* Green app bar, full width, content centred to the same 640px column as the page. */
header.appbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand-hero); color: var(--on-brand);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  box-shadow: 0 1px 0 rgb(0 0 0 / 8%);
}
header.appbar .inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 40px; }
header.appbar h1 { font-size: 19px; font-weight: 650; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header.appbar .back { color: inherit; }
.back { border: 0; background: none; color: inherit; padding: 8px; margin-left: -8px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.back:hover { background: rgb(127 127 127 / 14%); }
.back svg { width: 22px; height: 22px; }
.shell { padding-top: 4px; }

/* Logo slot: an uploaded /brand/ logo when present, otherwise the CLT monogram. */
.brandmark { display: inline-flex; align-items: center; gap: 10px; flex: none; color: inherit; text-decoration: none; }
.brandmark img { display: block; height: 30px; width: auto; max-width: 140px; object-fit: contain; }
.monogram {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: rgb(255 255 255 / 16%); border: 1px solid rgb(255 255 255 / 30%);
  color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .06em;
}
.brandmark .wordmark { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brandmark .wordmark small { display: block; font-weight: 500; font-size: 12px; opacity: .8; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs .inner { display: flex; width: 100%; max-width: 640px; }
nav.tabs .tab {
  flex: 1; min-width: 0; border: 0; background: none; padding: 6px 2px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); cursor: pointer; text-decoration: none; white-space: nowrap;
}
nav.tabs .tab svg { width: 22px; height: 22px; }
nav.tabs .tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
nav.tabs .tab[aria-current="page"] svg { background: var(--accent-soft); border-radius: 999px; padding: 2px 14px; width: 52px; box-sizing: border-box; height: 26px; }

/* ---------- Building blocks ---------- */
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; display: flex; align-items: center; justify-content: space-between; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; width: 100%; text-align: left; background: none; border: 0; cursor: pointer; }
.row:disabled { cursor: default; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row .chev { color: var(--muted); flex: none; width: 18px; height: 18px; }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 15px; text-transform: uppercase; }
.meter { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--bar); border-radius: 4px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-right: 4px; }
.pill.warn { background: var(--danger-soft); color: var(--danger); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 12px; padding: 11px 16px; min-height: 44px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.link { background: none; color: var(--accent); padding: 6px 8px; min-height: 0; font-weight: 600; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions > .btn { flex: 1 1 140px; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.input, select.input {
  width: 100%; padding: 12px 14px; min-height: 46px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.input-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group .input { flex: 1; min-width: 6em; border: 0; box-shadow: none; border-radius: 0; min-width: 0; }
.input-group .suffix { padding: 0 12px; display: flex; align-items: center; background: var(--surface-2); color: var(--muted); font-size: 14px; white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.error { color: var(--danger); font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 48px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.checklist { max-height: 42dvh; overflow: auto; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.secret { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }
.secret code { flex: 1; overflow-wrap: anywhere; }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.callout { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.callout.warn { background: var(--danger-soft); color: var(--danger); }
ol.steps { padding-left: 20px; margin: 8px 0 0; }
ol.steps li + li { margin-top: 6px; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--brand-hero); color: var(--on-brand);
}
.login .hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login .hero .brandmark img { height: 56px; max-width: 240px; }
.login .hero .monogram { width: 64px; height: 64px; border-radius: 18px; font-size: 20px; }
.login .hero h1 { margin: 0; font-size: 22px; font-weight: 700; }
.login .hero p { margin: 0; opacity: .85; font-size: 15px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; color: var(--text); }
.login footer { font-size: 13px; opacity: .75; }

/* ---------- Sheet (dialog) ---------- */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92dvh;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
dialog#sheet::backdrop { background: rgb(0 0 0 / 45%); }
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 20px; } }
.sheet-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); overflow: auto; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 0 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-head h2 { font-size: 18px; margin: 0; flex: 1; }
.grabber { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 32px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } #toast { transition: none; } }
