/* HECTACORN ERP - UI styles. Palette: dataviz reference instance (roles, not raw hex in body). */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --series-1: #2a78d6;
  --seq-250: #86b6ef; --seq-350: #5598e7; --seq-450: #2a78d6;
  --seq-550: #1c5cab; --seq-650: #104281; --seq-700: #0d366b;
  --good: #0ca30c; --good-text: #006300;
  --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --sidebar: #10263c;
  --sidebar-2: #0b1c2e;
  --sidebar-ink: #c6d6e6;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 2px 8px rgba(11, 11, 11, .05);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --seq-250: #184f95; --seq-350: #1c5cab; --seq-450: #256abf;
  --seq-550: #3987e5; --seq-650: #6da7ec; --seq-700: #9ec5f4;
  --good-text: #0ca30c;
  --sidebar: #0e1a26;
  --sidebar-2: #0a141d;
  --sidebar-ink: #b9cee2;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --seq-250: #184f95; --seq-350: #1c5cab; --seq-450: #256abf;
    --seq-550: #3987e5; --seq-650: #6da7ec; --seq-700: #9ec5f4;
    --good-text: #0ca30c;
    --sidebar: #0e1a26;
    --sidebar-2: #0a141d;
    --sidebar-ink: #b9cee2;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 13.5px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--page);
  color: var(--ink);
  display: flex;
  overflow: hidden;              /* app shell: sidebar stays fixed, only #main scrolls */
}

/* thin, subtle scrollbars everywhere */
* { scrollbar-width: thin; scrollbar-color: var(--baseline) transparent; }
*::-webkit-scrollbar { width: 9px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- sidebar ---------- */
#sidebar {
  width: 200px; min-width: 200px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  height: 100%; z-index: 20;
}
#sidebar .logo { padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.10); }
#sidebar .logo b { color: #fff; font-size: 16px; letter-spacing: .08em; }
#sidebar .logo small { display: block; opacity: .65; margin-top: 1px; font-size: 11px; }
#nav { flex: 1; overflow-y: auto; padding: 6px 0 8px; }
#nav .cap {
  padding: 12px 16px 4px; font-size: 10px; font-weight: 700;
  letter-spacing: .14em; opacity: .5; text-transform: uppercase;
}
#nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 16px; color: var(--sidebar-ink);
  text-decoration: none; font-weight: 500; font-size: 13px;
  border-left: 3px solid transparent;
}
#nav a:hover { background: rgba(255,255,255,.06); }
#nav a.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: var(--seq-350); }
#nav a .ico { width: 17px; text-align: center; font-size: 13px; }
#sidebar .foot { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,.10); font-size: 11.5px; }
#sidebar .foot button {
  background: none; border: 1px solid rgba(255,255,255,.22); color: var(--sidebar-ink);
  border-radius: 6px; padding: 3px 9px; cursor: pointer; font-size: 11.5px; margin: 6px 6px 0 0;
}
#userchip { display: flex; align-items: center; gap: 7px; }
#userchip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }

/* ---------- main ---------- */
#main { flex: 1; min-width: 0; padding: 0 26px 40px; overflow-y: auto; height: 100%; }
/* keep content readable on ultrawide monitors */
#main > * { max-width: 1480px; margin-left: auto; margin-right: auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 10;
  background: var(--page); padding: 14px 0 10px;
  border-bottom: 1px solid var(--grid); margin-bottom: 14px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; }
.topbar .sub { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }

button, .btn {
  font: inherit; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--ink);
  padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--series-1); }
button.primary, .btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button.ghost { border: none; background: none; color: var(--series-1); padding: 3px 6px; }
button:disabled { opacity: .45; cursor: default; }

input, select, textarea {
  font: inherit; font-size: 13px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--grid); border-radius: 7px;
  padding: 6px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.filters { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 11px; align-items: center; }
.filters input[type=search] { min-width: 230px; }
.filters .spacer { flex: 1; }
.filters .count { color: var(--muted); font-size: 12px; }

/* ---------- cards & tiles ---------- */
.grid { display: grid; gap: 12px; align-items: start; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); margin-bottom: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 13px; box-shadow: var(--shadow);
}
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: var(--series-1); }
.tile .k { color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: .05em; }
.tile .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.tile .d { color: var(--muted); font-size: 11px; margin-top: 2px; }
.tile.alert .v { color: var(--critical); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 15px; box-shadow: var(--shadow);
  min-width: 0;
}
.card h3 {
  margin: 0 0 8px; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.card h3 .total { color: var(--ink); font-size: 13px; letter-spacing: 0; text-transform: none; }
.two-col { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1150px) {
  .two-col { grid-template-columns: 1fr; }
  .three-col { grid-template-columns: 1fr; }
}

/* action chips strip */
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.chips-cap { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 12px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.chip b { font-size: 12.5px; }
.chip::before { content: "●"; font-size: 8px; }
.chip.crit { color: var(--critical); } .chip.crit::before { color: var(--critical); }
.chip.warn::before { color: var(--warning); }
.chip.plain::before { color: var(--muted); }
.chip:hover { border-color: var(--series-1); }

/* ---------- tables ---------- */
.tablewrap {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.gridscroll { overflow: auto; overscroll-behavior: contain; }
.card .tablewrap { border: none; box-shadow: none; border-radius: 0; max-height: none; }
.card .gridscroll { overflow: visible; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 11px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.wrap { white-space: normal; min-width: 200px; }
th {
  position: sticky; top: 0; z-index: 1;
  background: color-mix(in srgb, var(--ink) 3.5%, var(--surface));
  border-bottom: 2px solid var(--baseline);
  color: var(--ink-2); font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  cursor: pointer; user-select: none;
}
th .sort { margin-left: 5px; font-size: 8.5px; color: var(--baseline); }
th .sort.on { color: var(--series-1); }
th:hover { color: var(--ink); }
tbody tr:nth-child(even) td { background-color: color-mix(in srgb, var(--ink) 2.2%, transparent); }
tbody tr:hover td { background-color: color-mix(in srgb, var(--series-1) 8%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px; color: var(--ink-2); letter-spacing: .02em;
}
tfoot td {
  border-top: 2px solid var(--baseline); border-bottom: none;
  font-weight: 700; font-size: 12px;
  background: color-mix(in srgb, var(--ink) 3.5%, var(--surface));
  position: sticky; bottom: 0;
}
tr.clickable { cursor: pointer; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.pager {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--grid);
}
.pager .pinfo { flex: 1; font-variant-numeric: tabular-nums; }
.pager button { padding: 2px 9px; font-size: 12px; }
.pager .psizes { display: inline-flex; gap: 2px; }
.pager .psizes button { border: none; background: none; color: var(--muted); padding: 2px 7px; }
.pager .psizes button.on {
  color: var(--series-1); font-weight: 700;
  background: color-mix(in srgb, var(--series-1) 12%, transparent); border-radius: 5px;
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1.5px 8px;
  border: 1px solid var(--border); color: var(--ink-2); background: transparent;
}
.badge::before { content: "●"; font-size: 8px; }
.badge.good { color: var(--good-text); } .badge.good::before { color: var(--good); }
.badge.warn { color: var(--ink-2); } .badge.warn::before { color: var(--warning); }
.badge.serious { color: var(--ink-2); } .badge.serious::before { color: var(--serious); }
.badge.crit { color: var(--critical); } .badge.crit::before { color: var(--critical); }
.badge.info { color: var(--ink-2); } .badge.info::before { color: var(--series-1); }
.badge.plain::before { color: var(--muted); }

/* ---------- charts ---------- */
.hbar-row { display: grid; grid-template-columns: 118px 1fr 84px; gap: 9px; align-items: center; margin: 5px 0; }
.hbar-row .lbl { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.hbar-track { height: 14px; border-radius: 3px; position: relative; }
.hbar-fill { height: 100%; border-radius: 0 3px 3px 0; background: var(--series-1); min-width: 2px; transition: width .35s ease; }
.hbar-row .val { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink); }
.hbar-row:hover .hbar-fill { filter: brightness(1.12); }

#tooltip {
  position: fixed; z-index: 99; pointer-events: none; display: none;
  background: var(--ink); color: var(--page);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; max-width: 320px; white-space: pre-line;
}

/* ---------- modal (always centered on screen) ---------- */
#modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 24px 16px;
}
#modal-back.open { display: flex; }
#modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; padding: 18px 20px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  animation: pop .16s ease;
}
@keyframes pop {
  from { transform: scale(.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- dialog (replaces native confirm / prompt / alert) ---------- */
#dlg-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center; z-index: 90; padding: 16px;
}
#dlg-back.open { display: flex; }
#dlg {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  width: 100%; max-width: 400px; padding: 18px 20px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  animation: pop .16s ease;
}
#dlg h2 { margin: 0 0 8px; font-size: 15px; }
#dlg .msg { font-size: 13px; color: var(--ink-2); white-space: pre-line; margin-bottom: 14px; }
#dlg input { width: 100%; margin-bottom: 8px; }
#dlg .userlist button.sel { border-color: var(--series-1); outline: 1px solid var(--series-1); }
#dlg .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#dlg .userlist { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
#dlg .userlist button {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  text-align: left; font-weight: 500; padding: 8px 12px;
}
#dlg .userlist .uid { color: var(--muted); font-size: 11px; font-weight: 600; }
#dlg .divider { border-top: 1px solid var(--grid); margin: 12px 0; position: relative; }
#dlg .divider span {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: var(--surface); padding: 0 10px; font-size: 11px; color: var(--muted);
}
button.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
#modal h2 { margin: 0 0 13px; font-size: 15px; }
#modal .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 13px; }
#modal .fields label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
#modal .fields label.full { grid-column: 1 / -1; }
#modal .fields input, #modal .fields select, #modal .fields textarea { width: 100%; }
#modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#modal .err { color: var(--critical); font-size: 12.5px; margin-top: 10px; display: none; }

/* ---------- custom dropdown (replaces every native select) ---------- */
.dd { position: relative; display: inline-block; }
.dd-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-width: 132px; width: 100%;
  font: inherit; font-size: 13px; font-weight: 500; text-align: left;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--grid); border-radius: 7px;
  padding: 6px 10px; cursor: pointer;
}
.dd-btn:hover { border-color: var(--series-1); }
.dd-btn:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.dd-lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-arrow { color: var(--muted); font-size: 9px; flex: none; }
.dd-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 70;
  min-width: 100%; max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--grid); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .20); padding: 4px;
}
.dd-opt {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
  font-size: 12.5px; white-space: nowrap;
}
.dd-opt:hover { background: color-mix(in srgb, var(--series-1) 10%, transparent); }
.dd-opt.sel { font-weight: 600; }
.dd-check { width: 14px; flex: none; color: var(--series-1); font-weight: 700; }
#modal .dd { width: 100%; }

/* ---------- searchable picker ---------- */
.picker { position: relative; }
.picker-drop {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 70;
  background: var(--surface); border: 1px solid var(--grid); border-radius: 8px;
  max-height: 250px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .20);
}
.picker-opt { padding: 7px 11px; cursor: pointer; border-bottom: 1px solid var(--grid); }
.picker-opt:last-child { border-bottom: none; }
.picker-opt:hover, .picker-opt.hl { background: color-mix(in srgb, var(--series-1) 10%, transparent); }
.picker-opt .plabel { font-size: 12.5px; font-weight: 600; }
.picker-opt .psub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.picker-opt.none { cursor: default; color: var(--muted); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--page); border-radius: 8px; padding: 9px 16px;
  font-size: 13px; display: none; z-index: 60; box-shadow: var(--shadow);
}

/* ---------- detail pane ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 5px 13px; font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
a.link { color: var(--series-1); text-decoration: none; cursor: pointer; }
a.link:hover { text-decoration: underline; }
.section-title {
  font-size: 11px; font-weight: 700; margin: 16px 0 7px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---------- responsive (phone) ---------- */
@media (max-width: 820px) {
  body { flex-direction: column; overflow: auto; height: auto; }
  #sidebar { width: 100%; min-width: 0; height: auto; position: static; }
  #main { overflow: visible; height: auto; }
  #nav { display: flex; overflow-x: auto; padding: 0; }
  #nav .cap { display: none; }
  #nav a { border-left: none; border-bottom: 3px solid transparent; padding: 8px 12px; white-space: nowrap; }
  #nav a.active { border-left: none; border-bottom-color: var(--seq-350); }
  #sidebar .foot { display: flex; align-items: center; gap: 10px; padding: 6px 12px; }
  #main { padding: 0 12px 40px; }
  .kv { grid-template-columns: 110px 1fr; }
}
