:root {
  /* Triad brand palette */
  --triad-teal: #18a599;
  --triad-blue: #0e7abb;
  --triad-orange: #f78d29;
  --triad-purple: #643591;

  /* Always-dark theme */
  --bg: #131117;
  --surface: #1d1a22;
  --surface-2: #27232e;
  --border: #37323f;
  --text: #eeebf2;
  --muted: #a8a2b3;

  --primary: var(--triad-purple);        /* navbar, primary buttons (filled, white text) */
  --primary-hover: #7843ad;
  --primary-soft: #2c2138;
  --on-primary: #ffffff;
  --link: var(--triad-teal);             /* links and tags */
  --link-soft: #13302e;
  --select: var(--triad-orange);         /* selected / active state */
  --on-select: #1a1208;
  --info: var(--triad-blue);             /* focus rings, hover outlines */

  --danger: #f2877e;
  --danger-soft: #3d2220;
  --warn: var(--triad-orange);
  --warn-soft: #3a2812;
  --ok: var(--triad-teal);
  --ok-soft: #13302e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  --tabbar-h: 0px;
  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.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--link); }
img { max-width: 100%; display: block; }
/* Default icon size; more specific rules below override it. */
svg[aria-hidden] { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
  background: var(--primary); color: var(--on-primary);
}
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.nav a {
  color: inherit; text-decoration: none; padding: .4rem .7rem; border-radius: var(--radius-sm); opacity: .85; font-size: .95rem;
}
.nav a:hover { opacity: 1; background: rgb(255 255 255 / .12); }
.nav a.active { opacity: 1; background: rgb(0 0 0 / .22); box-shadow: inset 0 -3px 0 var(--select); }

.view { max-width: 1200px; margin: 0 auto; padding: 1rem; outline: none; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

.tabbar { display: none; }
@media (max-width: 720px) {
  :root { --tabbar-h: 60px; }
  .nav { display: none; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: .72rem;
  }
  .tabbar a.active { color: var(--select); font-weight: 600; }
  .tabbar svg { width: 22px; height: 22px; }
  .view { padding: .75rem; }
}

.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; flex: 1 1 auto; }
.page-head > p { flex: 1 1 260px; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: .25rem; text-decoration: none; margin-bottom: .5rem; font-size: .95rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card + .card, .stack > * + * { margin-top: 1rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: .45rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 32px; padding: .25rem .6rem; font-size: .875rem; }
.btn svg { width: 18px; height: 18px; flex: none; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; margin-top: .25rem; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email], select, textarea {
  width: 100%; min-height: 42px; padding: .5rem .65rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--info); outline-offset: 1px;
}
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--select); }
.form-error { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }

/* ---------- Chips / badges ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 999px; font-size: .82rem;
  background: var(--link-soft); color: var(--link); border: 1px solid transparent;
  text-decoration: none; white-space: nowrap;
}
button.chip { cursor: pointer; font: inherit; font-size: .82rem; }
.chip.toggle { background: var(--surface); color: var(--text); border-color: var(--border); min-height: 34px; padding: .3rem .75rem; }
.chip.toggle[aria-pressed=true] { background: var(--select); color: var(--on-select); border-color: var(--select); font-weight: 600; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.out { background: var(--warn-soft); color: var(--warn); }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.role { background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.badge.note { background: var(--surface-2); color: var(--muted); }
.badge.pending { background: #10263a; color: #5fb3e6; }

/* ---------- Inventory list ---------- */
.toolbar { display: grid; gap: .6rem; margin-bottom: 1rem; }
.toolbar .search { position: relative; }
.toolbar .search input { padding-left: 2.3rem; min-height: 46px; font-size: 1rem; }
.toolbar .search svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); width: 20px; color: var(--muted); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .5rem; }
.filters select { min-height: 38px; font-size: .92rem; }
.result-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: .25rem 0 .75rem; color: var(--muted); font-size: .9rem; }

.group-head { margin: 1.25rem 0 .5rem; font-size: .95rem; color: var(--muted); font-weight: 600; display: flex; gap: .5rem; align-items: baseline; }
.group-head:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
@media (max-width: 480px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; } }
.item-card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.item-card:hover { border-color: var(--info); }
.item-card .thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.item-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-card .thumb svg { width: 36px; height: 36px; opacity: .5; }
.item-card .body { padding: .55rem .7rem .7rem; display: grid; gap: .15rem; }
.item-card .name { font-weight: 600; line-height: 1.25; }
.item-card .meta { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-card .foot { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; margin-top: .2rem; font-size: .8rem; }

.table-list { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.table-list th, .table-list td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-list th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table-list tr:last-child td { border-bottom: none; }
.table-list td.thumbcell { width: 56px; padding: .35rem; }
.table-list td.thumbcell img, .table-list td.thumbcell .ph { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.table-list tr.clickable { cursor: pointer; }
.table-list tr.clickable:hover td { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .4; margin: 0 auto .5rem; }

/* ---------- Item detail ---------- */
.gallery .main { aspect-ratio: 4 / 3; background: var(--surface-2); border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; cursor: zoom-in; }
.gallery .main img { width: 100%; height: 100%; object-fit: contain; }
.gallery .strip { display: flex; gap: .4rem; margin-top: .5rem; overflow-x: auto; padding-bottom: .25rem; }
.gallery .strip button { flex: none; width: 64px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.gallery .strip button[aria-current=true] { border-color: var(--select); }
.gallery .strip img { width: 100%; height: 100%; object-fit: cover; }
.no-photo { aspect-ratio: 4 / 3; border-radius: var(--radius); background: var(--surface-2); display: grid; place-items: center; color: var(--muted); text-align: center; padding: 1rem; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .9rem; }
dl.facts dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.crumbs { display: inline-flex; flex-wrap: wrap; gap: .2rem; align-items: center; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--muted); }

.availability { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: space-between; }
.checkout-row { display: flex; justify-content: space-between; gap: .75rem; align-items: center; padding: .6rem 0; border-top: 1px solid var(--border); }
.checkout-row:first-child { border-top: none; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .55rem 0; border-top: 1px solid var(--border); font-size: .9rem; }
.timeline li:first-child { border-top: none; }
.timeline .when { color: var(--muted); font-size: .8rem; }
.timeline .changes { margin: .3rem 0 0; padding-left: 1rem; color: var(--muted); font-size: .85rem; }
.timeline .changes b { color: var(--text); font-weight: 600; }

/* ---------- Photo editor ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.photo-tile { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: .25rem; background: linear-gradient(transparent, rgb(0 0 0 / .6)); }
.photo-tile .tools button { background: rgb(255 255 255 / .92); color: #222; border: 0; border-radius: 6px; width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; }
.photo-tile .tools svg { width: 16px; height: 16px; }
.photo-tile .primary-tag { position: absolute; top: .3rem; left: .3rem; background: var(--primary); color: var(--on-primary); font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; font-weight: 600; }
.photo-tile.uploading { display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.photo-tile.add { display: grid; place-items: center; cursor: pointer; border-style: dashed; color: var(--muted); text-align: center; font-size: .82rem; gap: .2rem; padding: .5rem; }
.photo-tile.add:hover { border-color: var(--link); color: var(--link); }
.photo-tile.add svg { width: 26px; height: 26px; }
.photo-tile.pick { cursor: pointer; padding: 0; }
.photo-tile.pick[aria-pressed=true] { outline: 3px solid var(--select); outline-offset: -3px; }
.photo-tile .unused { position: absolute; top: .3rem; right: .3rem; background: var(--warn-soft); color: var(--warn); font-size: .68rem; padding: .05rem .35rem; border-radius: 4px; font-weight: 600; }

.prod-picker { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Location tree ---------- */
.tree { list-style: none; margin: 0; padding: 0; }
.tree .tree { padding-left: 1.25rem; border-left: 1px dashed var(--border); margin-left: .6rem; }
.tree-row { display: flex; align-items: center; gap: .5rem; padding: .4rem .25rem; border-radius: 6px; }
.tree-row:hover { background: var(--surface-2); }
.tree-row .name { font-weight: 600; text-decoration: none; }
.tree-row .kind { font-size: .78rem; color: var(--muted); }
.tree-row .count { margin-left: auto; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.tree-row .btns { display: flex; gap: .15rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .55rem .85rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--select); border-bottom-color: var(--select); font-weight: 600; }

.list-rows { display: grid; }
.list-row { display: flex; align-items: center; gap: .75rem; padding: .65rem .25rem; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: none; }
.list-row .grow { flex: 1 1 auto; min-width: 0; }

/* ---------- Dialog ---------- */
dialog {
  border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 2rem); background: var(--surface); color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / .3);
}
dialog.wide { width: min(920px, calc(100vw - 1.5rem)); }
dialog::backdrop { background: rgb(0 0 0 / .65); }
dialog form, dialog .dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
dialog header { padding: 1rem 1.1rem .5rem; display: flex; align-items: center; gap: .5rem; }
dialog header h2 { margin: 0; flex: 1; }
dialog .dlg-body { padding: .5rem 1.1rem 1rem; overflow-y: auto; }
dialog footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1.1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
dialog footer .left { margin-right: auto; }
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  dialog form, dialog .dlg { max-height: 100dvh; height: 100%; }
  dialog .dlg-body { flex: 1; }
}

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .92); display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox button { position: absolute; top: .75rem; right: .75rem; }

/* ---------- Offline / sync status ---------- */
.netbar { font-size: .88rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.netbar[data-tone="offline"] { background: #232a33; }
.netbar[data-tone="warn"] { background: var(--warn-soft); }
.netbar-inner { max-width: 1200px; margin: 0 auto; padding: .45rem 1rem; display: flex; flex-wrap: wrap; gap: .35rem .9rem; align-items: center; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }
.tip { background: var(--primary-soft); border-radius: var(--radius-sm); padding: .7rem .85rem; margin-top: .75rem; font-size: .9rem; }
.tip p { margin: .3rem 0 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 1rem + env(safe-area-inset-bottom)); z-index: 60; display: grid; gap: .5rem; width: min(420px, calc(100vw - 2rem)); }
.toast { background: #2e2936; color: var(--text); border-left: 4px solid var(--link); padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); font-size: .92rem; animation: toast-in .2s ease-out; }
.toast.error { background: #5a1f1b; border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Login ---------- */
.login-wrap { min-height: 80dvh; display: grid; place-items: center; }
.login { width: min(380px, 100%); }
.login .logo { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 1.5rem; }
.login .logo img { width: min(200px, 60vw); height: auto; margin-bottom: .75rem; }
.login .logo h1 { font-size: 1.35rem; margin: 0; }
.google-btn { display: flex; justify-content: center; min-height: 44px; }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1.1rem 0; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
