/* Hossa: "modern finance dashboard" theme. Every colour is a token here; map.js reads the
   --map-* ones, the charts in app.js read --accent, --pos, --neg and --muted. */
:root {
  --bg: #090d14;
  --panel: #0d121b;
  --card: #121925;
  --card-hi: #161f2e;
  --line: rgba(148, 163, 184, 0.12);
  --line-strong: rgba(148, 163, 184, 0.22);
  --text: #e7ecf4;
  --muted: #7d8aa0;
  --faint: #4b566a;
  --accent: #7c8cff;
  --accent-2: #38d6c4;
  --accent-soft: rgba(124, 140, 255, 0.14);
  --pos: #34d399;
  --neg: #f87171;
  --warn: #fbbf24;
  --purchase: #60a5fa;
  --sales: #34d399;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
  --num: "Inter", "SF Pro Display", "Segoe UI Variable Display", system-ui, sans-serif;
  /* map */
  --map-bg: #090d14;
  --map-block: #0f1520;
  --map-road: #141b27;
  --map-road-line: #232d3d;
  --map-home: #1b2434;
  --map-home-roof: #26324a;
  --map-office: #1f2b45;
  --map-office-window: #5b6fb0;
  --map-park: #0f2a26;
  --map-tree: #1c5a4c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 75% -10%, rgba(124, 140, 255, 0.07), transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---- header: brand, company, KPI tiles ---- */
#top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(13, 18, 27, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.logo {
  font-weight: 800; font-size: 19px; letter-spacing: -0.3px; margin-right: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.company {
  font-weight: 600; min-width: 120px; padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); margin-right: 6px;
}
.company:empty { display: none; }
.stat {
  display: flex; flex-direction: column; line-height: 1.15; min-width: 150px;
  padding: 7px 14px 7px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
}
.stat > span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; }
.stat b { font-family: var(--num); font-size: 17px; font-weight: 650; letter-spacing: -0.2px; }
.conn { color: var(--warn); font-weight: 600; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(251, 191, 36, 0.1); }
.lang { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; }
.lang select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }

/* ---- layout ---- */
main { flex: 1; display: flex; min-height: 0; }
#mapWrap { flex: 1; position: relative; min-width: 0; }
#map { width: 100%; height: 100%; display: block; cursor: pointer; touch-action: none; }
.tip {
  position: absolute; pointer-events: none; background: rgba(18, 25, 37, 0.94); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 8px 11px; font-size: 12px; max-width: 250px; box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.map-help {
  position: absolute; left: 14px; bottom: 12px; font-size: 11.5px; color: var(--muted); pointer-events: none;
  padding: 5px 10px; border-radius: 999px; background: rgba(13, 18, 27, 0.8); border: 1px solid var(--line);
}
#side { width: 460px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
#tabs {
  display: flex; gap: 2px; margin: 12px 12px 0; padding: 4px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
}
#tabs button {
  flex: 1; background: none; border: 0; padding: 7px 4px; color: var(--muted); cursor: pointer; border-radius: 9px;
  font-size: 13px; font-weight: 550; white-space: nowrap; transition: background 0.15s, color 0.15s;
}
#tabs button:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
#tabs button.active { color: var(--text); background: var(--card-hi); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--line-strong) inset; }
#panel { flex: 1; overflow-y: auto; padding: 12px; }

@media (max-width: 860px) {
  main { flex-direction: column; }
  #mapWrap { flex: none; height: 45vh; }
  #side { width: 100%; flex: 1; min-height: 0; border-left: 0; border-top: 1px solid var(--line); }
  #top { gap: 8px; }
  .stat { min-width: 0; flex: 1; }
}

/* ---- cards and tables ---- */
.card {
  background: linear-gradient(180deg, var(--card-hi), var(--card) 60px); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15.5px; font-weight: 650; letter-spacing: -0.1px; margin: 0 0 10px; }
.card h3 { font-size: 12px; font-weight: 650; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.card h2 .ico, .card h3 .ico { vertical-align: -4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.warn { color: var(--warn); }
.hint ol { margin: 0; padding-left: 20px; }
.hint li { margin-bottom: 5px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row h2 { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 10px 0; }
.grid2 dt { color: var(--muted); }
.grid2 dd { margin: 0; text-align: right; font-family: var(--num); font-weight: 550; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04); }
.online { color: var(--pos); font-size: 10px; }
.tag { font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; }

table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th {
  text-align: left; color: var(--faint); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.7px;
  padding: 6px 6px; border-bottom: 1px solid var(--line);
}
table.list td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; font-family: var(--num); font-weight: 500; white-space: nowrap; }
table.list th.num { font-family: inherit; }
table.list tr.click { cursor: pointer; }
table.list tr.click td { transition: background 0.12s; }
table.list tr.click:hover td { background: rgba(255, 255, 255, 0.025); }
table.list tr.current td { background: var(--accent-soft); }
table.list tr.current td:first-child { box-shadow: 2px 0 0 var(--accent) inset; }
table.list tr.group td {
  color: var(--muted); font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.8px;
  padding-top: 14px; border-bottom: 0;
}
table.list tr.total td { font-weight: 700; border-top: 1px solid var(--line-strong); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 7px 0 7px 14px; border-bottom: 1px solid var(--line); position: relative; }
.feed li::before { content: ""; position: absolute; left: 2px; top: 14px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: 0.7; }
.feed li:last-child { border-bottom: 0; }
.legend-row { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
canvas[data-chart] { width: 100%; height: 170px; display: block; }

/* ---- buttons and fields ---- */
button {
  background: var(--card-hi); border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 13px; cursor: pointer;
  font-weight: 550; transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
button:hover { background: #1c2638; border-color: rgba(148, 163, 184, 0.32); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: wait; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  background: linear-gradient(180deg, #8b99ff, #6a79f5); border-color: transparent; color: #fff; font-weight: 650;
  box-shadow: 0 6px 18px rgba(124, 140, 255, 0.28);
}
button.primary:hover { background: linear-gradient(180deg, #9aa6ff, #7584f7); }
button.danger { background: transparent; border-color: rgba(248, 113, 113, 0.35); color: var(--neg); }
button.danger:hover { background: rgba(248, 113, 113, 0.1); }
button.small { padding: 3px 9px; font-size: 12px; border-radius: 7px; }
.field { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.field > span, .field { color: var(--muted); }
.field select, .field input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 10px; color: var(--text);
}
.field input { font-family: var(--num); }
.field button { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--bg); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices button { display: flex; flex-direction: column; gap: 5px; text-align: left; padding: 12px; border-radius: 12px; background: var(--bg); }
.choices button:hover { border-color: var(--accent); }

/* ---- store unit grid ---- */
.units { position: relative; display: grid; margin: 12px auto; }
.units .links { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.units .links line { stroke: rgba(231, 236, 244, 0.35); stroke-width: 2.5; }
.units .links line.flow { stroke: var(--accent-2); stroke-dasharray: 6 5; animation: flow 0.8s linear infinite; }
.units .links marker path { fill: rgba(231, 236, 244, 0.5); }
@keyframes flow { to { stroke-dashoffset: -11; } }
.unit {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  padding: 8px 9px; border-radius: 12px; text-align: left; overflow: hidden; border-width: 1px; background: var(--bg);
}
.unit.empty {
  align-items: center; justify-content: center; border-style: dashed; border-color: var(--line-strong);
  background: transparent; color: var(--faint); font-size: 22px; font-weight: 300;
}
.unit.empty:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.unit.purchase { background: linear-gradient(160deg, rgba(96, 165, 250, 0.16), var(--bg) 70%); border-color: rgba(96, 165, 250, 0.35); }
.unit.sales { background: linear-gradient(160deg, rgba(52, 211, 153, 0.16), var(--bg) 70%); border-color: rgba(52, 211, 153, 0.35); }
.unit.warn { border-color: rgba(251, 191, 36, 0.7); }
.unit.selected { box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(124, 140, 255, 0.35); }
.unit .kind { font-size: 9.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.unit.purchase .kind { color: var(--purchase); }
.unit.sales .kind { color: var(--sales); }
.unit .prod { font-weight: 650; font-size: 13px; line-height: 1.1; }
.unit .lvl, .unit .flow { font-size: 11px; color: var(--muted); font-family: var(--num); }
.unit .bar { width: 100%; height: 3px; background: rgba(255, 255, 255, 0.06); border-radius: 2px; overflow: hidden; }
.unit .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---- toast and modal ---- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(22, 31, 46, 0.96); border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 18px;
  transition: 0.2s; z-index: 20; box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { border-color: rgba(248, 113, 113, 0.6); color: #fecaca; }
#modal { position: fixed; inset: 0; background: rgba(3, 6, 10, 0.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 30; }
#modal[hidden] { display: none; }
#nameForm { width: min(420px, 92vw); display: flex; flex-direction: column; gap: 12px; padding: 22px; }
#nameForm input { background: var(--bg); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; }

/* ---- icons (client/img/ui, made by tools/make-ui.ts; absent icons are simply left out) ---- */
.ico { width: 20px; height: 20px; vertical-align: -5px; margin-right: 8px; flex: none; }
.ico.tiny { width: 14px; height: 14px; vertical-align: -3px; margin-right: 4px; }
.ico.big { width: 34px; height: 34px; margin: 2px 0; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45)); }
.ico.tab { width: 17px; height: 17px; vertical-align: -4px; margin-right: 6px; }
.ico.kpi {
  width: 34px; height: 34px; padding: 6px; margin-right: 2px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
}
.stat:has(.ico) { display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: center; padding-left: 8px; }
.stat .ico { grid-row: span 2; }
.stat:has(.ico) { min-width: 0; }
table.list td .ico { width: 22px; height: 22px; padding: 2px; border-radius: 6px; background: rgba(255, 255, 255, 0.04); }
/* line icons (client/line-icons.js): drawn in the text colour, accent colour when selected */
.ico.li {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  color: var(--muted); background: none; padding: 0; border-radius: 0;
}
table.list td .ico.li { width: 26px; height: 26px; vertical-align: -8px; background: none; padding: 0; }
table.list tr.group .ico.li { color: var(--text); }
#tabs button.active .ico.li, table.list tr.current .ico.li, button.active .ico.li, .selected .ico.li { color: var(--accent); }
