:root {
  --bg: #0b0f14; --panel: #121923; --panel2: #172131; --line: #243246;
  --text: #e6edf5; --muted: #8b9bb0; --accent: #22d3ee; --accent-d: #0e7490;
  --ok: #34d399; --warn: #fbbf24; --err: #f87171; --busy: #60a5fa; --off: #64748b;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); display: flex; height: 100vh; overflow: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); }
.hidden { display: none !important; }

.sidebar { width: 232px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 22px; }
.brand small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.logo { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; font-weight: 700;
  color: #04222a; background: linear-gradient(135deg, var(--accent), #38bdf8); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { padding: 9px 12px; border-radius: 6px; color: var(--muted); border-left: 2px solid transparent; }
nav a:hover { background: var(--panel2); color: var(--text); }
nav a.active { background: var(--panel2); color: var(--text); border-left-color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px #34d39922; }
.dot.off { background: var(--off); box-shadow: none; }
.link { color: var(--muted); } .link:hover { color: var(--accent); }

main { flex: 1; min-width: 0; padding: 0 28px 40px; height: 100vh; overflow-y: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 20px 0; position: sticky; top: 0;
  background: linear-gradient(var(--bg) 80%, transparent); z-index: 5; }
.topbar h1 { font-size: 22px; } .actions { display: flex; gap: 10px; align-items: center; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 7px 13px;
  border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: var(--accent-d); }
.btn.primary { background: var(--accent); color: #04222a; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; } .btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--err); } .btn.danger:hover { border-color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 30px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .bar { height: 3px; border-radius: 3px; margin-top: 10px; background: var(--c, var(--accent)); opacity: .8; }
.two { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .sidebar { display: none; } main { padding: 0 14px; } }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase;
  letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #1b2636; vertical-align: middle; }
tbody tr:hover { background: #151e2b; } tr.click { cursor: pointer; }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.s-online { --c: var(--ok); } .s-busy { --c: var(--busy); } .s-error { --c: var(--err); } .s-offline { --c: var(--off); }
.s-active { --c: var(--accent); } .s-ended { --c: var(--off); }

.robots-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.robot-card { cursor: pointer; border-left: 3px solid var(--c); transition: transform .1s; }
.robot-card:hover { transform: translateY(-2px); }
.robot-card .id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.robot-card .name { font-size: 16px; font-weight: 600; margin: 2px 0 8px; }

.feed { max-height: 420px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.feed-item { display: grid; grid-template-columns: 70px 1fr; gap: 8px; padding: 8px 10px; border-radius: 6px; background: var(--panel2);
  border-left: 2px solid var(--accent); font-size: 13px; }
.feed-item .t { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.feed-item code { font-family: var(--mono); color: var(--accent); }

input, select, textarea { font: inherit; width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: var(--mono); min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; } .toolbar select, .toolbar input { max-width: 220px; }

.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 30; }
.modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(440px, 92vw); }
.modal h3 { margin-bottom: 4px; } .modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(520px, 100vw); background: var(--panel);
  border-left: 1px solid var(--line); z-index: 20; padding: 22px; overflow: auto; box-shadow: -20px 0 40px #0008; }
.drawer .head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 12px 0 18px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 16px; display: flex; flex-direction: column; gap: 12px; }
.tl { position: relative; } .tl::before { content: ""; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
.tl pre { margin: 4px 0 0; font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 6px; max-width: 360px; }
.toast.err { border-left-color: var(--err); }

/* ---- Project tracker additions ---- */
.tablewrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.late { color: var(--err); }
.s-open { --c: var(--busy); } .s-in-progress { --c: var(--warn); } .s-completed { --c: var(--ok); } .s-dropped { --c: var(--off); }
.pbar { display: inline-block; vertical-align: middle; width: 90px; height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-right: 8px; }
.pbar span { display: block; height: 100%; background: var(--accent); }
.modal .box.wide { width: min(680px, 94vw); max-height: 92vh; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--text); font-size: 14px; cursor: pointer; }
.check input { width: auto; }
.req::after { content: " *"; color: var(--err); }
.donut-wrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.donut { width: 160px; height: 160px; flex: none; }
.donut text { fill: var(--text); text-anchor: middle; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend b { margin-left: auto; padding-left: 18px; font-variant-numeric: tabular-nums; }
.plant-row { display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: center; margin-bottom: 14px; }
.plant-row .tag { font-weight: 700; color: var(--accent); }
.hbar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-bottom: 4px; }
.hbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-d), var(--accent)); }
.vbars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; overflow-x: auto; }
.vbar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 38px; height: 100%; font-size: 12px; }
.vbar span { width: 100%; max-width: 34px; background: linear-gradient(var(--accent), var(--accent-d)); border-radius: 4px 4px 0 0; min-height: 3px; }
.vbar em { font-style: normal; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.vbar b { font-weight: 600; margin-bottom: 3px; }
.upd { padding: 9px 11px; border-radius: 6px; background: var(--panel2); margin-bottom: 8px; border-left: 2px solid var(--accent); font-size: 13px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input { max-width: 260px; } .filters select { width: auto; min-width: 130px; }
.spacer { flex: 1; }
.note { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; color: var(--muted); margin-bottom: 14px; }

.idrow { display: grid; grid-template-columns: 28px 1fr; gap: 8px; margin-bottom: 6px; align-items: center; }
.idlist { max-height: 300px; overflow: auto; margin-top: 12px; padding-right: 4px; }

.dfilters { align-items: center; } .dfilters .inl { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
.dfilters .inl input { width: auto; max-width: none; } .dfilters .spacer { min-width: 150px; }
.cardhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; } .cardhead h2 { margin: 0; text-transform: capitalize; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; background: transparent; color: var(--muted); border: 0; padding: 4px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #04222a; font-weight: 600; }

/* Projects table scrolls inside its own frame; headings stay visible */
.tablewrap.tall { max-height: calc(100vh - 235px); min-height: 260px; overflow: auto; }
.tablewrap.tall th { position: sticky; top: 0; z-index: 2; background: var(--panel); }
/* ---- Accounts ---- */
.usercard { width: 100%; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; }
.usercard .uname { font-weight: 600; word-break: break-word; }
.row-btns { display: flex; gap: 6px; }
.filters .inl { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; color: var(--text); font-size: 14px; }
.filters .inl input[type="checkbox"] { width: auto; }
.modal .box .hidden { display: none; }
