/* Light is the default. Dark is html[data-theme="dark"]. The sidebar and the
   remote-session viewer are always dark. */
:root {
  --bg: #f4f5f9; --panel: #ffffff; --panel2: #f0f2f8; --line: #dfe3ee;
  --text: #151b30; --muted: #5d6685; --accent: #c98e08; --accent2: #a87505; --on-accent: #1a1400;
  --crit: #cf2445; --high: #c85a12; --med: #96700a; --low: #177a5e; --info: #55607f; --ok: #137a52;
  --shadow: 0 1px 2px rgba(21,27,48,.06), 0 4px 14px rgba(21,27,48,.05);
  --side: #0b1020; --side-text: #c9cfe6; --side-muted: #7f88ab; --side-line: #1d2748;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html[data-theme="dark"], .term {
  --bg: #0b1020; --panel: #121933; --panel2: #18213f; --line: #253056;
  --text: #e6e9f5; --muted: #8b93b3; --accent: #d4a017; --accent2: #b88a0e; --on-accent: #0b1020;
  --crit: #ff4d6d; --high: #ff8a3d; --med: #f5c542; --low: #4fc3a1; --info: #7f8bb3; --ok: #3ccf91;
  --shadow: none;
}
html[data-theme="dark"] { --side: #070b17; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.45; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; }
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 650; }
button.primary:hover { background: var(--accent2); border-color: var(--accent2); }
button.danger { background: transparent; border-color: var(--crit); color: var(--crit); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.big { padding: 14px 22px; font-size: 16.5px; border-radius: 10px; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.err { color: var(--crit); min-height: 1.2em; }
a { color: var(--accent2); }

.brand { font-weight: 700; display: flex; align-items: center; gap: 10px; color: #d4a017; letter-spacing: 2.5px; text-transform: uppercase; }
.brand.big { font-size: 22px; margin-bottom: 8px; }
.logo { width: 30px; height: 30px; }
.brand.big .logo { width: 44px; height: 44px; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
.login-card button { padding: 11px; font-size: 15.5px; }

/* ---- shell: sidebar + page ---- */
#app { display: flex; min-height: 100vh; }
.side { width: 224px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 20px 14px 14px; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: 0 8px 18px; font-size: 16px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.navhead { color: var(--side-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; padding: 14px 10px 6px; }
nav button { background: transparent; border: 0; border-left: 3px solid transparent; border-radius: 6px; color: var(--side-text); text-align: left; padding: 9px 10px; font-size: 14.5px; }
nav button:hover { background: rgba(255,255,255,.06); }
nav button.active { background: rgba(212,160,23,.14); border-left-color: #d4a017; color: #fff; font-weight: 600; }
.sidefoot { border-top: 1px solid var(--side-line); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--side-muted); word-break: break-all; }
.sidefoot button { color: var(--side-text); text-align: left; padding: 6px 0; }
.page { flex: 1; min-width: 0; }
header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 28px 6px; }
header h1 { margin: 0; font-size: 24px; letter-spacing: -.2px; }
.who { display: flex; align-items: center; gap: 8px; }
#tenantSel { max-width: 240px; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 12px 28px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
.stat.alert { border-color: var(--crit); }
.stat.alert .n { color: var(--crit); }

main { padding: 18px 28px 48px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 120px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; }
.card h4 { margin: 14px 0 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
.tokenrow { display: flex; gap: 8px; align-items: center; }
.tokenrow code { background: var(--panel2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; flex: 1; overflow-x: auto; }

table.grid { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding: 11px 14px; background: var(--panel2); border-bottom: 1px solid var(--line); }
.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr.click { cursor: pointer; }
.grid tbody tr.click:hover { background: var(--panel2); }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.trunc { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px !important; }
.host { font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.sev-critical { background: color-mix(in srgb, var(--crit) 14%, transparent); color: var(--crit); }
.sev-high { background: color-mix(in srgb, var(--high) 14%, transparent); color: var(--high); }
.sev-medium { background: color-mix(in srgb, var(--med) 16%, transparent); color: var(--med); }
.sev-low { background: color-mix(in srgb, var(--low) 14%, transparent); color: var(--low); }
.sev-informational { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); }
.st-online { color: var(--ok); font-weight: 600; }
.st-offline { color: var(--muted); }
.st-isolated { color: var(--crit); font-weight: 700; }
.st-on { color: var(--ok); font-weight: 600; }
.tag { display: inline-block; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; margin: 1px 3px 1px 0; font-size: 11.5px; color: var(--muted); }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(660px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(10,14,30,.22); z-index: 10; display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 18px; }
#dBody { padding: 18px 22px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin: 10px 0 16px; }
.kv .k { color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 16px; }
.section-title { color: var(--muted); text-transform: uppercase; font-size: 11.5px; letter-spacing: .6px; margin-top: 18px; }

/* The connect block at the top of an endpoint: the main thing people come here to do. */
.connect { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 6px; }
.connect button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 16px 18px; border-radius: 12px; text-align: left; }
.connect button b { font-size: 18px; }
.connect button span { font-size: 12.5px; font-weight: 400; opacity: .85; }
.connect button.wide { grid-column: 1 / -1; }
.connect-note { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.rowconnect { padding: 6px 16px; font-size: 14px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #151b30; color: #fff; padding: 11px 20px; border-radius: 10px; z-index: 40; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.tenantcol { display: none; }
body.alltenants .tenantcol { display: table-cell; }
.pill { display: inline-block; border: 1px solid var(--accent); color: var(--accent2); border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 6px; text-transform: uppercase; letter-spacing: .4px; }
.rowactions { display: flex; gap: 6px; justify-content: flex-end; }
.rowactions button { padding: 3px 10px; font-size: 12.5px; }
.notice { border: 1px solid var(--accent); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }

.reasonform { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 16px; }
.reasonform textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 76px; resize: vertical; font-size: 15px; }
.reasonform textarea:focus { outline: none; border-color: var(--accent); }
.reasonform .actions button.primary { flex: 1; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkline input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---- remote session viewer (always dark) ---- */
.term { position: fixed; inset: 0; z-index: 30; background: #05070f; color: var(--text); display: flex; flex-direction: column; }
.term button { background: var(--panel2); }
.term button.danger { background: transparent; }
.term-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.term-actions { display: flex; align-items: center; gap: 10px; }
.term-box { flex: 1; min-height: 0; padding: 8px; }
.screen-box { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; position: relative; }
.screen-box canvas { max-width: 100%; max-height: 100%; background: #000; box-shadow: 0 0 0 1px var(--line); }
.screen-box canvas.control { cursor: default; outline: none; }
.screen-box canvas.control:focus { box-shadow: 0 0 0 2px var(--accent); }
.term-tools { display: flex; align-items: center; gap: 8px; }
.term-tools select { background: var(--bg); color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

/* ---- reports ---- */
.report h2 { margin: 0 0 2px; font-size: 20px; }
.report .sub { color: var(--muted); margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.repgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.bars { display: grid; grid-template-columns: minmax(90px, max-content) 1fr max-content; gap: 8px 12px; align-items: center; }
.bars .bar { height: 10px; border-radius: 5px; background: var(--accent); min-width: 2px; }
.bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.bars .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.flag { color: var(--high); font-weight: 600; }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  .side { width: auto; height: auto; position: static; padding: 12px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .navhead { display: none; }
  .connect { grid-template-columns: 1fr; }
}
@media print {
  .side, header, .stats, .noprint, .drawer, .toast { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .card, table.grid, .stat { box-shadow: none; break-inside: avoid; }
}
.rowactions button.rowconnect { padding: 9px 24px; font-size: 15px; border-radius: 9px; }

/* ---- lists: filters, selection, flags ---- */
.grid th.chk, .grid td.chk { width: 36px; padding-right: 0; }
.chk input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.bulk { background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; }
.small { font-size: 12.5px; }
.flag.small { font-weight: 500; }
.settingrow { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.settingrow label { min-width: 300px; }
.setupkey { font-size: 15px; letter-spacing: 1px; }
.reasonform input { width: 100%; }
.screen-box.actual { display: block; overflow: auto; }
.screen-box.actual canvas { max-width: none; max-height: none; display: block; margin: 0 auto; }
