:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #17212b;
  --muted: #5d6b78;
  --line: #dde3e9;
  --accent: #0b5a30;
  --accent-2: #e07b1f;
  --accent-soft: #e4f1e8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1e7b4a;
  --ok-soft: #e6f4ec;
  --warn: #a15c07;
  --warn-soft: #fdf1df;
  --info: #1d5fa8;
  --info-soft: #e5eefa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --tabbar-h: 64px;
  --on-accent: #ffffff;
  --cat-1: #2f7d4f; --cat-2: #e07b1f; --cat-3: #3c6fb6; --cat-4: #b8892a; --cat-5: #8a5bb5; --cat-6: #3f9c92; --cat-7: #c4485a; --cat-8: #6b7a89; --cat-9: #a3adb6;
  color-scheme: light;
}
/* Dark theme: follows the device setting ("Automatic"), or forced with data-theme="dark" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #1f2a32;
    --text: #e8edf1;
    --muted: #97a6b3;
    --line: #2b3741;
    --accent: #6cc58f;
    --accent-2: #f0a35a;
    --accent-soft: #183526;
    --danger: #f2877d;
    --danger-soft: #3a1d1b;
    --ok: #6ccf98;
    --ok-soft: #173326;
    --warn: #f0b45c;
    --warn-soft: #3a2a12;
    --info: #8cb8ee;
    --info-soft: #1a2a40;
    --shadow: none;
    color-scheme: dark;
    --on-accent: #0b1a1f;
    --cat-1: #5cbf85; --cat-2: #f0a35a; --cat-3: #7ea6e6; --cat-4: #d8b25a; --cat-5: #b993dd; --cat-6: #6cc7bd; --cat-7: #e8838f; --cat-8: #9aa7b3; --cat-9: #c5ccd2;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418;
  --surface: #182027;
  --surface-2: #1f2a32;
  --text: #e8edf1;
  --muted: #97a6b3;
  --line: #2b3741;
  --accent: #6cc58f;
  --accent-2: #f0a35a;
  --accent-soft: #183526;
  --danger: #f2877d;
  --danger-soft: #3a1d1b;
  --ok: #6ccf98;
  --ok-soft: #173326;
  --warn: #f0b45c;
  --warn-soft: #3a2a12;
  --info: #8cb8ee;
  --info-soft: #1a2a40;
  --shadow: none;
  color-scheme: dark;
  --on-accent: #0b1a1f;
  --cat-1: #5cbf85; --cat-2: #f0a35a; --cat-3: #7ea6e6; --cat-4: #d8b25a; --cat-5: #b993dd; --cat-6: #6cc7bd; --cat-7: #e8838f; --cat-8: #9aa7b3; --cat-9: #c5ccd2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Kannada", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
svg { fill: currentColor; }

/* ---------- top bar & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand img { width: 32px; height: 32px; border-radius: 7px; flex-shrink: 0; }
.brand { min-width: 0; }
.brand-text { display: block; line-height: 1.25; min-width: 0; white-space: nowrap; }
.brand-org { font-weight: 700; color: var(--accent); }
.brand-sep { color: var(--muted); font-weight: 400; padding: 0 6px; }
.brand-app { font-weight: 550; color: var(--text); }
@media (max-width: 420px) {
  .brand-text { white-space: normal; }
  .brand-org, .brand-app { display: block; }
  .brand-sep { display: none; }
  .brand-org { font-size: .95rem; }
  .brand-app { font-size: .8rem; color: var(--muted); }
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  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(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 550;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent); }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabs {
    position: static; display: flex; height: auto; padding: 0; border: 0; gap: 4px; background: none;
  }
  .tabs a { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 9px; font-size: .92rem; }
  .tabs a svg { width: 18px; height: 18px; }
  .tabs a.active { background: var(--accent-soft); }
}

.container { max-width: 980px; margin: 0 auto; padding: 16px; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 550; margin-bottom: 6px; }
.subtle { color: var(--muted); font-size: .9rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 0 8px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row.stretch .btn { flex: 1 1 160px; }

/* ---------- cards & lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card > h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); color: var(--text);
}
.row:last-child { border-bottom: 0; }
a.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; line-height: 1.3; }
.row .meta { color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex-shrink: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.chev { color: var(--muted); flex-shrink: 0; }

.thumb {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex-shrink: 0;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
}
.thumb svg { width: 24px; height: 24px; }

.pill { display: inline-block; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; margin-top: 3px; }
.pill.s-in-use { background: var(--ok-soft); color: var(--ok); }
.pill.s-in-storage { background: var(--info-soft); color: var(--info); }
.pill.s-under-repair { background: var(--warn-soft); color: var(--warn); }
.pill.s-disposed { background: var(--danger-soft); color: var(--danger); }

.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 9px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .92rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .6; margin-bottom: 8px; }
.empty h2 { color: var(--text); }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.search {
  flex: 1 1 240px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search input { border: 0; background: transparent; outline: none; padding: 11px 0; width: 100%; font: inherit; color: var(--text); }
select, input, textarea { font: inherit; color: var(--text); }
.toolbar select { flex: 1 1 180px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); }
.input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
.input:focus, select:focus, textarea:focus, .search:focus-within { outline: 2px solid var(--accent-2); outline-offset: -1px; border-color: transparent; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
@media (min-width: 760px) { .form-actions { bottom: 0; } }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 12px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo button {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
}
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- QR ---------- */
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 132px; height: 132px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 8px; }

/* ---------- scanner ---------- */
.scanner {
  position: relative; width: 100%; max-width: 520px; margin: 0 auto 14px; aspect-ratio: 3 / 4;
  background: #000; border-radius: 16px; overflow: hidden;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame {
  position: absolute; inset: 18% 14%; border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35); border: 3px solid rgba(255,255,255,.9);
}
.scanner .msg {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: .9rem; white-space: nowrap;
}

/* ---------- reports ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat .value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
table.sum { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.sum th, table.sum td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.sum th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.sum td.num, table.sum th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.sum tr.total td { font-weight: 700; border-bottom: 0; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login img { width: 120px; height: 120px; border-radius: 20px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; margin-bottom: 18px; }

/* ---------- toast & dialog ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 550; font-size: .92rem; transition: .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 760px) { .toast { bottom: 24px; } }

dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100% - 24px)); max-height: 86vh;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 18, 24, .5); }
dialog .d-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
dialog .d-head h2 { margin: 0; }
dialog .d-body { padding: 16px; overflow: auto; max-height: calc(86vh - 130px); }
dialog .d-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
dialog.photo-view { width: min(900px, calc(100% - 24px)); background: #000; }
dialog.photo-view img { display: block; width: 100%; max-height: 80vh; object-fit: contain; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }

.thumb.doc { width: 40px; height: 40px; border-radius: 8px; color: var(--accent); }
.thumb.doc svg { width: 22px; height: 22px; }
.btn.ghost.danger { color: var(--danger); }
.row > a.grow { min-width: 0; }

/* users list rows as buttons */
.row-btn { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font: inherit; cursor: pointer; color: var(--text); }
.row-btn:last-child { border-bottom: 0; }
.row-btn:hover { background: var(--surface-2); }
.row-btn .meta { white-space: normal; }

/* activity log */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.activity li:first-child { padding-top: 0; }
.activity li:last-child { border-bottom: 0; padding-bottom: 0; }
.act-head { overflow-wrap: anywhere; }
.act-details { font-size: .88rem; color: var(--text); margin-top: 2px; overflow-wrap: anywhere; }
.act-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
details summary { padding: 4px 0; }

/* signed-in user + sign out in the top bar */
.brand { flex-shrink: 0; }
.theme-btn { margin-left: auto; flex-shrink: 0; }
.userbox { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.userbox .btn { white-space: nowrap; }
.user-name { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
@media (max-width: 1180px) { .user-name { display: none; } }
@media (max-width: 760px) {
  .brand { flex-shrink: 1; min-width: 0; }
  .userbox .btn span { display: none; }
  .userbox .btn { padding: 0 10px; }
}

/* ---------- Assets: location dashboard ---------- */
.page-head .seg { margin-left: auto; }
.page-head h1 { flex: 0 1 auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 8px 14px; font: inherit; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; min-height: 40px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.seg button:focus-visible, .loc:focus-visible, .link:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .95rem; margin: 2px 0 14px; }
.crumbs .sep { color: var(--muted); }
.link { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--accent); cursor: pointer; }
.loc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 14px; }
.loc-grid.cats { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.loc {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px; text-align: left; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); font: inherit; color: var(--text); cursor: pointer;
}
.loc:hover { border-color: var(--accent); }
.loc.small { padding: 10px 12px; gap: 2px; }
.loc.muted { opacity: .65; }
.lname { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; font-weight: 650; overflow-wrap: anywhere; }
.lcount { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }
.loc.small .lcount { font-size: 1.25rem; }
.lsub { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.catbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); margin-top: 4px; }
.catleg { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .74rem; color: var(--muted); }
.catleg i, .dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.dash-h { font-size: 1rem; margin: 6px 0 10px; }
@media (max-width: 520px) {
  .lcount { font-size: 1.35rem; }
  .loc-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .loc-grid.cats { grid-template-columns: 1fr 1fr; }
  .loc { padding: 12px; }
  .page-head .btn.primary { order: 3; width: 100%; }
}

/* ---------- theme switch ---------- */
.theme-btn { padding: 0 10px; }
.theme-btn .moon { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { display: none; }
  :root:not([data-theme="light"]) .theme-btn .moon { display: inline; }
}
