/* GeoAssetTracker: mobile first, light and dark. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --brand: #1e3a5f;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --radius: 8px;
  --gutter: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #1a2028;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2d3540;
    --accent: #60a5fa;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; padding-bottom: 64px; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875rem; }
pre.code { overflow: auto; max-height: 300px; background: var(--bg); padding: 8px; border-radius: var(--radius); }
.muted { color: var(--muted); }
small { display: block; color: var(--muted); font-size: 0.8rem; }

/* layout */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px var(--gutter); background: var(--brand); color: #fff; }
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.nav { display: none; gap: 4px; flex: 1; }
.nav a, .nav summary { padding: 6px 10px; border-radius: 6px; }
.nav a[aria-current="page"], .nav a:hover, .nav summary[aria-current="page"], .nav summary:hover, .nav-menu[open] > summary { background: rgba(255, 255, 255, 0.15); }
.nav-menu { position: relative; }
.nav-menu > summary { list-style: none; cursor: pointer; margin: 0; display: flex; align-items: center; gap: 4px; }
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu > summary::after { content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); }
.nav-menu-items { position: absolute; top: calc(100% + 6px); left: 0; z-index: 1100; min-width: 200px; display: flex; flex-direction: column; padding: 6px; background: var(--brand); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.nav-menu-items a { white-space: nowrap; }
.me { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.me .link { color: #cbd5e1; }
.role { font-size: 0.75rem; padding: 1px 6px; border-radius: 99px; background: rgba(127, 127, 127, 0.2); }
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 1000; padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav a { flex: 1; text-align: center; padding: 14px 4px; text-decoration: none; color: var(--text); font-size: 0.9rem; }
@media (min-width: 900px) {
  .nav { display: flex; }
  .bottom-nav { display: none; }
  body { padding-bottom: 0; }
}
main.page { max-width: 1200px; margin: 0 auto; padding: var(--gutter); }
main.narrow { max-width: 560px; margin: 0 auto; padding: var(--gutter); }
main.full { padding: 0; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.grid { display: grid; gap: var(--gutter); }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--gutter); margin-bottom: var(--gutter); min-width: 0; }
.login h1 { justify-content: center; }
.language-switch { justify-content: center; margin-top: var(--gutter); }
.language-switch select { width: auto; }
.factor { margin-top: var(--gutter); }
.factor + .factor { border-top: 1px solid var(--border); padding-top: var(--gutter); }
.qr { display: inline-block; background: #fff; padding: 8px; border-radius: var(--radius); }
.qr svg { display: block; width: 180px; height: 180px; }
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(9em, 1fr)); gap: 6px 16px; padding: 0; list-style: none; }
.codes code { font-size: 1.05rem; letter-spacing: 0.04em; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.row > label { margin: 0; }
.filters .export { margin-left: auto; align-items: center; color: var(--muted); }
.inline { display: inline; }
.table-wrap { overflow-x: auto; }

/* forms */
label { display: block; margin-bottom: 12px; font-weight: 500; }
label.check, label.chip-check { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; }
input, select, textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; width: 100%; margin-top: 4px; }
input[type="checkbox"], input[type="color"] { width: auto; margin: 0; }
input[type="color"] { padding: 2px; height: 38px; width: 48px; }
.row input, .row select { width: auto; }
.command-preset { margin: 16px 0; }
.command-preset h3 { margin: 0 0 2px; font-size: 1rem; }
#command-log code { overflow-wrap: break-word; }
/* phones: one block per command instead of squeezed columns */
@media (max-width: 640px) {
  #command-log thead { display: none; }
  #command-log table, #command-log tbody, #command-log tr, #command-log td { display: block; }
  #command-log tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  #command-log td { padding: 2px 0; border: 0; }
  #command-log td:empty { display: none; }
}
textarea.code { min-height: 160px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
fieldset.bulk, fieldset.tag-filter { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; }
legend { font-weight: 500; padding: 0 4px; }
.button { display: inline-block; font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.danger { color: var(--danger); border-color: var(--danger); }
.button.small { padding: 4px 10px; font-size: 0.875rem; }
.button:disabled, button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
button.link.danger { color: var(--danger); }
input.token { font-family: ui-monospace, monospace; }
.setting input { max-width: 200px; }

/* messages */
.notice { padding: 10px 14px; border-radius: var(--radius); background: rgba(37, 99, 235, 0.1); }
.notice.ok { background: rgba(22, 163, 74, 0.12); }
.notice.error { background: rgba(220, 38, 38, 0.12); color: var(--danger); }
.banner { padding: 8px var(--gutter); background: #fef3c7; color: #78350f; text-align: center; }
.banner.info { background: #dbeafe; color: #1e3a8a; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
table.audit code { word-break: break-all; }

/* chips and statuses */
.chip { display: inline-block; font-size: 0.8rem; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--chip, #64748b); color: var(--text); background: color-mix(in srgb, var(--chip, #64748b) 18%, transparent); }
.chip-check input { position: absolute; opacity: 0; }
.chip-check input:checked + .chip { background: var(--chip); color: #fff; }
.chip-check input:focus-visible + .chip { outline: 2px solid var(--accent); }
.group-badge { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.status { font-size: 0.8rem; padding: 1px 8px; border-radius: 99px; background: rgba(127, 127, 127, 0.15); white-space: nowrap; }
.status.moving, .status.active { background: rgba(22, 163, 74, 0.15); color: var(--ok); }
.status.stopped { background: rgba(37, 99, 235, 0.15); color: var(--accent); }
.status.offline, .status.retired { background: rgba(148, 163, 184, 0.25); color: var(--muted); }
.status.inactive { background: rgba(180, 83, 9, 0.15); color: var(--warn); }
.warn { color: var(--danger); }

/* maps */
.map-layout { display: flex; flex-direction: column-reverse; height: calc(100vh - 52px - 64px); }
.map-panel { background: var(--surface); padding: var(--gutter); overflow: auto; max-height: 40vh; border-top: 1px solid var(--border); }
.map { flex: 1; min-height: 300px; }
@media (min-width: 900px) {
  .map-layout { flex-direction: row; height: calc(100vh - 52px); }
  .map-panel { width: 340px; max-height: none; border-top: 0; border-right: 1px solid var(--border); }
}
.mini-map { height: 240px; border-radius: var(--radius); margin-bottom: 8px; }
.filters label { margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.asset-list { list-style: none; padding: 0; margin: 0; }
.asset-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.asset-list li.low-battery button { color: var(--danger); }
.asset-list .seen { margin-left: auto; display: inline; }
.playback { display: flex; align-items: center; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.playback input[type="range"] { flex: 1; padding: 0; }
.stops { padding-left: 20px; }
.leaflet-container { font: inherit; }

/* trees and lists */
.tree { list-style: none; padding: 0; }
.tree li { padding: 6px 0 6px calc(var(--depth) * 24px); border-bottom: 1px solid var(--border); }
.tree li small { display: inline; margin-left: 8px; }
.plain { padding-left: 18px; }
dl.attributes { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0; }
dl.attributes dt { color: var(--muted); }
dl.attributes dd { margin: 0; }

/* offline */
body.is-offline .topbar { background: #475569; }

/* events */
.severity { font-size: 0.75rem; padding: 1px 8px; border-radius: 99px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; }
.severity.info { background: rgba(37, 99, 235, 0.12); color: var(--accent); }
.severity.warning { background: rgba(180, 83, 9, 0.15); color: var(--warn); }
.severity.critical { background: rgba(220, 38, 38, 0.15); color: var(--danger); font-weight: 600; }
.event-filters label { margin-bottom: 0; }
small.inline { display: inline; }

/* geofences */
.fence-layout { display: grid; gap: var(--gutter); }
@media (min-width: 900px) { .fence-layout { grid-template-columns: 2fr 1fr; } }
.fence-layout .card { margin-bottom: 0; }
.fence-map { height: 60vh; min-height: 320px; border-radius: var(--radius); }
.fence-tools { margin-bottom: 8px; }
.fence-tools .radius { margin: 0; }
.fence-tools .radius input { width: 7em; }
.fence-handle { background: #fff; border: 2px solid var(--brand); border-radius: 50%; cursor: move; }
.fence-handle.edge { border-color: var(--accent); }
.fence-handle.mid { opacity: 0.6; transform: scale(0.7); }
.fence-list { list-style: none; padding: 0; margin: 0; }
.fence-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.fence-list small { margin-left: 18px; }
fieldset.selector .grid { margin-top: 8px; }
fieldset.selector select[multiple] { min-height: 6em; }

/* notifications */
.bell { position: relative; display: inline-flex; color: #fff; }
.bell .badge { position: absolute; top: -6px; right: -10px; min-width: 18px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center; }
.toasts { position: fixed; right: 16px; bottom: 80px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface); color: var(--text); border-left: 4px solid var(--accent); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); text-decoration: none; }
.toast.warning { border-left-color: var(--warn); }
.toast.critical { border-left-color: var(--danger); }
.toast span { font-size: 0.875rem; color: var(--muted); }
.tabs { display: flex; gap: 16px; border-bottom: 1px solid var(--border); margin-bottom: var(--gutter); }
.tabs a { padding: 6px 0; text-decoration: none; color: var(--muted); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom: 2px solid var(--accent); }
.message-preview { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; white-space: pre-wrap; }
.message-preview p { margin: 8px 0 0; }
.status.delivery-sent { background: rgba(22, 163, 74, 0.15); color: var(--ok); }
.status.delivery-failed { background: rgba(220, 38, 38, 0.15); color: var(--danger); }
.status.delivery-retrying { background: rgba(180, 83, 9, 0.15); color: var(--warn); }
.inbox { list-style: none; padding: 0; }
.inbox li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.inbox li.unread a, .inbox li.unread strong { font-weight: 700; }
.inbox li p { margin: 4px 0 0; }
.contacts li { padding: 8px 0; border-bottom: 1px solid var(--border); }
details > summary { cursor: pointer; margin: 8px 0; }
summary.link { cursor: pointer; }
