:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --danger: #ef4444;
  --border: #334155;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  background: var(--accent);
  color: white;
  font-weight: 600;
}
button.secondary { background: var(--panel2); color: var(--text); }
button.danger { background: var(--danger); }
input, select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  width: 100%;
}
label { display:block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); padding: 32px; border-radius: 16px; width: 360px;
  border: 1px solid var(--border);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Layout */
.topbar {
  display:flex; align-items:center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; }
.layout { display: flex; height: calc(100vh - 57px); }
.sidebar {
  width: 300px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px;
}
.main { flex: 1; overflow-y: auto; padding: 20px; }
.emp {
  padding: 11px 12px; border-radius: 10px; margin-bottom: 6px; cursor: pointer;
  border: 1px solid transparent;
}
.emp:hover { background: var(--panel2); }
.emp.active { background: var(--panel2); border-color: var(--accent); }
.emp .name { font-weight: 600; font-size: 14px; }
.emp .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.dot.on { background: var(--accent2); }
.dot.off { background: #64748b; }

.cards { display:flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card {
  background: var(--panel); border:1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; min-width: 150px;
}
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 700; margin-top: 4px; }

.section { margin-top: 22px; }
.section h3 { font-size: 15px; margin: 0 0 10px; }
.grid-shots { display:grid; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); gap: 10px; }
.shot { border:1px solid var(--border); border-radius: 8px; overflow:hidden; background: var(--panel); }
.shot img { width:100%; display:block; cursor: pointer; }
.shot .t { font-size: 11px; color: var(--muted); padding: 5px 7px; }
.audio-item, .call-item {
  background: var(--panel); border:1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px; font-size: 13px;
}
.call-item .tag { padding:2px 8px; border-radius: 20px; font-size: 11px; background: var(--panel2); }
.row { display:flex; gap: 12px; align-items:flex-end; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.modal-bg { position:fixed; inset:0; background: rgba(0,0,0,.85); display:none; align-items:center; justify-content:center; z-index:50; gap: 12px; padding: 16px; }
.modal-bg.show { display:flex; }
.modal-bg img { max-width: 86vw; max-height: 82vh; border-radius: 8px; display:block; }
.lb-stage { display:flex; flex-direction:column; align-items:center; gap: 8px; }
.lb-caption { color:#cbd5e1; font-size: 13px; }
.lb-nav {
  width: 44px; height: 44px; border-radius: 50%; background: rgba(30,41,59,.9);
  color:#fff; font-size: 28px; line-height: 1; display:flex; align-items:center; justify-content:center;
  border: 1px solid #475569; flex-shrink: 0; cursor: pointer;
}
.lb-nav:hover { background: #334155; }
.hidden { display:none; }
table { width:100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align:left; padding: 8px; border-bottom: 1px solid var(--border); }


.webhook-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #0b1220;
  border: 1px solid var(--border, #334155);
}
.webhook-box .webhook-url,
.webhook-url {
  display: block;
  margin-top: 6px;
  word-break: break-all;
  color: #93c5fd;
  font-size: 12px;
}
.call-item .tag { margin-right: 6px; }

/* Giai đoạn 5 — cảnh báo / báo cáo */
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  vertical-align: middle;
}
.alert-strip {
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.alert-strip.critical { background: #450a0a; color: #fecaca; }
.alert-strip.warning { background: #422006; color: #fde68a; }
.system-box, .sys-grid {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.sys-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.sys-grid .k { font-size: 11px; color: var(--muted); }
.sys-grid .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.alert-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel);
}
.alert-item .alert-top { display: flex; gap: 8px; margin-bottom: 4px; }
.alert-item .sev, .alert-item .type {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel2);
  text-transform: uppercase;
}
.alert-item.sev-critical { border-color: #ef4444; }
.alert-item.sev-critical .sev { background: #7f1d1d; color: #fecaca; }
.alert-item.sev-warning { border-color: #f59e0b; }
.alert-item.sev-warning .sev { background: #78350f; color: #fde68a; }
.alert-item.sev-info .sev { background: #1e3a5f; color: #93c5fd; }
.alert-item .msg { font-size: 14px; font-weight: 600; }
.alert-item.acked { opacity: 0.6; }
.alert-item .alert-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.alert-item .ack-tag { margin-left: auto; font-size: 11px; color: #86efac; background: #14532d; padding: 2px 8px; border-radius: 999px; }
.ack-btn { padding: 4px 10px; font-size: 12px; }
.risk-box { background: #1f2937; border: 1px solid #374151; border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.risk-row { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.risk-row .risk-score { font-weight: 700; color: #fca5a5; min-width: 28px; text-align: right; }
.tab-btn { padding: 6px 12px; }
.cards { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 720px) {
  .sys-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }
  .topbar h1 { font-size: 15px; line-height: 1.3; }
  .topbar .row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .topbar button,
  .topbar select,
  .topbar .team-filter {
    flex: 1 1 auto;
    min-width: calc(50% - 6px);
    font-size: 12px;
    padding: 8px 10px;
  }
  .layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 120px);
  }
  .sidebar {
    width: 100%;
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main { padding: 14px; }
  .cards .card { min-width: calc(50% - 8px); flex: 1 1 140px; }
  .modal .card,
  .modal-card {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh;
    overflow: auto;
  }
  .grid-shots { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* GĐ10-12 — theme sáng */
html[data-theme="light"] {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel2: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent2: #16a34a;
  --danger: #dc2626;
  --border: #cbd5e1;
}
html[data-theme="light"] .webhook-box,
html[data-theme="light"] .system-box,
html[data-theme="light"] .sys-grid { background: #f8fafc; }
html[data-theme="light"] .webhook-url { color: #1d4ed8; }
html[data-theme="light"] .lb-caption { color: #e2e8f0; }
html[data-theme="light"] .risk-box { background: #fff7ed; border-color: #fed7aa; }
html[data-theme="light"] .risk-row .risk-score { color: #b91c1c; }
html[data-theme="light"] .alert-strip.critical { background: #fee2e2; color: #991b1b; }
html[data-theme="light"] .alert-strip.warning { background: #fef3c7; color: #92400e; }

/* Thanh trên: bộ lọc nhóm, tìm nhanh */
.team-filter { width: auto; min-width: 140px; padding: 7px 10px; font-size: 13px; }
#empSearch { font-size: 13px; padding: 7px 10px; }
.tab-btn.active { background: var(--accent); color: #fff; }
button.small { padding: 4px 10px; font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.good-txt { color: var(--accent2); font-weight: 600; }
.bad-txt { color: var(--danger); font-weight: 600; }

/* Danh sách nhân viên */
.emp.locked { opacity: .55; }
.note-tag {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: var(--panel2); color: var(--muted); vertical-align: middle; margin-left: 2px;
}
.note-tag.leave { background: #1e3a5f; color: #93c5fd; }
.note-tag.half { background: #78350f; color: #fde68a; }
html[data-theme="light"] .note-tag.leave { background: #dbeafe; color: #1e40af; }
html[data-theme="light"] .note-tag.half { background: #fef3c7; color: #92400e; }
.team-chip {
  display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 999px;
  background: rgba(59,130,246,.18); color: var(--accent); vertical-align: middle;
}

/* Tổng quan trực tiếp */
.card.ov { border-left: 4px solid var(--border); }
.card.ov.good { border-left-color: var(--accent2); }
.card.ov.warn { border-left-color: #f59e0b; }
.card.ov.bad  { border-left-color: var(--danger); }
.card .v .sub { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel2); }
tr.top-row td { background: rgba(34,197,94,.08); }
tr.drop-row td { background: rgba(239,68,68,.10); }
.trend { font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 999px; }
.trend.up { color: #86efac; background: rgba(34,197,94,.15); }
.trend.down { color: #fca5a5; background: rgba(239,68,68,.15); }
.trend.flat { color: var(--muted); background: var(--panel2); }
html[data-theme="light"] .trend.up { color: #166534; }
html[data-theme="light"] .trend.down { color: #991b1b; }

/* Timeline 288 ô × 5 phút */
.tl-wrap { margin: 6px 0 4px; }
.tl-bar {
  display: grid; grid-template-columns: repeat(288, 1fr); gap: 1px;
  height: 26px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--panel);
}
.tl-cell { position: relative; background: var(--panel); }
.tl-cell.idle { background: #475569; }
.tl-cell.lo { background: #86efac55; }
.tl-cell.mid { background: #4ade80; }
.tl-cell.hi { background: #16a34a; }
.tl-cell.call::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px;
  transform: translate(-50%,-50%); border-radius: 50%; background: #fff; box-shadow: 0 0 2px #000;
}
.tl-hours { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 2px; }
.tl-legend { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin: 0 2px 0 8px; }
.tl-legend.hi { background: #16a34a; }
.tl-legend.mid { background: #4ade80; }
.tl-legend.lo { background: #86efac55; border: 1px solid var(--border); }
.tl-legend.idle { background: #475569; }

/* Bảng quản lý nhân viên / ghi chú */
.manage-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin: 12px 0;
}
.manage-panel h4 { margin: 0 0 6px; font-size: 14px; }
.days-pick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.day-chk {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text);
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; margin: 0; cursor: pointer;
}
.day-chk input { width: auto; margin: 0; }
.stab label { margin-top: 10px; }
.report-pre {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  white-space: pre-wrap; font-size: 13px; line-height: 1.5; max-height: 480px; overflow: auto; margin: 0;
}

/* Dung lượng */
.disk-bar { height: 14px; background: var(--panel2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); margin: 6px 0; }
.disk-bar .fill { height: 100%; background: var(--accent2); }
.disk-bar .fill.warn { background: #f59e0b; }
.disk-bar .fill.bad { background: var(--danger); }
.sep { border-top: 1px solid var(--border); margin: 14px 0; }
