@font-face {
  font-family: 'Michroma';
  src: url('../fonts/Michroma-Regular.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'DSEG7';
  src: url('../fonts/DSEG7Modern-Regular.woff2') format('woff2');
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root,
:root[data-theme="dark"] {
  --bg: #18191b;
  --surface: #232428;
  --surface-2: #2b2d32;
  --border: #34363c;
  --text: #f1f2f4;
  --text-2: #a3a6ad;
  --text-3: #73767d;
  --accent: #4a8fe0;
  --accent-strong: #3d7ac7;
  --accent-soft: rgba(74, 143, 224, 0.16);
  --on-accent: #ffffff;
  --success: #3fb67b;
  --success-soft: rgba(63, 182, 123, 0.16);
  --warn: #e0a23a;
  --warn-soft: rgba(224, 162, 58, 0.14);
  --danger: #ef5d5d;
  --danger-soft: rgba(239, 93, 93, 0.14);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde0e5;
  --text: #17181a;
  --text-2: #5a5e66;
  --text-3: #8a8e96;
  --accent: #2f72c4;
  --accent-strong: #2a66b0;
  --accent-soft: rgba(47, 114, 196, 0.12);
  --success: #1f8f57;
  --success-soft: rgba(31, 143, 87, 0.12);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.12);
  --danger: #d64545;
  --danger-soft: rgba(214, 69, 69, 0.1);
  --shadow: 0 8px 28px rgba(20, 30, 50, 0.16);
  --scrim: rgba(20, 22, 26, 0.4);
  color-scheme: light;
}

:root {
  --radius: 20px;
  --radius-sm: 14px;
  --font: Roboto, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-brand: 'Michroma', var(--font);
  --gutter: 16px;
  --bottom-bar: 88px;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.muted { color: var(--text-3); }

.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; }
.clock {
  font-family: 'DSEG7', monospace;
  font-size: 19px; letter-spacing: 1px;
  color: var(--text-2);
  margin-right: 6px;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--accent);
}
.icon-btn:active { background: var(--accent-soft); }
.back-btn {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--accent); font-size: 19px; padding: 8px 8px 8px 0;
}
.back-btn .icon { width: 28px; height: 28px; }

.avatar {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(145deg, #4a8fe0, #2f62a8);
  color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .5px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.08);
}
.avatar.large { width: 64px; height: 64px; font-size: 22px; }
.avatar .icon { width: 24px; height: 24px; }

/* ---------- Page ---------- */
.page {
  padding: 4px var(--gutter) calc(var(--bottom-bar) + env(safe-area-inset-bottom) + 24px);
}
.page-head { margin: 4px 0 16px; }
.page-title {
  margin: 0; font-size: 24px; font-weight: 700; color: var(--accent);
  overflow-wrap: anywhere;
}
.page-sub { margin: 2px 0 10px; color: var(--text-2); }
.section-title {
  font-size: 17px; font-weight: 700; margin: 22px 4px 10px;
}
.version { text-align: center; color: var(--text-3); font-size: 14px; margin: 28px 0 0; }

/* Brand */
.brand {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin: 8px 0 20px;
}
.brand-logo { width: 104px; height: 104px; }
[data-theme="light"] .brand-logo { filter: invert(1) hue-rotate(180deg) saturate(1.2); }
.brand-text { display: flex; flex-direction: column; align-items: center; }
.brand-name { font-family: var(--font-brand); font-size: 30px; letter-spacing: 3px; font-style: italic; }
.brand-sub {
  font-family: var(--font-brand); font-size: 10px; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--text-2); margin-top: 2px;
}

/* ---------- Cards & lists ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
a.card:active, .task-main:active { background: var(--surface-2); }
.card-icon { color: var(--accent); }
.card-icon .icon { width: 28px; height: 28px; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 19px; overflow-wrap: anywhere; }
.card-sub { color: var(--text-2); font-size: 15px; margin-top: 2px; }
.card.location .progress { margin-top: 10px; }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--warn); flex: none; }
.status-dot.done { background: var(--success); }

/* Task rows */
.card.task { padding: 0; gap: 0; align-items: stretch; overflow: hidden; }
.card.task .checkbox { margin: 14px 0 14px 14px; align-self: flex-start; }
.task-main {
  flex: 1; min-width: 0; text-align: left;
  background: none; border: 0; padding: 14px 16px 14px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.task-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.task-inv { font-weight: 700; font-size: 19px; letter-spacing: .3px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.task-sector { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 15px; }
.task-sector .icon { width: 15px; height: 15px; }
.task-comment { display: flex; gap: 6px; color: var(--text-2); font-size: 14px; }
.task-comment .icon { width: 15px; height: 15px; margin-top: 2px; color: var(--accent); }
.task-comment span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.task-meta { color: var(--success); font-size: 13px; }
.card.task.done .task-inv { color: var(--text-2); text-decoration: line-through; text-decoration-color: var(--text-3); }

.checkbox {
  flex: none; width: 32px; height: 32px; border-radius: 10px;
  border: 2px solid var(--text-3); background: transparent;
  display: grid; place-items: center; color: transparent;
  transition: background .15s, border-color .15s;
  position: relative;
}
.checkbox::after { content: ''; position: absolute; inset: -8px; } /* bigger touch target */
.checkbox .icon { width: 20px; height: 20px; }
.checkbox.checked { background: var(--success); border-color: var(--success); color: #fff; }

/* Results */
.card.result { padding: 14px 16px; }

/* Empty */
.empty { text-align: center; padding: 36px 12px; color: var(--text-2); }
.empty-icon { width: 44px; height: 44px; color: var(--text-3); }
.empty-title { font-size: 17px; margin: 12px 0 4px; color: var(--text); }
.empty-hint { margin: 0; }

/* ---------- Search & chips ---------- */
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 0 6px 0 14px; margin: 8px 0 12px;
  color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); }
.search-input:focus-visible { outline: none; }
.search-input {
  flex: 1; min-width: 0; height: 50px; border: 0; background: transparent; outline: none;
  color: var(--text); font-size: 16px;
}
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear { color: var(--text-3); width: 38px; height: 38px; }

.chips { display: flex; gap: 8px; margin: 0 0 14px; overflow-x: auto; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: 15px;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-count { font-size: 13px; opacity: .8; font-variant-numeric: tabular-nums; }
.chip.small { padding: 6px 12px; font-size: 14px; }
.chip.removable { padding-right: 4px; }
.chip.removable button {
  border: 0; background: none; color: var(--text-3); display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
}
.chip.removable .icon { width: 16px; height: 16px; }

/* ---------- Banners ---------- */
.banners:empty { display: none; }
.banner {
  display: flex; align-items: center; gap: 10px;
  border-radius: var(--radius-sm); padding: 8px 8px 8px 14px; margin: 0 0 12px;
  background: var(--accent-soft); color: var(--text);
}
.banner > .icon { color: var(--accent); }
.banner > span:not(.icon) { flex: 1; font-size: 15px; }
.banner.warn { background: var(--warn-soft); }
.banner.warn > .icon { color: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  border: 1px solid transparent; background: transparent;
  font-weight: 600; font-size: 16px; color: var(--accent);
}
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.grow { flex: 1; }
.btn.primary { background: var(--accent-strong); color: var(--on-accent); }
.btn.primary:active { filter: brightness(1.1); }
.btn.outline { border-color: var(--border); background: var(--surface); color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-text { color: var(--danger); padding: 0 14px; }
.btn.text:active, .btn.outline:active { background: var(--accent-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row .btn { flex: 1 1 200px; }
.top-gap { margin-top: 24px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  max-width: 640px; margin: 0 auto;
}
.bottom-bar .btn.primary {
  min-height: 56px; border-radius: 999px; font-size: 18px;
  box-shadow: 0 8px 24px rgba(61, 122, 199, 0.35);
}

/* ---------- Forms ---------- */
.form-card { flex-direction: column; align-items: stretch; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; color: var(--text-2); font-weight: 500; }
.req { color: var(--danger); }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row .input { flex: 1; min-width: 0; }
.field-btn { background: var(--accent-soft); border-radius: 14px; width: 52px; height: 52px; }
.input {
  width: 100%; min-height: 52px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  color: var(--text); font-size: 17px; outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-3); }
.textarea { resize: none; min-height: 96px; line-height: 1.45; }
.field-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.field-error:empty { display: none; }

.note { display: flex; gap: 8px; align-items: flex-start; margin: 0; color: var(--text-2); font-size: 15px; }
.note .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--warn); }
.note.ok .icon { color: var(--success); }
.meta-line { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 15px; color: var(--text-2); }
.meta-line .icon { width: 18px; height: 18px; }
.meta-line.ok { color: var(--success); }
.meta-line.warn { color: var(--warn); }

.profile-head { display: flex; align-items: center; gap: 14px; }

.segmented {
  display: flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 4px; gap: 4px;
}
.segmented button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; border: 0; border-radius: 12px; background: transparent; color: var(--text-2);
  font-weight: 600;
}
.segmented button .icon { width: 18px; height: 18px; }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Dialog ---------- */
dialog { color: var(--text); }
.dialog {
  border: 0; border-radius: 24px; padding: 22px 20px 12px;
  background: var(--surface); width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dialog::backdrop, .sheet::backdrop { background: var(--scrim); }
.dialog-title { margin: 0 0 8px; font-size: 20px; }
.dialog-body { margin: 0 0 8px; color: var(--text-2); overflow-wrap: anywhere; }
.dialog-field { margin: 12px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Bottom sheet ---------- */
.sheet {
  border: 0; padding: 0; margin: 0; background: transparent;
  width: 100%; max-width: 640px; max-height: 100dvh;
  inset: auto 0 0 0; margin: 0 auto;
}
.sheet-panel {
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 8px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform .2s ease-out;
}
.sheet.open .sheet-panel { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-title { margin: 0; font-size: 21px; color: var(--accent); }
.sheet-head .icon-btn { color: var(--text-2); }
.sheet-form { display: flex; flex-direction: column; gap: 14px; }
.field-group { display: flex; flex-direction: column; gap: 14px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; }
.suggestions:empty { display: none; }
.sheet-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

.status-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 6px 6px 10px;
}
.status-pill {
  font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn);
}
.status-pill.done { background: var(--success-soft); color: var(--success); }
.status-meta { flex: 1; font-size: 14px; color: var(--text-2); min-width: 120px; }

/* ---------- Menu ---------- */
.menu {
  position: absolute; z-index: 50; min-width: 220px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu-item {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; background: none; padding: 12px; border-radius: 10px; font-size: 16px;
}
.menu-item .icon { color: var(--accent); width: 20px; height: 20px; }
.menu-item:active, .menu-item:focus-visible { background: var(--accent-soft); outline: none; }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 100;
  bottom: calc(var(--bottom-bar) + env(safe-area-inset-bottom) + 8px);
  transform: translate(-50%, 20px); opacity: 0; transition: .2s;
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow);
  width: max-content; max-width: calc(100vw - 32px); font-size: 15px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-action { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px; }
[data-theme="dark"] .toast-action { color: var(--accent-strong); }

/* ---------- Scanner ---------- */
.scanner { position: fixed; inset: 0; z-index: 200; background: #000; }
.scanner-video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute; left: 50%; top: 50%; width: min(80vw, 420px); height: 34vw; max-height: 200px;
  transform: translate(-50%, -50%); border: 3px solid #4a8fe0; border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
}
.scanner-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 12px 12px; color: #fff;
}
.scanner-title { font-weight: 600; text-align: center; }
.scanner-btn { color: #fff; background: rgba(0, 0, 0, 0.4); }
.scanner-btn.active { background: #4a8fe0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
body:not(:has(.bottom-bar)) .toast { bottom: calc(env(safe-area-inset-bottom) + 20px); }

/* Location status & import */
.card-sub .status-pill, .page-sub .status-pill { margin-right: 8px; font-size: 12px; padding: 2px 8px; vertical-align: 1px; }
.card.location.loc-done .card-icon { color: var(--success); }
.card.location.loc-done .card-title { color: var(--text-2); }
.page-sub .status-pill { display: inline-block; }
.note.plain { display: block; }
.import-area { min-height: 180px; font-size: 15px; }
.import-list {
  list-style: none; margin: 8px 0 0; padding: 0; max-height: 46dvh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.import-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 15px; }
.import-list li + li { border-top: 1px solid var(--border); }
.import-list li > span:not(.icon):not(.status-pill) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.import-list li.exists { color: var(--text-3); }
.import-list .icon { width: 18px; height: 18px; color: var(--accent); }
.import-list .icon.ok { color: var(--success); }
.import-list .status-pill { font-size: 12px; padding: 2px 8px; }
