/* TISMO NFC demo – colors only through variables, light/dark by system setting. */
:root {
  --primary: #1E5AA8;
  --primary-fg: #ffffff;
  --bg: #f4f3f1;
  --fg: #141619;
  --card: #ffffff;
  --muted: #5e646e;
  --border: #e6e4e0;
  --success: oklch(0.52 0.14 150);
  --success-fg: #ffffff;
  --success-soft: oklch(0.52 0.14 150 / 0.12);
  --danger: oklch(0.577 0.245 27.325);
  --danger-soft: oklch(0.577 0.245 27.325 / 0.1);
  --warn: oklch(0.62 0.15 70);
  --warn-soft: oklch(0.75 0.15 80 / 0.18);
  --primary-soft: rgb(30 90 168 / 0.1);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 14px;
  --touch: 48px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --fg: #f1f3f6;
    --card: #1a1e28;
    --muted: #9ca3af;
    --border: #262b38;
    --primary: #4c86d6;
    --success: oklch(0.78 0.15 150);
    --success-fg: #0e1015;
    --success-soft: oklch(0.78 0.15 150 / 0.14);
    --danger: oklch(0.7 0.19 27);
    --danger-soft: oklch(0.7 0.19 27 / 0.14);
    --warn: oklch(0.8 0.14 80);
    --warn-soft: oklch(0.8 0.14 80 / 0.14);
    --primary-soft: rgb(76 134 214 / 0.16);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.2rem 0 0.6rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85em; word-break: break-all; }

/* --- top bar ----------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px max(16px, env(safe-area-inset-left));
  min-height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); min-height: var(--touch); }
.brand img { display: block; height: 25px; width: auto; }
.brand-tag {
  font-size: 0.75rem; font-weight: 600; color: var(--primary);
  background: var(--primary-soft); padding: 2px 8px; border-radius: 999px;
}
.topnav a {
  display: inline-grid; place-items: center;
  min-width: var(--touch); min-height: var(--touch);
  font-size: 1.5rem; text-decoration: none; color: var(--muted); border-radius: 12px;
}
.topnav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }

/* --- page -------------------------------------------------------------- */
.page {
  max-width: 760px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-left)) 120px;
}
.page.wide { max-width: 1100px; }

.back { display: inline-flex; align-items: center; min-height: var(--touch); text-decoration: none; font-weight: 500; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.grid-2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }

/* --- home tiles ---------------------------------------------------------- */
.tiles { display: grid; gap: 14px; margin-top: 8px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 140px; padding: 20px;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.1s, border-color 0.15s;
}
.tile:hover { border-color: var(--primary); }
.tile:active { transform: scale(0.98); }
.tile-icon { font-size: 2.2rem; line-height: 1; }
.tile-title { font-size: 1.3rem; font-weight: 700; }
.tile-sub { color: var(--muted); font-size: 0.95rem; }

/* --- buttons & inputs ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 18px;
  font: inherit; font-weight: 600;
  color: var(--fg); background: var(--card);
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, transform 0.08s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.success { background: var(--success); border-color: var(--success); color: var(--success-fg); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
.btn.icon { padding: 0; width: var(--touch); }
.btn.big { width: 100%; min-height: 60px; font-size: 1.1rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="url"], select, textarea {
  width: 100%; min-height: var(--touch); padding: 10px 12px;
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 140px; font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.inline-form { display: flex; gap: 8px; }
.inline-form > :first-child { flex: 1; min-width: 0; }

/* --- rows ------------------------------------------------------------------ */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 0;
  border-top: 1px solid var(--border);
}
.list > .row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { color: var(--muted); font-size: 0.9rem; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row a.row-link { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 12px; flex: 1; min-height: var(--touch); }
.order {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 700;
  background: var(--primary-soft); color: var(--primary);
}
.point-row { flex-wrap: wrap; }
.point-edit { flex: 1 1 200px; min-width: 0; }
.point-row .row-actions { align-items: center; margin-left: auto; }

/* --- chips ----------------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.chip.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* --- notices --------------------------------------------------------------- */
.notice {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px;
  background: var(--primary-soft); color: var(--fg); font-size: 0.95rem;
}
.notice.warn { background: var(--warn-soft); }
.notice.err { background: var(--danger-soft); }

/* --- scan bar -------------------------------------------------------------- */
.scan-bar {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px 16px; margin-bottom: 16px;
  border-radius: 14px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary);
}
.pulse {
  flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--primary);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgb(30 90 168 / 0.55); }
  100% { box-shadow: 0 0 0 16px rgb(30 90 168 / 0); }
}

.sim {
  border: 1px dashed var(--border); border-radius: 12px; padding: 12px; margin-bottom: 16px;
}
.sim-title { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }

/* --- driver ---------------------------------------------------------------- */
.counter { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.counter-label { font-size: 1.15rem; font-weight: 600; }
.counter-num { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.counter-num.done { color: var(--success); }
.progress { height: 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.35s ease; }
.progress.done > div { background: var(--success); }

.check {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.3rem; font-weight: 800;
  border: 2px solid var(--border); color: transparent;
}
.check.on { background: var(--success); border-color: var(--success); color: var(--success-fg); }
.check.none { border-style: dashed; color: var(--muted); font-size: 1rem; }
.row.scanned .row-title { color: var(--success); }
.row.notag { opacity: 0.7; }
.row.flash { animation: flash 1.2s ease-out; }
.row.flash .check { animation: pop 0.45s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { 0% { transform: scale(0.3); } 100% { transform: scale(1); } }
@keyframes flash { 0% { background: var(--success-soft); } 100% { background: transparent; } }

.footer-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px max(16px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border);
}
.footer-bar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; }
.footer-bar .btn { min-height: 56px; }
.footer-bar .grow { flex: 1; }

/* --- assign ---------------------------------------------------------------- */
.target { text-align: center; padding: 24px 16px; }
.target-label { font-size: 1rem; color: var(--muted); }
.target-name { font-size: 1.6rem; font-weight: 800; margin: 4px 0; }
.big-ok { font-size: 3.5rem; line-height: 1; color: var(--success); animation: pop 0.45s cubic-bezier(.2,1.6,.4,1); }

/* --- QR -------------------------------------------------------------------- */
.qr { width: min(280px, 70vw); margin: 8px auto; background: #fff; border-radius: 12px; padding: 4px; }
.qr svg { display: block; width: 100%; height: auto; }

/* --- modal ----------------------------------------------------------------- */
.modal {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 20px; border: 1px solid var(--border); border-radius: 18px;
  background: var(--card); color: var(--fg);
}
.modal::backdrop { background: rgb(0 0 0 / 0.5); }
.modal h2 { margin-bottom: 8px; }
.modal .btn-row { margin-top: 16px; justify-content: flex-end; }
.modal .btn-row .btn { flex: 1; }

/* --- toast ----------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 20;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  padding: 14px 18px; border-radius: 14px;
  font-weight: 600; font-size: 1.05rem;
  background: var(--fg); color: var(--bg);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
  animation: toast-in 0.2s ease-out;
}
.toast.ok { background: var(--success); color: var(--success-fg); }
.toast.warn { background: var(--warn); color: #141619; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

details > summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
