/* Dashboard TV — thiết kế để đọc từ 3–5 mét.
 *
 * Cỡ chữ ở đây dùng clamp() theo chiều rộng màn hình: cùng một file chạy được
 * trên TV 4K treo tường lẫn màn 1080p, không cần cấu hình riêng.
 * Không có gì nhỏ hơn 18px.
 */

.tv {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--plane); color: var(--ink);
  overflow: hidden;
}

/* ---------------- Thanh đầu ---------------- */
.tv-header {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 20px;
  padding: clamp(14px, 1.4vw, 26px) clamp(20px, 2vw, 40px);
  border-bottom: 2px solid var(--border); background: var(--surface);
}
.tv-head-left { display: flex; flex-direction: column; gap: 2px; }
.tv-title {
  font-size: clamp(20px, 1.5vw, 30px); font-weight: 700; letter-spacing: -0.02em;
}
.tv-panel-name {
  font-size: clamp(15px, 1vw, 21px); color: var(--ink-muted); font-weight: 550;
}
.tv-head-right {
  display: flex; align-items: center; justify-content: flex-end;
  gap: clamp(16px, 1.6vw, 32px); text-align: right;
}
.tv-clock {
  font-size: clamp(30px, 2.6vw, 52px); font-weight: 700;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.tv-date { font-size: clamp(13px, 0.85vw, 18px); color: var(--ink-muted); margin-top: 3px; }
.tv-logo { height: clamp(30px, 2.4vw, 48px); width: auto; display: block; }
.tv-logo.on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tv-logo.on-light { display: none; }
  :root:not([data-theme="light"]) .tv-logo.on-dark { display: block; }
}
:root[data-theme="dark"] .tv-logo.on-light { display: none; }
:root[data-theme="dark"] .tv-logo.on-dark { display: block; }

/* Chấm chỉ vị trí trong vòng xoay */
.tv-dots { display: flex; gap: 10px; }
.tv-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--axis); transition: background .3s, transform .3s;
}
.tv-dot.active { background: var(--accent); transform: scale(1.35); }

/* ---------------- Sân khấu ---------------- */
.tv-stage {
  padding: clamp(18px, 1.8vw, 40px) clamp(20px, 2vw, 44px);
  overflow: hidden; display: flex;
}
.tv-panel { flex: 1; display: flex; flex-direction: column; gap: clamp(16px, 1.6vw, 32px); min-height: 0; }
.tv-fade { animation: tvIn .45s ease-out; }
@keyframes tvIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.tv-empty {
  flex: 1; display: grid; place-items: center;
  font-size: clamp(20px, 1.6vw, 30px); color: var(--ink-muted);
}

/* ---------------- Panel 1: tổng quan ---------------- */
.tv-hero {
  text-align: center; flex: 1;
  display: grid; place-content: center; align-content: center;
  gap: 4px;
}
.tv-hero-value {
  font-size: clamp(72px, 9vw, 180px); font-weight: 750;
  line-height: 0.95; letter-spacing: -0.04em; color: var(--good-text);
}
.tv-hero-label {
  font-size: clamp(18px, 1.5vw, 30px); color: var(--ink-2); margin-top: 10px; font-weight: 550;
}
.tv-hero-sub { font-size: clamp(15px, 1.1vw, 22px); color: var(--ink-muted); margin-top: 6px; }

.tv-tiles {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: clamp(12px, 1.2vw, 24px);
}
.tv-tile {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 16px; padding: clamp(14px, 1.3vw, 26px); text-align: center;
}
.tv-tile-value {
  font-size: clamp(38px, 4vw, 78px); font-weight: 700; line-height: 1; letter-spacing: -0.03em;
}
.tv-tile-label {
  font-size: clamp(13px, 0.95vw, 19px); color: var(--ink-muted);
  margin-top: 8px; font-weight: 550; text-transform: uppercase; letter-spacing: .04em;
}
.tv-tile-note { font-size: clamp(12px, 0.85vw, 17px); color: var(--ink-2); margin-top: 4px; }
.tv-tile.is-good  .tv-tile-value { color: var(--good-text); }
.tv-tile.is-warn  { border-color: var(--warning); }
.tv-tile.is-bad   { border-color: var(--critical); }
.tv-tile.is-bad   .tv-tile-value { color: var(--critical); }

/* ---------------- Panel 2: khu vực ---------------- */
.tv-regions {
  flex: 1; display: grid; gap: clamp(14px, 1.4vw, 28px);
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-content: stretch;
}
.tv-region {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 18px; padding: clamp(20px, 2vw, 40px);
  display: flex; flex-direction: column; justify-content: flex-start;
  gap: clamp(16px, 1.8vw, 34px);
}
.tv-region-foot { margin-top: auto; }
.tv-region.is-warn { border-color: var(--warning); }
.tv-region.is-bad  { border-color: var(--critical); }
.tv-region-top { display: flex; flex-direction: column; gap: 6px; }
.tv-region-mid { display: flex; flex-direction: column; gap: 12px; }
.tv-region-name {
  font-size: clamp(22px, 1.8vw, 36px); font-weight: 700; letter-spacing: -0.02em;
}
.tv-region-count { display: flex; align-items: baseline; gap: 10px; }
.tv-region-num {
  font-size: clamp(48px, 5vw, 96px); font-weight: 750; line-height: 1; letter-spacing: -0.03em;
}
.tv-region-unit { font-size: clamp(15px, 1.1vw, 22px); color: var(--ink-muted); }

/* Thanh tỉ lệ: chiều dài mang thông tin, màu chỉ là lớp nhấn mạnh thứ hai */
.tv-region-bar {
  display: flex; gap: 3px; height: 16px; border-radius: 8px; overflow: hidden;
  background: var(--surface-2);
}
.tv-region-bar .seg { display: block; }
.tv-region-bar .seg.up { background: var(--good); }
.tv-region-bar .seg.degraded { background: var(--warning); }
.tv-region-bar .seg.down { background: var(--critical); }
.tv-region-bar .seg.maint { background: var(--ink-muted); }

.tv-region-stats {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: clamp(14px, 1.05vw, 21px); font-weight: 550;
}
.tv-region-stats .ok { color: var(--good-text); }
.tv-region-stats .warn { color: var(--ink); }
.tv-region-stats .bad { color: var(--critical); }
.tv-region-foot { font-size: clamp(13px, 0.9vw, 18px); color: var(--ink-muted); }

/* ---------------- Panel 3: sơ đồ ---------------- */
.tv-topo { flex: 1; min-height: 0; background: var(--surface); border-radius: 18px; }
.tv-topo-legend {
  display: flex; gap: clamp(14px, 1.4vw, 30px); flex-wrap: wrap; justify-content: center;
  font-size: clamp(13px, 0.95vw, 19px); color: var(--ink-2); font-weight: 550;
}
.tv-leg { display: inline-flex; align-items: center; gap: 8px; }
.tv-leg.is-bad { color: var(--critical); font-weight: 650; }
.tv-leg-dot { width: 14px; height: 14px; border-radius: 50%; }
.tv-leg-dot.good { background: var(--good); }
.tv-leg-dot.warn { background: var(--warning); }
.tv-leg-dot.bad  { background: var(--critical); }
.tv-leg-sq { width: 14px; height: 14px; border-radius: 3px; background: var(--ink-muted); }
.tv-leg-line { width: 28px; height: 0; border-top: 3px solid var(--ink-muted); }
.tv-leg-line.ethernet  { border-color: var(--series-1); }
.tv-leg-line.ospf      { border-color: var(--series-1); border-top-style: dashed; }
.tv-leg-line.ipsec     { border-color: var(--series-2); border-top-style: dashed; }
.tv-leg-line.wireguard { border-color: var(--series-3); border-top-style: dotted; }
.tv-leg-line.dead      { border-color: var(--critical); border-top-style: dashed; }

/* ---------------- Panel 4: thiết bị cần xử lý ---------------- */
.tv-table { width: 100%; border-collapse: collapse; font-size: clamp(16px, 1.15vw, 24px); }
.tv-table th {
  text-align: left; padding: 10px 14px; font-size: clamp(12px, 0.85vw, 17px);
  color: var(--ink-muted); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 2px solid var(--border);
}
.tv-table td { padding: clamp(10px, 0.9vw, 18px) 14px; border-bottom: 1px solid var(--border); }
.tv-table tr.is-down td { background: color-mix(in srgb, var(--critical) 9%, transparent); }
.tv-dev { font-weight: 650; }
.tv-dev-ip {
  font-family: var(--mono); font-size: clamp(12px, 0.85vw, 17px); color: var(--ink-muted);
}
.tv-reason { color: var(--ink-2); }
.tv-age { white-space: nowrap; color: var(--ink-muted); }
.tv-status {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap;
}
.tv-status::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: currentColor; }
.tv-status.down { color: var(--critical); }
.tv-status.degraded { color: var(--ink); }
.tv-status.degraded::before { background: var(--warning); }
.tv-status.maintenance, .tv-status.unknown { color: var(--ink-muted); }

.tv-allgood { flex: 1; display: grid; place-items: center; text-align: center; gap: 8px; align-content: center; }
.tv-allgood-mark {
  font-size: clamp(80px, 8vw, 150px); line-height: 1; color: var(--good-text); font-weight: 700;
}
.tv-allgood-text { font-size: clamp(22px, 1.8vw, 36px); font-weight: 650; }
.tv-allgood-sub { font-size: clamp(15px, 1.1vw, 22px); color: var(--ink-muted); }

.tv-wan {
  margin-top: auto;      /* day xuong day man hinh cho can doi */
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 16px; padding: clamp(14px, 1.2vw, 24px);
}
.tv-wan-head {
  font-size: clamp(13px, 0.95vw, 19px); color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 10px;
}
.tv-wan-rows {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr)); gap: 6px 36px;
}
.tv-wan-row {
  display: flex; align-items: baseline; gap: 16px;
  font-size: clamp(15px, 1.05vw, 21px); padding: 4px 0;
}
/* Ten duoc co lai truoc, so lieu khong bao gio bi cat */
.tv-wan-name {
  color: var(--ink-2); flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tv-wan-val {
  display: flex; gap: 16px; flex: none;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tv-wan-val .rx { color: var(--series-1); font-weight: 600; }
.tv-wan-val .tx { color: var(--series-2); font-weight: 600; }

/* ---------------- Chế độ sự cố: chiếm toàn màn hình ---------------- */
.tv.is-alarm { background: color-mix(in srgb, var(--critical) 14%, var(--plane)); }
.tv.is-alarm .tv-header { border-bottom-color: var(--critical); }
.tv.is-alarm .tv-panel-name { color: var(--critical); font-weight: 750; letter-spacing: .06em; }

.tv-alarm {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: clamp(10px, 1vw, 20px); text-align: center;
}
.tv-alarm-badge {
  align-self: center; background: var(--critical); color: #fff;
  font-size: clamp(18px, 1.5vw, 30px); font-weight: 750; letter-spacing: .05em;
  padding: 10px clamp(20px, 2vw, 40px); border-radius: 999px;
  animation: tvPulse 1.8s ease-in-out infinite;
}
/* Nhịp đập chậm và nhẹ: đủ để kéo mắt, không gây khó chịu khi nhìn cả ngày */
@keyframes tvPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .68; }
}
@media (prefers-reduced-motion: reduce) {
  .tv-alarm-badge { animation: none; }
  .tv-fade { animation: none; }
}
.tv-alarm-device {
  font-size: clamp(44px, 5.5vw, 110px); font-weight: 750;
  line-height: 1.02; letter-spacing: -0.03em; color: var(--critical);
}
.tv-alarm-msg { font-size: clamp(20px, 1.9vw, 40px); color: var(--ink); font-weight: 550; }
.tv-alarm-meta {
  display: flex; gap: clamp(16px, 1.6vw, 32px); justify-content: center; flex-wrap: wrap;
  font-size: clamp(16px, 1.2vw, 26px); color: var(--ink-2);
}
.tv-alarm-list {
  margin-top: clamp(10px, 1vw, 22px); background: var(--surface);
  border: 2px solid var(--border); border-radius: 16px;
  padding: clamp(12px, 1.1vw, 22px); text-align: left;
  max-width: 1400px; width: 100%; align-self: center;
}
.tv-alarm-list-head {
  font-size: clamp(13px, 0.95vw, 19px); color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 8px;
}
.tv-alarm-row {
  display: grid; grid-template-columns: minmax(160px, 1fr) 3fr auto;
  gap: 16px; padding: 7px 0; border-top: 1px solid var(--border);
  font-size: clamp(15px, 1.1vw, 22px);
}
.tv-alarm-row-dev { font-weight: 650; }
.tv-alarm-row-msg { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; }
.tv-alarm-row-age { color: var(--ink-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tv-alarm-more { font-size: clamp(14px, 1vw, 20px); color: var(--ink-muted); padding-top: 8px; }

/* ---------------- Chân trang ---------------- */
.tv-footer {
  display: flex; align-items: center; gap: clamp(16px, 1.6vw, 32px);
  padding: clamp(10px, 0.9vw, 18px) clamp(20px, 2vw, 40px);
  border-top: 2px solid var(--border); background: var(--surface);
  font-size: clamp(14px, 1vw, 20px); overflow: hidden;
}
.tv-health { color: var(--ink-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tv-health.is-offline { color: var(--critical); font-weight: 650; }
.tv-ticker {
  display: flex; gap: clamp(20px, 2vw, 44px); overflow: hidden;
  flex: 1; color: var(--ink-2); white-space: nowrap;
  /* Mo dan o mep phai: nguoi xem hieu la con nua, thay vi tuong chu bi loi */
  -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
  mask-image: linear-gradient(to right, #000 88%, transparent 100%);
}
.tv-ticker-ok { color: var(--good-text); font-weight: 550; }
.tv-ticker-item { display: inline-flex; align-items: center; gap: 8px; }
.tv-ticker-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ink-muted); }
.tv-ticker-dot.warning { background: var(--warning); }
.tv-ticker-dot.info { background: var(--series-1); }
.tv-ticker-dot.critical { background: var(--critical); }

/* Màn hình dọc hoặc TV nhỏ: xếp lại cho vừa */
@media (max-width: 1200px) {
  .tv-tiles { grid-template-columns: repeat(3, 1fr); }
  .tv-header { grid-template-columns: 1fr auto; }
  .tv-head-mid { display: none; }
}
