/* B36 Profile Fleet Dashboard — dark-glass, cùng ngôn ngữ hình ảnh với ScanIpProxy */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --panel: rgba(22, 27, 34, 0.85);
  --glass: rgba(30, 37, 48, 0.55);
  --hover: rgba(48, 54, 61, 0.5);
  --ink: #e6edf3;
  --muted: #8b949e;
  --faint: #6e7681;
  --line: rgba(48, 54, 61, 0.7);
  --accent: #58a6ff;
  --run: #3fb950;
  --run-bg: rgba(63, 185, 80, .15);
  --idle: #58a6ff;
  --idle-bg: rgba(88, 166, 255, .13);
  --quar: #f85149;
  --quar-bg: rgba(248, 81, 73, .15);
  --stale: #d29922;
  --stale-bg: rgba(210, 153, 34, .16);
  --miss: #8b949e;
  --miss-bg: rgba(139, 148, 158, .13);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg2: #fff;
  --panel: #fff;
  --glass: #fff;
  --hover: #f0f3f6;
  --ink: #1f2328;
  --muted: #59636e;
  --faint: #818b98;
  --line: #d1d9e0;
  --accent: #0969da;
  --run: #1a7f37;
  --run-bg: #dafbe1;
  --idle: #0969da;
  --idle-bg: #ddf4ff;
  --quar: #cf222e;
  --quar-bg: #ffebe9;
  --stale: #9a6700;
  --stale-bg: #fff8c5;
  --miss: #59636e;
  --miss-bg: #eaeef2;
  --shadow: 0 1px 3px rgba(31, 35, 40, .12), 0 4px 14px rgba(31, 35, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(88, 166, 255, .08), transparent),
    var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }

/* ---------- header ---------- */
.header {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1360px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.header-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip-status {
  display: flex; align-items: center; gap: 6px;
  background: var(--glass); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 20px; font-size: 12px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.chip-status.ok .dot { background: var(--run); box-shadow: 0 0 8px var(--run); }
.chip-status.bad .dot { background: var(--quar); box-shadow: 0 0 8px var(--quar); }
.dot.live { background: var(--run); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.updated { color: var(--faint); font-size: 12px; }
.icon-btn {
  background: var(--glass); border: 1px solid var(--line); color: var(--ink);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.link { text-decoration: none; }

/* ---------- layout ---------- */
.wrap { max-width: 1360px; margin: 0 auto; padding: 20px; }
.banner { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; }
.banner.error { background: var(--quar-bg); border: 1px solid var(--quar); color: var(--ink); }

/* ---------- tiles ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  text-align: left; font: inherit; color: inherit; cursor: pointer; width: 100%;
  transition: transform .1s, border-color .15s, box-shadow .15s;
}
.tile:hover { transform: translateY(-1px); border-color: var(--accent); }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,.35), var(--shadow); }
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.tile.run::before { background: var(--run); } .tile.run .v { color: var(--run); }
.tile.idle::before { background: var(--idle); }
.tile.quar::before { background: var(--quar); } .tile.quar .v { color: var(--quar); }
.tile.stale::before { background: var(--stale); } .tile.stale .v { color: var(--stale); }
.tile.sel.run { box-shadow: 0 0 0 2px rgba(63,185,80,.4), var(--shadow); border-color: var(--run); }
.tile.sel.quar { box-shadow: 0 0 0 2px rgba(248,81,73,.4), var(--shadow); border-color: var(--quar); }
.tile.sel.stale { box-shadow: 0 0 0 2px rgba(210,153,34,.4), var(--shadow); border-color: var(--stale); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--glass); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 20px; font-size: 12.5px; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.chip:hover { background: var(--hover); color: var(--ink); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="light"] .chip.active { color: #fff; }
.chip .n { opacity: .7; font-variant-numeric: tabular-nums; margin-left: 4px; }
.search { margin-left: auto; }
.search input {
  background: var(--glass); border: 1px solid var(--line); color: var(--ink);
  padding: 8px 12px; border-radius: 8px; font-size: 13px; width: 220px; outline: none;
}
.search input:focus { border-color: var(--accent); }

/* ---------- panel + table ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; }
.count { color: var(--faint); font-size: 12.5px; font-weight: 400; }
.hint-inline { color: var(--faint); font-size: 12px; margin-left: auto; }
.hint-inline a, .foot a { color: var(--accent); text-decoration: none; }
.hint-inline a:hover, .foot a:hover { text-decoration: underline; }
.help-th .qmark { cursor: pointer; color: var(--accent); font-weight: 700; margin-left: 2px; }
.qmark:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 900px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
td.id { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; color: var(--accent); white-space: nowrap; }
td.mono { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); font-size: 12px; }
.dim { color: var(--faint); }

/* status badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.running { background: var(--run-bg); color: var(--run); }
.badge.idle { background: var(--idle-bg); color: var(--idle); }
.badge.quarantined { background: var(--quar-bg); color: var(--quar); }
.badge.stale-lock { background: var(--stale-bg); color: var(--stale); }
.badge.missing { background: var(--miss-bg); color: var(--miss); }
.wp { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700;
  background: var(--glass); border: 1px solid var(--line); color: var(--muted); }
.wp.WP1 { color: #58a6ff; } .wp.WP2 { color: #3fb950; } .wp.WP3 { color: #d29922; }

.run-host { display: flex; flex-direction: column; gap: 1px; }
.run-host .h { font-weight: 600; }
.run-host .t { color: var(--faint); font-size: 11px; }
.run-host .h.warn, .run-host .t.warn { color: var(--stale); }

.rowlink { cursor: pointer; }
.rowlink.active { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.empty.sm { padding: 16px; font-size: 12.5px; }
.foot { color: var(--faint); font-size: 12px; text-align: center; padding: 10px 0 30px; }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; background: var(--glass); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; border: 0; color: var(--muted); padding: 6px 14px; font: inherit;
  font-size: 12.5px; cursor: pointer; transition: background .15s, color .15s;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--accent); color: #fff; }

/* ---------- stats ---------- */
.stats-body { padding: 16px 18px; }
.chart-card { margin-bottom: 16px; }
.chart-title { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.legend { display: inline-flex; gap: 12px; }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.legend .lg-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-wrap { width: 100%; overflow: hidden; }
svg.chart { width: 100%; height: 220px; display: block; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .axis { fill: var(--faint); font-size: 10px; }
svg.chart .bar { transition: opacity .1s; }
svg.chart .bar:hover { opacity: .8; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.mini-card { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.mini-title { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.ranklist { display: flex; flex-direction: column; gap: 9px; }
.rank { display: flex; flex-direction: column; gap: 3px; }
.rank.clickable { cursor: pointer; }
.rank.clickable:hover .rank-label { color: var(--accent); }
.rank-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.rank-label { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-bar { height: 6px; background: var(--hover); border-radius: 4px; overflow: hidden; }
.rank-fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 4px; }
.rank-sub { color: var(--faint); font-size: 11px; }

/* ---------- drawer ---------- */
/* [hidden] phải thắng display:flex/fixed bên dưới, nếu không drawer luôn hiện */
.drawer[hidden], .drawer-scrim[hidden] { display: none !important; }
.drawer-scrim { position: fixed; inset: 0; background: rgba(1,4,9,.55); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 96vw); z-index: 50;
  background: var(--bg2); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,.4);
  display: flex; flex-direction: column; animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-id { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; font-size: 16px; color: var(--accent); word-break: break-all; }
.drawer-sub { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.drawer-body { padding: 16px 18px; overflow-y: auto; }
.drawer-h { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.drawer-foot { color: var(--faint); font-size: 11.5px; margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 10px; }

.guide { display: flex; flex-direction: column; gap: 10px; }
.drawer-note { padding: 11px 13px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; }
.drawer-note code { background: var(--hover); padding: 1px 5px; border-radius: 4px; }
.drawer-note.warn { background: var(--stale-bg); border: 1px solid var(--stale); }
.drawer-note.bad  { background: var(--quar-bg);  border: 1px solid var(--quar); }
.drawer-note.info { background: var(--idle-bg);  border: 1px solid var(--idle); }
.drawer-note.ok   { background: var(--run-bg);   border: 1px solid var(--run); }
.steps { margin: 2px 0 4px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.45; }
.steps code { background: var(--hover); padding: 1px 5px; border-radius: 4px; }

.cmd { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.cmd-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--glass); }
.cmd-title { font-size: 11.5px; color: var(--muted); }
.copy-btn { background: var(--glass); border: 1px solid var(--line); color: var(--ink); font: inherit; font-size: 11.5px; padding: 3px 10px; border-radius: 6px; cursor: pointer; }
.copy-btn:hover { background: var(--hover); border-color: var(--accent); }
.cmd pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--ink); white-space: pre; }

.kv-group { display: grid; grid-template-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.kv { display: grid; grid-template-columns: 42% 58%; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv-k { padding: 8px 12px; color: var(--muted); font-size: 12.5px; background: var(--glass); }
.kv-v { padding: 8px 12px; font-size: 12.5px; word-break: break-word; }
.kv-v.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

body.drawer-open { overflow: hidden; }

@media (max-width: 640px) {
  .subtitle { display: none; }
  .search { margin-left: 0; width: 100%; }
  .search input { width: 100%; }
  .hint-inline { display: none; }
}
