:root {
  --bg: #070d19;
  --bg2: #0b1324;
  --card: #0f192d;
  --card2: #13203a;
  --line: rgba(148, 163, 184, .13);
  --line2: rgba(148, 163, 184, .22);
  --text: #e6edf7;
  --muted: #8b9bb4;
  --dim: #5b6b85;
  --accent: #2dd4bf;
  --accent2: #22b8a6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --gone: #8b5cf6;
  --nodata: #1e2a42;
  --r: 16px;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { background: radial-gradient(1200px 600px at 85% -10%, rgba(45, 212, 191, .07), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(99, 102, 241, .06), transparent 60%), var(--bg); min-height: 100vh; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 15px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: rgba(148, 163, 184, .12); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); margin: 2px 0 0; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
.link { color: var(--accent); font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ---------- nút & ô nhập ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line2); background: var(--card2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover { border-color: rgba(148, 163, 184, .4); background: #182844; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #34e0cb, var(--accent2)); color: #04241f; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: #fca5a5; }
.btn.wide { width: 100%; justify-content: center; height: 44px; }
.btn:disabled { opacity: .55; cursor: progress; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.field.grow { flex: 1; }
input, select, textarea { height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--bg2); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45, 212, 191, .15); }
input::placeholder, textarea::placeholder { color: var(--dim); }

/* ---------- đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px; display: flex; flex-direction: column; gap: 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); }
.err { color: #fca5a5; min-height: 20px; margin: 0; font-size: 13px; }

/* ---------- bố cục ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 22px 16px; border-right: 1px solid var(--line); background: rgba(9, 16, 30, .7); backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand.big b { font-size: 18px; }
.logo { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: var(--accent); background: linear-gradient(145deg, rgba(45, 212, 191, .18), rgba(45, 212, 191, .04)); border: 1px solid rgba(45, 212, 191, .3); }
.logo svg { width: 22px; height: 22px; stroke-width: 2.4; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; transition: background .15s, color .15s; }
.side nav a:hover { background: rgba(148, 163, 184, .07); color: var(--text); }
.side nav a.on { background: rgba(45, 212, 191, .1); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.side nav a.on svg { color: var(--accent); }
.count { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center; background: rgba(239, 68, 68, .18); color: #fca5a5; }
.count.warn { background: rgba(245, 158, 11, .18); color: #fcd34d; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.live { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); padding: 0 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: pulse 2s infinite; }
.live.off i { background: var(--bad); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
main { padding: 28px 32px 48px; min-width: 0; max-width: 1280px; }
.view { display: flex; flex-direction: column; gap: 20px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.span2 { grid-column: span 2; }
.card { background: linear-gradient(180deg, var(--card), #0d1628); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

/* ---------- thẻ X4 ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 24px 32px; padding: 26px; position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: 0; background: radial-gradient(600px 220px at 0% 0%, var(--glow, rgba(34, 197, 94, .14)), transparent 70%); pointer-events: none; }
.hero[data-s="ok"] { --glow: rgba(34, 197, 94, .16); --sc: var(--ok); }
.hero[data-s="slow"], .hero[data-s="flapping"] { --glow: rgba(245, 158, 11, .18); --sc: var(--warn); }
.hero[data-s="down"] { --glow: rgba(239, 68, 68, .22); --sc: var(--bad); }
.hero[data-s="unreachable"] { --glow: rgba(139, 92, 246, .2); --sc: var(--gone); }
.hero-label { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--sc, var(--dim)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sc, var(--dim)) 22%, transparent); }
.hero-state { font-size: 40px; font-weight: 750; letter-spacing: -.025em; margin-top: 10px; color: var(--sc, var(--text)); line-height: 1.1; }
.hero-sub { color: var(--muted); margin-top: 8px; font-size: 14.5px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-self: center; }
.metric { background: rgba(7, 13, 25, .55); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.metric small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.metric b { display: block; font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; line-height: 1.25; overflow-wrap: anywhere; }
.metric em { display: block; font-style: normal; color: var(--dim); font-size: 12px; }
.ribbon-wrap { grid-column: 1 / -1; }
.ribbon-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.ribbon { display: grid; grid-template-columns: repeat(144, 1fr); gap: 2px; height: 34px; }
.ribbon span { border-radius: 3px; background: var(--nodata); transition: transform .1s; }
.ribbon span:hover { transform: scaleY(1.18); }
.c0 { background: var(--ok) !important; } .c1 { background: var(--warn) !important; } .c2 { background: var(--bad) !important; } .c3 { background: var(--gone) !important; }
.ribbon span.c0 { opacity: .75; }
.legend i.cn { background: var(--nodata); }
.ribbon-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---------- cổng, thiết bị ---------- */
.ports { display: flex; flex-direction: column; gap: 8px; }
.port { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: rgba(7, 13, 25, .45); border: 1px solid var(--line); }
.port.watched { border-color: rgba(45, 212, 191, .35); }
.port b { font-weight: 650; }
.port small { display: block; color: var(--muted); font-size: 12px; }
.port .r { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.sd { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); }
.sd.ok { background: var(--ok); } .sd.warn { background: var(--warn); } .sd.bad { background: var(--bad); } .sd.off { background: #334155; }
.watch-mini { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.wm { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; background: rgba(7, 13, 25, .45); border: 1px solid var(--line); min-width: 0; }
.wm div { min-width: 0; flex: 1; }
.wm b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wm small { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.wm .ms { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- dòng thời gian ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 82px 14px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.timeline .sd { margin-top: 6px; }
.timeline p { margin: 0; }
.timeline .day { grid-column: 1 / -1; color: var(--accent); font-size: 12px; font-weight: 700; padding: 14px 0 4px; border: 0; letter-spacing: .04em; text-transform: uppercase; display: block; }
.empty { text-align: center; padding: 28px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button, .seg button { height: 32px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line2); background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.chips button.on, .seg button.on { background: rgba(45, 212, 191, .12); color: var(--text); border-color: rgba(45, 212, 191, .45); }

/* ---------- công cụ ---------- */
.tool-card { display: flex; flex-direction: column; gap: 18px; }
.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); flex-wrap: wrap; align-self: flex-start; }
.seg button { border: 0; height: 32px; }
.tool-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.tool-form .field:not(.grow) { width: 210px; }
.tool-form .port-field { width: 110px !important; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -6px; }
.quick button { height: 28px; padding: 0 10px; border-radius: 8px; border: 1px dashed var(--line2); background: transparent; color: var(--muted); font: 12px var(--mono); cursor: pointer; }
.quick button:hover { color: var(--text); border-color: var(--accent); }
.tool-out { border-top: 1px solid var(--line); padding-top: 18px; min-height: 120px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.res-title { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 14px; font-size: 15px; flex-wrap: wrap; }
.res-title small { color: var(--muted); font-weight: 500; font-family: var(--mono); }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pill.ok { background: rgba(34, 197, 94, .15); color: #86efac; } .pill.bad { background: rgba(239, 68, 68, .15); color: #fca5a5; } .pill.warn { background: rgba(245, 158, 11, .15); color: #fcd34d; } .pill.mute { background: rgba(148, 163, 184, .12); color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 70px; margin-top: 16px; }
.bars span { flex: 1; max-width: 48px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--accent), rgba(45, 212, 191, .35)); position: relative; min-height: 4px; }
.bars span::after { content: attr(data-v); position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.hops { width: 100%; border-collapse: collapse; }
.hops td { padding: 8px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.hops td:first-child { color: var(--dim); width: 36px; }
.hops .bar { height: 6px; border-radius: 3px; background: var(--accent); opacity: .7; }
.big-state { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.addr { display: flex; gap: 8px; flex-wrap: wrap; }
.addr span { font-family: var(--mono); padding: 6px 12px; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; margin-top: 16px; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line2); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:hover td { background: rgba(148, 163, 184, .04); }
.tbl td .actions { display: flex; gap: 6px; justify-content: flex-end; }
.tbl select { height: 30px; padding: 0 8px; border-radius: 8px; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #26344f; border-radius: 22px; cursor: pointer; transition: background .2s; }
.switch i::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #cbd5e1; border-radius: 50%; transition: transform .2s; }
.switch input:checked + i { background: var(--accent2); }
.switch input:checked + i::before { transform: translateX(16px); background: #fff; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.login-box { margin-top: 16px; padding: 16px; border-radius: 12px; border: 1px dashed rgba(45, 212, 191, .45); background: rgba(45, 212, 191, .06); display: flex; flex-direction: column; gap: 12px; }
.login-box .code { font: 700 26px var(--mono); letter-spacing: .12em; color: var(--accent); }
.login-box pre { margin: 0; max-height: 160px; overflow: auto; font: 12px var(--mono); color: var(--muted); white-space: pre-wrap; background: var(--bg2); padding: 10px; border-radius: 8px; }
.login-box .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; margin: 16px 0 0; }
.stack { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.stack .btn { align-self: flex-start; }

/* ---------- thông báo ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: #15233f; border: 1px solid var(--line2); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); animation: fade .2s ease; font-size: 13.5px; }
.toast.red { border-left-color: var(--bad); } .toast.orange { border-left-color: var(--warn); } .toast.green { border-left-color: var(--ok); }

/* ---------- điện thoại ---------- */
.tabbar { display: none; }
@media (max-width: 1100px) {
  .hero { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 18px 14px 96px; }
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .hero-state { font-size: 32px; }
  .ribbon { gap: 1px; height: 28px; }
  .watch-mini { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-form .field:not(.grow) { width: 100%; }
  .tool-form .btn { width: 100%; justify-content: center; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: rgba(9, 16, 30, .94); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 40; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--muted); padding: 4px 0; font-weight: 600; }
  .tabbar a.on { color: var(--accent); }
  .tabbar svg { width: 20px; height: 20px; }
}
