/* MikroNOC - bang mau lay tu bo tham chieu dataviz, da qua validator
   (6/6 PASS o ca che do sang lan toi). */

:root {
  color-scheme: light;

  /* Be mat */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f2ee;
  --surface-hover:#eeeeea;

  /* Chu */
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;

  /* Duong ke */
  --border:       rgba(11, 11, 11, 0.10);
  --grid:         #e1e0d9;
  --axis:         #c3c2b7;

  /* Trang thai - co dinh, khong doi theo theme */
  --good:         #0ca30c;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;
  --good-text:    #006300;

  /* Chuoi du lieu */
  --series-1:     #2a78d6;   /* rx / ethernet */
  --series-2:     #eb6834;   /* tx / ipsec */
  --series-3:     #1baf7a;   /* wireguard */
  --accent:       #2a78d6;
  --accent-ink:   #ffffff;

  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 2px rgba(11,11,11,.05), 0 4px 16px rgba(11,11,11,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface:      #16171a;
    --surface-2:    #1f2024;
    --surface-hover:#26272c;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --ink-muted:    #898781;
    --border:       rgba(255, 255, 255, 0.10);
    --grid:         #2c2c2a;
    --axis:         #383835;
    --good-text:    #0ca30c;
    --series-1:     #3987e5;
    --series-2:     #d95926;
    --series-3:     #199e70;
    --accent:       #3987e5;
    --accent-ink:   #ffffff;
    --shadow:       0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #16171a;
  --surface-2:    #1f2024;
  --surface-hover:#26272c;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --ink-muted:    #898781;
  --border:       rgba(255, 255, 255, 0.10);
  --grid:         #2c2c2a;
  --axis:         #383835;
  --good-text:    #0ca30c;
  --series-1:     #3987e5;
  --series-2:     #d95926;
  --series-3:     #199e70;
  --accent:       #3987e5;
  --accent-ink:   #ffffff;
  --shadow:       0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---------------- Bo cuc ---------------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 0 8px 18px; font-weight: 650; font-size: 16px; letter-spacing: -0.02em;
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent);
  flex: none;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); cursor: pointer; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
  font-family: inherit; font-size: 14px;
}
.nav-item:hover { background: var(--surface-hover); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.nav-spacer { flex: 1; }
/* Nhan pham vi vung: nguoi dung phai luon biet minh dang nhin phan nao cua he thong */
.scope-note {
  font-size: 12px; color: var(--ink-muted); padding: 0 10px 12px;
  margin-top: -8px; line-height: 1.4;
}
.scope-note.is-limited {
  color: var(--ink-2); font-weight: 550;
  border-left: 2px solid var(--warning); padding-left: 8px; margin: -6px 10px 12px;
}
.scope-note:empty { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.main-body { padding: 22px 26px 60px; flex: 1; min-width: 0; }

/* Thanh tren: logo cong ty o goc phai */
.topbar {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 14px; padding: 10px 26px; min-height: 56px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title {
  margin-right: auto; font-size: 13px; color: var(--ink-muted); font-weight: 500;
}
.brand-logo { height: 30px; width: auto; display: block; }
.brand-logo.on-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo.on-light { display: none; }
  :root:not([data-theme="light"]) .brand-logo.on-dark { display: block; }
}
:root[data-theme="dark"] .brand-logo.on-light { display: none; }
:root[data-theme="dark"] .brand-logo.on-dark { display: block; }
.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-sub { color: var(--ink-muted); font-size: 13px; }

/* ---------------- The ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}

.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
/* Bieu do can rong hon the thong thuong moi doc duoc truc thoi gian */
.grid-charts { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

/* ---------------- O chi so ---------------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-label {
  color: var(--ink-muted); font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .05em;
  display: flex; align-items: center; gap: 6px;
}
.stat-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.stat-note { color: var(--ink-muted); font-size: 12px; }
.stat.is-good .stat-value    { color: var(--good-text); }
.stat.is-warning .stat-value { color: var(--ink); }
.stat.is-critical .stat-value{ color: var(--critical); }

/* ---------------- Nhan trang thai ---------------- */
/* Mau khong bao gio dung mot minh: luon co cham + chu */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border);
}
.badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: none;
}
.badge.up        { color: var(--good-text); }
.badge.degraded  { color: var(--ink); }
.badge.degraded::before { background: var(--warning); }
.badge.down      { color: var(--critical); }
.badge.maintenance { color: var(--ink-muted); }
.badge.maintenance::before { background: var(--ink-muted); }
.badge.unknown   { color: var(--ink-muted); }
.badge.info::before     { background: var(--series-1); }
.badge.warning::before  { background: var(--warning); }
.badge.critical  { color: var(--critical); }
.badge.serious::before  { background: var(--serious); }
.badge.plain::before { display: none; }
.badge.plain { padding: 2px 9px; }

/* ---------------- Bang ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 10px; font-weight: 600; font-size: 12px;
  color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.row-link { cursor: pointer; }

/* ---------------- Dieu khien ---------------- */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
input[type="text"], input[type="password"], input[type="search"],
input[type="datetime-local"], select, textarea {
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; min-width: 0;
}
input:disabled, select:disabled, textarea:disabled {
  opacity: .55; cursor: not-allowed; background: var(--surface-2);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px; border-color: var(--accent);
}
.btn {
  font-family: inherit; font-size: 13px; font-weight: 550;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--surface-2); color: var(--ink); font-weight: 650; z-index: 1; }
label.check {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: 13px;
}
label.check input { flex: none; width: auto; }

/* ---------------- Bieu do ---------------- */
.chart { width: 100%; min-width: 0; overflow: hidden; }
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.chart-sub { font-size: 12px; color: var(--ink-muted); margin-bottom: 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* Bieu do cot ngang dung HTML thuan - nhan truc tiep, khong can thu vien */
.barlist { display: grid; gap: 9px; }
.barlist-row { display: grid; grid-template-columns: 110px 1fr 46px; gap: 10px; align-items: center; }
.barlist-label { font-size: 12.5px; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.barlist-track { background: var(--surface-2); border-radius: 4px; height: 20px; overflow: hidden; }
.barlist-fill { height: 100%; border-radius: 4px; background: var(--series-1); min-width: 3px; }
.barlist-fill.is-outdated { background: var(--warning); }
.barlist-value { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink); }

/* uPlot ghi de */
.uplot { font-family: var(--font) !important; width: 100% !important; }
.u-legend { font-size: 12px; color: var(--ink-2); }
.u-legend .u-marker { border-radius: 2px; }
.u-title { color: var(--ink); font-weight: 600; }

/* ---------------- So do ---------------- */
#cy { width: 100%; height: 620px; background: var(--surface); border-radius: var(--radius); }
.topo-legend {
  display: flex; gap: 18px; flex-wrap: wrap; padding-top: 12px;
  border-top: 1px solid var(--border); margin-top: 12px; font-size: 12px; color: var(--ink-2);
}
.legend-line { width: 20px; height: 0; border-top-width: 2px; border-top-style: solid; flex: none; }

/* ---------------- Dang nhap ---------------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { font-size: 18px; padding-bottom: 6px; }
.login-logo { height: 34px; width: auto; display: block; margin-bottom: 18px; }
.login-logo.on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .login-logo.on-light { display: none; }
  :root:not([data-theme="light"]) .login-logo.on-dark { display: block; }
}
:root[data-theme="dark"] .login-logo.on-light { display: none; }
:root[data-theme="dark"] .login-logo.on-dark { display: block; }
.field { display: grid; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
/* Chi ap cho o nhap la con truc tiep cua .field — neu khong, checkbox nam
   trong label.check se bi keo rong 100% va lam vo bo cuc. */
.field > input, .field > select, .field > textarea { width: 100%; }

/* ---------------- Hop thoai ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto; padding: 20px;
}
.modal.wide { max-width: 860px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.callout {
  border-left: 3px solid var(--warning); background: var(--surface-2);
  padding: 11px 13px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px; color: var(--ink-2);
}
.callout.danger { border-left-color: var(--critical); }
.callout strong { color: var(--ink); }

/* ---------------- Thong bao ---------------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 380px;
}
.toast.error { border-left-color: var(--critical); }
.toast.success { border-left-color: var(--good); }

.log-view {
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px;
  max-height: 380px; overflow-y: auto; color: var(--ink-2); line-height: 1.55;
}
.empty { text-align: center; padding: 40px 20px; color: var(--ink-muted); font-size: 13px; }
.spinner {
  width: 15px; height: 15px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.dl dt { color: var(--ink-muted); }
.dl dd { margin: 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--border); align-items: center;
  }
  .brand { padding: 0 12px 0 4px; }
  .nav-item { width: auto; }
  .nav-spacer { display: none; }
  .main-body { padding: 16px 14px 40px; }
  .topbar { padding: 8px 14px; min-height: 48px; }
  .brand-logo { height: 24px; }
}
