:root {
  --bg: #f7f8fc;
  --panel: #ffffff;
  --text: #1a1c21;
  --muted: #6a717d;
  --border: #e3e6ec;
  --primary: #0b64dd;
  --primary-dark: #0a5bc4;
  --up: #54b399;
  --down: #e7664c;
  --warn: #d6a200;
  --warn-bg: #fdf3d6;
  --down-bg: #fbeae5;
  --link: #0b64dd;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.muted { color: var(--muted); }

/* Top nav */
.topnav {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 10px 22px; font-size: 13px;
}
.crumb { background: #eef1f6; color: #4a4f59; padding: 4px 14px; border-radius: 4px; font-weight: 600; }
.topnav-right { display: flex; gap: 22px; color: #343741; align-items: center; }
.topnav-right .link { color: var(--link); }

.page { max-width: 1320px; margin: 0 auto; padding: 22px 26px 70px; }

/* Title */
.title-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.title-row h1 { font-size: 32px; font-weight: 700; margin: 0; }
.title-actions { display: flex; gap: 10px; align-items: center; }
.time-box { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 8px 14px; font-size: 13px; box-shadow: var(--shadow); }

.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 9px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; transition: background .12s; white-space: nowrap; }
.btn:hover { background: #f2f4f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-add { background: #e8f1fd; border-color: #b9d4f6; color: var(--primary); font-weight: 600; }
.btn-add:hover { background: #d7e7fb; }

/* Tab chuyển trang */
.view-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 18px; }
.vtab { border: none; background: none; padding: 10px 18px; cursor: pointer; font-size: 15px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.vtab:hover { color: var(--text); }
.vtab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* View Thành phần */
.comp-toolbar { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.comp-toolbar input[type=text] { flex: 0 0 280px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; }
.comp-toolbar input[type=text]:focus { border-color: var(--primary); }
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.comp-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 16px 18px; border-top: 3px solid var(--up); }
.comp-card.down { border-top-color: var(--down); }
.comp-card.unknown { border-top-color: #cfd4dc; }
.comp-card .cc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.comp-card .cc-name { font-weight: 700; font-size: 15px; }
.comp-card .cc-url { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, monospace; word-break: break-all; margin-top: 2px; }
.comp-card .cc-checks { display: flex; flex-direction: column; gap: 7px; margin-top: 6px; }
.cc-item { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-family: ui-monospace, monospace; }
.cc-item .ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; flex: none; }
.cc-item.ok .ic { background: var(--up); }
.cc-item.bad .ic, .cc-item.down .ic { background: var(--down); }
.cc-item.warn .ic { background: var(--warn); }
.cc-item .val { margin-left: auto; font-weight: 700; }
.cc-item.ok .val { color: #2e8366; }
.cc-item.bad .val, .cc-item.down .val { color: var(--down); }
.cc-item.warn .val { color: #946f00; }
.cc-none { font-size: 13px; color: var(--muted); }
.cc-foot { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 12px; color: var(--muted); display: flex; gap: 14px; }

/* Search bar */
.searchbar { display: flex; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin-bottom: 18px; box-shadow: var(--shadow); }
.filter-ic { color: var(--muted); padding: 0 4px; }
.searchbar input { flex: 1; border: none; outline: none; font-size: 14px; padding: 6px 4px; background: transparent; }
.filter-chip { font-size: 13px; color: #343741; background: #f5f7fa; border: 1px solid var(--border); border-radius: 6px; padding: 7px 12px; white-space: nowrap; }
.filter-chip b { color: var(--muted); font-weight: 600; }

/* Panel */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }

/* Overview */
.overview { display: grid; grid-template-columns: 320px 1fr; gap: 24px; }
.overview h3 { margin: 0 0 16px; font-size: 18px; }
.donut-row { display: flex; align-items: center; gap: 22px; }
.donut { width: 120px; height: 120px; border-radius: 50%; }
.legend { display: flex; flex-direction: column; gap: 12px; }
.leg { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #343741; }
.leg b { margin-left: 14px; min-width: 20px; }
.ldot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.ldot.up { background: var(--up); }
.ldot.down { background: var(--down); }

/* Pings over time */
.pings-block { border-left: 1px solid var(--border); padding-left: 24px; }
.pings { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.pbar { flex: 1; min-width: 8px; display: flex; flex-direction: column-reverse; height: 100%; }
.pbar .seg-down { background: var(--down); }
.pbar .seg-up { background: var(--up); }
.pbar .seg-empty { flex: 1; }
.pings-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; color: var(--muted); }

/* Table */
.table-head { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; }
.table-head h3 { margin: 0; font-size: 18px; }
.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tab { border: none; background: #fff; padding: 7px 16px; cursor: pointer; font-size: 13px; color: #343741; border-right: 1px solid var(--border); }
.tab:last-child { border-right: none; }
.tab.active { background: #e8f1fd; color: var(--primary); font-weight: 600; }

.mon-table { width: 100%; border-collapse: collapse; }
.mon-table thead th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.mon-table tbody td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13px; }
.mon-table tbody tr:hover { background: #fafbfd; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 4px; }
.badge.down { background: var(--down-bg); color: var(--down); }
.badge.up { background: #e3f2ec; color: #2e8366; }
.badge.unknown { background: #eef0f3; color: var(--muted); }
.sub { color: var(--muted); font-size: 12px; margin-top: 5px; }

.name-link { color: var(--link); font-weight: 600; text-decoration: none; }
.name-link:hover { text-decoration: underline; }
.url-link { color: var(--link); text-decoration: none; word-break: break-all; }
.url-link:hover { text-decoration: underline; }
.ext { font-size: 11px; opacity: .7; }
.dash { color: var(--muted); }

/* Downtime sparkline */
.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 34px; }
.spark span { width: 5px; border-radius: 1px; background: var(--down); }
.spark span.up { background: var(--up); }

/* Toggle bật/tắt cảnh báo */
.toggle { width: 34px; height: 18px; border-radius: 999px; background: #cfd4dc; position: relative; display: inline-block; cursor: pointer; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--up); }
.toggle.on::after { left: 18px; }
.chev { color: var(--muted); cursor: pointer; }
.del-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px; padding: 2px 6px; border-radius: 4px; }
.del-btn:hover { background: var(--down-bg); color: var(--down); }

.sub.err { color: var(--down); margin-top: 3px; }
.deps { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 4px; }
.deps.ok { background: #e3f2ec; color: #2e8366; }
.deps.bad { background: var(--down-bg); color: var(--down); }
.deps.warn { background: var(--warn-bg); color: var(--warn); }

.row-actions { white-space: nowrap; }
.chev { display: inline-block; margin-left: 8px; transition: transform .15s; font-size: 16px; }
.chev.open { transform: rotate(180deg); }

/* Hàng chi tiết */
.detail-row td { background: #f7f9fc; }
.detail { padding: 6px 4px 10px; }
.d-title { font-weight: 700; font-size: 13px; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 6px; font-family: ui-monospace, monospace; }
.chip.ok { background: #e3f2ec; color: #1f6e54; border: 1px solid #bfe3d5; }
.chip.bad, .chip.down { background: var(--down-bg); color: #b23a23; border: 1px solid #f3c6bb; }
.chip.warn { background: var(--warn-bg); color: #946f00; border: 1px solid #ecd699; }
.d-line { font-size: 13px; color: #343741; margin: 4px 0; }
.d-line code { background: #eef1f6; padding: 1px 6px; border-radius: 4px; }
.d-raw { margin-top: 8px; font-size: 12.5px; }
.d-raw summary { cursor: pointer; color: var(--link); }
.d-raw pre { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow: auto; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 40px; }
.hidden { display: none !important; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(20,25,35,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; border-radius: 10px; padding: 24px; width: min(480px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-box h2 { margin: 0 0 6px; font-size: 19px; }
.modal-box code { background: #eef1f6; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.modal-box input { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; }
.modal-box input:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.msg.error { color: var(--down); }
.msg.ok { color: #2e8366; }

/* Settings form */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; }
.field span { font-weight: 600; }
.field small { font-size: 11px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 12px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.hint { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.hint summary { cursor: pointer; color: var(--link); }
.hint code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; }
.hint ol { margin: 8px 0 0; padding-left: 18px; line-height: 1.6; }

@media (max-width: 860px) {
  .overview { grid-template-columns: 1fr; }
  .pings-block { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 18px; }
  .mon-table thead { display: none; }
  .mon-table, .mon-table tbody, .mon-table tr, .mon-table td { display: block; width: 100%; }
  .mon-table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .mon-table td { border: none; padding: 4px 12px; }
}

/* Hộp người dùng đăng nhập (Keycloak) trên thanh nav */
.user-box { display: inline-flex; align-items: center; gap: 8px; }
.user-box #user-name { font-weight: 600; }
.user-box .link { cursor: pointer; }
