/* LOGMASTER backoffice — dependency-free design system.
   Themes: daylight (default light) · commanddeck (dark control-room) · slate (soft dark).
   Selected via <html data-theme="..."> (server-rendered from session, runtime-switchable).
   Density via <html data-density="comfortable|compact">.
   Every theme must keep body text at WCAG AA contrast — no pure black/white surfaces. */

/* ---------- tokens ---------- */
:root, :root[data-theme="daylight"] {
  color-scheme: light;
  --bg: #f2f4f7; --panel: #ffffff; --panel-2: #f7f9fc;
  --ink: #1f2933; --muted: #64707e; --line: #e2e8f0;
  --brand: #1565c0; --brand-d: #0d47a1; --brand-ink: #ffffff;
  --accent: #0e7c86;
  --ok: #1b873f; --warn: #b26a00; --err: #c62828;
  --ok-bg: #e6f4ea; --warn-bg: #fdf0e3; --err-bg: #fdeaea;
  --chip: #eef2f7;
  --side-bg: #0e2a47; --side-ink: #cfe0f3; --side-head: #6f9bcb; --side-active: var(--brand);
  --focus: #bcd4f5;
  --shadow: 0 12px 40px rgba(15, 23, 42, .22);
  --overlay: rgba(15, 23, 42, .45);
  --toast-bg: #1f2933; --toast-ink: #f4f6f8;
}
:root[data-theme="commanddeck"] {
  color-scheme: dark;
  --bg: #0b1017; --panel: #121a26; --panel-2: #182230;
  --ink: #e4ecf5; --muted: #93a1b3; --line: #24344a;
  --brand: #f5a623; --brand-d: #ffbd4d; --brand-ink: #16202e;
  --accent: #38d5c8;
  --ok: #43c073; --warn: #f0a63a; --err: #ef6461;
  --ok-bg: rgba(67, 192, 115, .14); --warn-bg: rgba(240, 166, 58, .15); --err-bg: rgba(239, 100, 97, .15);
  --chip: #1d2735;
  --side-bg: #070c13; --side-ink: #aebdd0; --side-head: #5b7995; --side-active: #1c2c40;
  --focus: #3d5174;
  --shadow: 0 14px 44px rgba(0, 0, 0, .55);
  --overlay: rgba(2, 6, 12, .62);
  --toast-bg: #182230; --toast-ink: #e4ecf5;
}
:root[data-theme="slate"] {
  color-scheme: dark;
  --bg: #1c2027; --panel: #252b35; --panel-2: #2b323e;
  --ink: #d7dde6; --muted: #98a1ae; --line: #353e4c;
  --brand: #6ea8e8; --brand-d: #8cbcf2; --brand-ink: #14202e;
  --accent: #6fd0c6;
  --ok: #57b87e; --warn: #d9a04f; --err: #dd7674;
  --ok-bg: rgba(87, 184, 126, .13); --warn-bg: rgba(217, 160, 79, .14); --err-bg: rgba(221, 118, 116, .14);
  --chip: #2e3542;
  --side-bg: #171b21; --side-ink: #aab4c2; --side-head: #6c7889; --side-active: #2a3546;
  --focus: #445571;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --overlay: rgba(8, 10, 14, .55);
  --toast-bg: #2b323e; --toast-ink: #d7dde6;
}

:root {
  --font-display: 'Archivo', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --radius: 10px;
  --pad-panel: 18px; --pad-cell: 9px 10px; --fs-body: 14px;
}
:root[data-density="compact"] {
  --pad-panel: 12px; --pad-cell: 5px 8px; --fs-body: 13px;
}

* { box-sizing: border-box; }
body { margin: 0; font: var(--fs-body)/1.45 var(--font-body);
  background: var(--bg); color: var(--ink);
  transition: background-color .25s ease, color .25s ease; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono, td.code { font-family: var(--font-mono); font-size: .93em; }

/* ---------- app layout: left sidebar + main ---------- */
.app { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar { width: 212px; flex: none; background: var(--side-bg); color: var(--side-ink); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; transition: background-color .25s ease; }
.side-brand { font-family: var(--font-display); font-weight: 800; letter-spacing: 1.5px; color: #fff; font-size: 17px; padding: 16px 18px 14px; display: block; }
:root[data-theme="commanddeck"] .side-brand { color: var(--brand); }
.side-brand:hover { text-decoration: none; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px;
  color: var(--side-ink); font-size: 14px; margin: 1px 0; transition: background-color .15s ease; }
.side-nav a:hover { background: rgba(255,255,255,.09); text-decoration: none; }
.side-nav a.active { background: var(--side-active); color: #fff; }
:root[data-theme="commanddeck"] .side-nav a.active { color: var(--brand); box-shadow: inset 2px 0 0 var(--brand); }
.side-group { margin-top: 12px; }
.side-group .ghead { display: flex; align-items: center; gap: 9px; padding: 6px 10px 3px;
  color: var(--side-head); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; font-weight: 700; }
.side-group .ghead .ic { width: 14px; height: 14px; }
.side-group .sub a { padding-left: 22px; }
.side-badge { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.side-badge.alert { background: var(--err); }
.side-foot { border-top: 1px solid rgba(255,255,255,.12); padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; }
.side-foot a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--side-ink); border-radius: 7px; font-size: 13px; }
.side-foot a:hover { background: rgba(255,255,255,.09); text-decoration: none; }
.side-foot a.active { background: var(--side-active); color: #fff; }
.side-version { color: var(--side-head); font-size: 11px; padding: 6px 10px 2px; font-family: var(--font-mono); }
.side-kbd { margin-left: auto; font-size: 10px; opacity: .55; font-family: var(--font-mono); border: 1px solid currentColor;
  border-radius: 4px; padding: 0 4px; }
.main { flex: 1; min-width: 0; }
@media (max-width: 760px) { .app { flex-direction: column; } .sidebar { width: 100%; height: auto; position: static; }
  .side-nav { display: flex; flex-wrap: wrap; } .side-group { margin: 0; } }

/* ---------- icons (inline SVG sprite via #ic-*) ---------- */
.ic { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
button .ic, .btn .ic { width: 15px; height: 15px; margin-right: 6px; vertical-align: -3px; }
h1 .ic, h2 .ic { width: 19px; height: 19px; vertical-align: -3px; margin-right: 8px; color: var(--brand); }

/* cross-entity link */
a.elink { display: inline-flex; align-items: center; gap: 4px; }
a.elink .ic { width: 13px; height: 13px; opacity: .6; }

/* breadcrumb */
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin: -4px 0 16px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.crumbs a:hover { color: var(--brand); text-decoration: none; }
.crumbs .ic { width: 13px; height: 13px; }
.crumbs .sep { opacity: .5; }

.wrap { max-width: 1180px; margin: 22px auto; padding: 0 18px; }
h1 { font-family: var(--font-display); font-size: 20px; margin: 0 0 16px; letter-spacing: .2px; }
h2 { font-family: var(--font-display); font-size: 16px; margin: 0 0 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--pad-panel); margin-bottom: 18px; transition: background-color .25s ease, border-color .25s ease; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* ---------- KPI tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  transition: transform .12s ease, box-shadow .12s ease, background-color .25s ease; }
.tile:hover { transform: translateY(-1px); }
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.tile .v { font-family: var(--font-display); font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .trend { margin-top: 8px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--pad-cell); border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover, tr.clickable:hover { background: var(--panel-2); cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.alert-cell { background: var(--err); color: #fff; font-weight: 700; border-radius: 4px; }

/* ---------- chips / status ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--chip);
  font-size: 12px; font-weight: 600; color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); }
.chip.sem-na { background: var(--chip); color: var(--muted); cursor: pointer; animation: sem-pulse 1.8s ease-out infinite; }
@keyframes sem-pulse { 0% { box-shadow: 0 0 0 0 rgba(220, 80, 80, .55); } 70% { box-shadow: 0 0 0 7px rgba(220, 80, 80, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 80, 80, 0); } }

/* ---------- buttons + forms ---------- */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--brand); background: var(--brand);
  color: var(--brand-ink); padding: 8px 14px; border-radius: 7px; font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease, transform .06s ease; }
button:hover, .btn:hover { background: var(--brand-d); border-color: var(--brand-d); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button.ghost, .btn.ghost { background: transparent; color: var(--brand); }
button.ghost:hover { background: var(--panel-2); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
button.sm { padding: 5px 10px; font-size: 13px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--brand); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; }
.login-card .brand { text-align: center; font-family: var(--font-display); font-size: 24px; font-weight: 800; color: var(--brand);
  letter-spacing: 2px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; font-size: 13px; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: 440px; max-width: 92vw;
  max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal h2 { margin-bottom: 4px; }
.modal.wide { width: 720px; }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.err-msg { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 8px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.feed { max-height: 360px; overflow: auto; }
.feed .ev { padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.feed .ev .t { font-weight: 600; }
.feed .ev .m { color: var(--muted); }
#toast { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
#toast .t { background: var(--toast-bg); color: var(--toast-ink); padding: 10px 14px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); opacity: .97; border: 1px solid var(--line); }
#toast .t.err { background: var(--err); color: #fff; }

/* ---------- timeline ---------- */
.tl { position: relative; padding-left: 6px; }
.tl-item { display: flex; gap: 12px; position: relative; padding-bottom: 14px; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 26px; bottom: -2px;
  width: 2px; background: var(--line); }
.tl-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; flex: none; color: var(--brand); }
.tl-dot .ic { width: 13px; height: 13px; }
.tl-title { font-size: 13px; }
.tl-when { color: var(--muted); font-size: 11px; font-family: var(--font-mono); margin-top: 1px; }

/* ---------- power grid ---------- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--brand); }
.sort-ind { color: var(--brand); font-size: 10px; }
.grid-filters th { padding: 4px 6px; }
.grid-filters input { padding: 4px 8px; font-size: 12px; }
.grid-foot { display: flex; align-items: center; gap: 8px; padding: 10px 2px 0; font-size: 13px; }
.grid-foot .spacer { flex: 1; }
.grid-sel { width: 30px; }
.grid-sel input { width: auto; cursor: pointer; }
.grid-bulk { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 60;
  background: var(--panel); border: 1px solid var(--brand); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px; }

/* ---------- settings: theme picker + sound rows ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.theme-card { border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; cursor: pointer; text-align: center;
  transition: border-color .15s ease, transform .12s ease; }
.theme-card:hover { transform: translateY(-1px); }
.theme-card.selected { border-color: var(--brand); }
.theme-card .swatch { height: 44px; border-radius: 6px; margin-bottom: 8px; display: flex; overflow: hidden; }
.theme-card .swatch span { flex: 1; }
.theme-card .tname { font-weight: 600; font-size: 13px; }
.sound-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sound-row:last-child { border-bottom: none; }
.sound-row .sname { flex: 1; }
.sound-row input[type=range] { width: 140px; }
.sound-row input[type=checkbox] { width: auto; }

/* ---------- segmented view toggle ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--panel-2); color: var(--muted); padding: 6px 14px; font-size: 13px;
  cursor: pointer; border-radius: 0; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* ---------- kanban board (orders) ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.kcol { flex: 0 0 240px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.kcol.kover { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.khead { padding: 10px 12px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel-2); border-radius: var(--radius) var(--radius) 0 0; }
.kcount { float: right; background: var(--line); color: var(--muted); border-radius: 10px; padding: 0 8px; font-size: 12px; }
.kbody { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 40px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease; }
.kcard:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.kcard.kdrag { opacity: .5; }
.kc-id { font-weight: 700; }
.kc-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kc-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- photo gallery + lightbox (trip load photos) ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery .ph { position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
  background: var(--panel-2); cursor: pointer; }
.gallery .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .ph .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; font-size: 11px;
  background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.9); display: flex; align-items: center;
  justify-content: center; flex-direction: column; }
.lightbox img { max-width: 94vw; max-height: 82vh; object-fit: contain; border-radius: 6px; } /* letterbox, never crop */
.lightbox .lb-cap { color: #cfd8e3; margin-top: 12px; font-size: 14px; }
.lightbox .lb-x { position: absolute; top: 18px; right: 22px; color: #fff; font-size: 30px; cursor: pointer; line-height: 1; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: 40px; cursor: pointer;
  padding: 0 18px; user-select: none; opacity: .8; }
.lightbox .lb-prev { left: 6px; } .lightbox .lb-next { right: 6px; }

/* ---------- notification bell + inbox ---------- */
.bell { position: fixed; top: 14px; right: 18px; z-index: 60; width: 40px; height: 40px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--ink); }
.bell:hover { border-color: var(--brand); }
.bell .ic { width: 18px; height: 18px; }
.bell-badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--err); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.bell-panel { position: fixed; top: 60px; right: 18px; z-index: 60; width: min(360px, 92vw); max-height: 70vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.bell-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.bell-head a { font-size: 12px; }
.nrow { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.nrow:hover { background: var(--panel-2); }
.nrow.unread { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.nrow .nic .ic { width: 16px; height: 16px; color: var(--brand); margin-top: 2px; }
.nrow .nt { font-weight: 600; font-size: 13px; }
.nrow .nb { font-size: 12px; margin-top: 2px; }
.nrow .nd { font-size: 11px; margin-top: 3px; }

/* ---------- stock heatmap ---------- */
.heatmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.heat { border: 1px solid var(--line); border-radius: 7px; padding: 8px 6px; text-align: center; font-size: 11px;
  color: var(--ink); }
.heat .hloc { font-weight: 700; font-size: 12px; }
.heat .hval { margin-top: 3px; opacity: .85; }
.heat.empty { opacity: .45; }
