/* Thành phần dùng chung (dùng token màu của app.css) */
:root {
  --good: #15803D;
  --bad: #B91C1C;
  --warn-bg: #FFFBEB;
  --warn-border: #FDE68A;
  --info-bg: #EFF6FF;
  --info-border: #BFDBFE;
}

.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.card + .card, .kpi-grid + .card, .card + .kpi-grid, .notice + .card { margin-top: 16px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0 0 2px; font-size: 22px; }
.page-head p { margin: 0; font-size: 13.5px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

.notice { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; background: var(--bg-surface); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.notice.info { background: var(--info-bg); border-color: var(--info-border); }
.notice.ok { background: #F0FDF4; border-color: #BBF7D0; color: var(--good); }
.notice.error { background: var(--brand-primary-light); border-color: var(--brand-border); color: #991B1B; }

/* Thanh công cụ */
.toolbar { padding: 14px 18px; margin-bottom: 16px; }
.tool-row { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.tool-row + .tool-row { margin-top: 12px; }
.tool-row.filters:empty { display: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--bg-surface); max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: transparent; padding: 7px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--text-muted); white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--brand-primary-light); color: var(--text); }
.seg button.active { background: var(--brand-primary); color: #fff; }
.seg-small button { padding: 5px 11px; font-size: 12.5px; }
.date-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; font-size: 13px; color: var(--text-muted); }
.date-range label { display: inline-flex; align-items: center; gap: 6px; }
input[type="date"], select {
  font: inherit; font-size: 13.5px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-surface); color: var(--text);
}
input[type="date"]:focus, select:focus, .btn:focus-visible, .seg button:focus-visible, .chip:focus-visible, th.sortable:focus-visible {
  outline: 2px solid var(--brand-primary); outline-offset: 1px;
}
.filter { display: inline-flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.filter select { min-width: 150px; max-width: 220px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; border-top: 3px solid var(--brand-primary); }
.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 800; margin: 4px 0 2px; word-break: break-word; }
.kpi-sub { font-size: 12px; }
.delta { font-weight: 700; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

/* Thẻ + tiêu đề */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* Biểu đồ */

/* Chip nhóm cột */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--bg-surface); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--text-muted); }
.chip:hover { border-color: var(--brand-primary); color: var(--text); }
.chip.active { background: var(--brand-primary-light); border-color: var(--brand-primary); color: var(--brand-primary-hover); }

/* Bảng */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table thead th { background: #F1F5F9; font-size: 12.5px; color: var(--text-muted); position: sticky; top: 0; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--brand-primary); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--brand-primary-light); }
.data-table tfoot th { background: #F8FAFC; border-top: 2px solid var(--border); border-bottom: 0; color: var(--text); font-size: 13.5px; }
.data-table .sticky-col { position: sticky; left: 0; background: inherit; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.data-table tbody .sticky-col { background: var(--bg-surface); }
.data-table tbody tr:hover .sticky-col { background: var(--brand-primary-light); }
.data-table td.drillable { cursor: pointer; color: var(--brand-primary-hover); font-weight: 600; }
.data-table td.drillable:hover { text-decoration: underline; }
.data-table td.empty { text-align: center; color: var(--text-muted); padding: 28px; white-space: normal; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #F1F5F9; color: var(--text-muted); }
.badge.ok { background: #DCFCE7; color: var(--good); }
.badge.fail { background: #FEE2E2; color: var(--bad); }
.badge.run { background: #DBEAFE; color: #1D4ED8; }
.err-text { color: var(--bad); white-space: normal; max-width: 420px; }

#content.loading { opacity: 0.6; transition: opacity 0.15s; pointer-events: none; }

@media (max-width: 640px) {
  .date-range { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 19px; }
  .page-head h1 { font-size: 19px; }
  .toolbar { padding: 12px; }
  .tool-row.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .filter select { min-width: 0; max-width: none; width: 100%; }
  .date-range input[type="date"] { max-width: 150px; }
}
