/* =====================================================
   PCCCTrace Web CQNN — Design Tokens
   Source: 07-7-ux-web-cqnn.md (Direction A — Government Authoritative Tablet)
   Variant of Web DN tokens: dark sidebar · gold star accent · audit banner đỏ persistent
   ===================================================== */

:root {
  /* Colors — Brand & action */
  --primary: #1e3a8a;            /* blue-900 */
  --primary-action: #1e40af;
  --primary-action-hover: #1d4ed8;
  --tertiary: #0284c7;
  --secondary: #4b5563;

  /* Accent — Government gold star */
  --accent: #fbbf24;            /* amber-400 — gov badge / CQNN signal */
  --accent-dark: #b45309;       /* amber-700 — text on light */
  --accent-soft: #fef3c7;

  /* Colors — Neutral */
  --neutral: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #737373;

  /* Sidebar — dark authoritative */
  --sidebar-bg: #0f172a;        /* slate-900 */
  --sidebar-bg-hover: #1e293b;  /* slate-800 */
  --sidebar-border: #1e293b;
  --sidebar-text: #cbd5e1;      /* slate-300 */
  --sidebar-text-muted: #64748b;/* slate-500 */
  --sidebar-active-bg: #1e3a8a;
  --sidebar-active-text: #ffffff;

  /* Audit mode banner — đỏ persistent */
  --audit-bg: #dc2626;
  --audit-text: #fef2f2;

  /* Colors — Semantic */
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --focus-ring: #93c5fd;

  /* Soft tints */
  --success-soft: #dcfce7;
  --warning-soft: #fef3c7;
  --error-soft: #fee2e2;
  --info-soft: #e0f2fe;
  --primary-soft: #dbeafe;

  /* Radius */
  --r-none: 0;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;
  --r-full: 9999px;

  /* Spacing */
  --s-xs: 4px;
  --s-sm: 8px;
  --s-md: 16px;
  --s-lg: 24px;
  --s-xl: 32px;
  --s-xxl: 48px;

  /* Layout */
  --audit-h: 40px;
  --topbar-h: 56px;
  --sidebar-w: 240px;
  --sidebar-collapsed-w: 64px;
  --content-pad: 24px;
  --content-max: 1440px;
  --detail-panel-w: 380px;
}

/* Reset / base */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--neutral);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
a { color: var(--primary-action); text-decoration: none; }
a:hover { color: var(--primary-action-hover); text-decoration: underline; }
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
code { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 0.92em; }

/* Typography helpers */
.h-lg { font-size: 30px; font-weight: 700; line-height: 1.2; }
.h-md { font-size: 24px; font-weight: 700; line-height: 1.25; }
.t-md { font-size: 18px; font-weight: 650; line-height: 1.35; }
.b-md { font-size: 14px; font-weight: 400; line-height: 1.5; }
.b-sm { font-size: 13px; font-weight: 400; line-height: 1.45; }
.label-md { font-size: 14px; font-weight: 600; line-height: 1.25; }
.cap { font-size: 12px; font-weight: 500; line-height: 1.35; color: var(--text-muted); }

/* ============= Components ============= */

/* Buttons — touch target 44px tablet */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--primary-action); color: var(--surface); }
.btn-primary:hover { background: var(--primary-action-hover); }
.btn-secondary { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-muted); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-muted); color: var(--text-primary); }
.btn-danger { background: var(--error); color: var(--surface); }
.btn-gold { background: var(--accent); color: #422006; border-color: #d97706; }
.btn-gold:hover { background: #f59e0b; }
.btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn-lg { height: 52px; padding: 0 24px; font-size: 16px; }

/* Input */
.input {
  height: 44px; padding: 0 12px;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; width: 100%;
}
.input:focus { outline: 3px solid var(--focus-ring); outline-offset: -1px; border-color: var(--primary-action); }
.input-lg { height: 52px; font-size: 16px; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
select.input { cursor: pointer; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-lg);
}
.card-tight { padding: var(--s-md); }
.card-title { font-size: 16px; font-weight: 650; color: var(--text-primary); margin: 0 0 4px; }
.card-subtitle { font-size: 13px; color: var(--text-secondary); margin: 0 0 var(--s-md); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 10px;
  border-radius: var(--r-full);
  font-size: 12px; font-weight: 500;
  background: var(--surface-muted); color: var(--text-secondary);
}
.badge-success { background: var(--success-soft); color: #15803d; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-error { background: var(--error-soft); color: #b91c1c; }
.badge-info { background: var(--info-soft); color: #0369a1; }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-gold { background: var(--accent-soft); color: var(--accent-dark); }
.badge-phase2 { background: #f3e8ff; color: #6b21a8; }
.badge-tenant { background: #eef2ff; color: #3730a3; font-family: "JetBrains Mono", monospace; font-size: 11px; }
.badge-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: var(--r-full);
  background: currentColor; display: inline-block;
}

/* Government gold star badge (topbar) */
.gov-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px; font-weight: 600;
  border: 1px solid #fcd34d;
}
.gov-badge .star { color: var(--accent); }

/* Audit chain verify badge */
.audit-chain {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: var(--r-md);
  background: var(--success-soft); color: #15803d;
  font-size: 12px; font-weight: 600;
  cursor: help;
  border: 1px solid #bbf7d0;
}
.audit-chain.mismatch { background: var(--error-soft); color: #b91c1c; border-color: #fecaca; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th {
  text-align: left; padding: 12px var(--s-md);
  background: var(--surface-muted);
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.table tbody td {
  padding: 14px var(--s-md);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--surface-muted); }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }

/* ============= Audit mode banner — đỏ persistent (KHÔNG dismissible) ============= */
.audit-banner {
  position: sticky; top: 0; z-index: 50;
  height: var(--audit-h);
  background: var(--audit-bg);
  color: var(--audit-text);
  display: flex; align-items: center; justify-content: center;
  gap: 10px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0 var(--s-md);
  text-align: center;
}
.audit-banner .lock { font-size: 15px; }
.audit-banner .ref { opacity: 0.85; font-weight: 500; }

/* Topbar (authenticated) — sits under audit banner */
.topbar {
  position: sticky; top: var(--audit-h); z-index: 40;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--s-lg);
  gap: var(--s-md);
}
.topbar .brand { display: flex; align-items: center; }
.topbar .brand img { height: 34px; }
.topbar .gov-id {
  display: flex; flex-direction: column;
  padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border);
}
.topbar .gov-id b { font-size: 13px; color: var(--text-primary); }
.topbar .gov-id span { font-size: 11px; color: var(--text-muted); }
.topbar .spacer { flex: 1; }
.topbar .actions { display: flex; align-items: center; gap: var(--s-md); }
.region-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border-radius: var(--r-full);
  background: var(--surface-muted); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
}
.region-pill:hover { background: #e9eef5; }
.region-pill b { color: var(--text-primary); }
.avatar {
  width: 36px; height: 36px; border-radius: var(--r-full);
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; cursor: pointer;
}

/* Topbar pre-auth */
.topbar-pre {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--s-lg); gap: var(--s-md);
}
.topbar-pre .brand img { height: 36px; }
.topbar-pre .right { margin-left: auto; font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 12px; }

/* App shell — sidebar + main */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--audit-h) - var(--topbar-h));
}
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: var(--s-md) 0;
  display: flex; flex-direction: column;
  min-height: calc(100vh - var(--audit-h) - var(--topbar-h));
}
.sidebar .section {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--sidebar-text-muted);
  padding: var(--s-md) var(--s-lg) 6px;
  display: flex; align-items: center; gap: 6px;
}
.sidebar .section .ph { color: #c084fc; font-weight: 600; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px var(--s-lg);
  color: var(--sidebar-text);
  font-size: 14px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  text-decoration: none;
}
.sidebar .nav-item:hover { background: var(--sidebar-bg-hover); color: #fff; text-decoration: none; }
.sidebar .nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar .nav-item.disabled { opacity: 0.45; cursor: not-allowed; }
.sidebar .nav-item .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar .nav-item .ref { margin-left: auto; font-size: 10px; color: var(--sidebar-text-muted); font-family: "JetBrains Mono", monospace; }
.sidebar .nav-item.active .ref { color: #93c5fd; }

.sidebar .user-card {
  margin-top: auto;
  padding: var(--s-md);
  border-top: 1px solid var(--sidebar-border);
  display: flex; gap: 10px; align-items: center;
}
.sidebar .user-card .avatar { width: 36px; height: 36px; background: var(--accent); color: #422006; }
.sidebar .user-card .info { flex: 1; min-width: 0; }
.sidebar .user-card .info b { display: block; font-size: 13px; color: #f1f5f9; }
.sidebar .user-card .info span { display: block; font-size: 11px; color: var(--sidebar-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .user-card .logout { color: var(--sidebar-text-muted); font-size: 18px; cursor: pointer; padding: 4px; text-decoration: none; }
.sidebar .user-card .logout:hover { color: #f87171; }

/* Main content */
.main {
  padding: var(--content-pad);
  max-width: var(--content-max);
  width: 100%;
}
.page-header {
  display: flex; align-items: flex-start; gap: var(--s-md);
  margin-bottom: var(--s-lg);
}
.page-header .title { flex: 1; }
.page-header h1 { margin: 0 0 6px; font-size: 24px; font-weight: 700; }
.page-header .subtitle { color: var(--text-secondary); font-size: 14px; margin: 0; }
.page-header .actions { display: flex; gap: 12px; }

.breadcrumb { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { margin: 0 6px; }

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-md);
  margin-bottom: var(--s-lg);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-md) var(--s-lg);
}
.kpi .label { color: var(--text-secondary); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin: 0; }
.kpi .value { font-size: 28px; font-weight: 700; color: var(--text-primary); margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; color: var(--success); }
.kpi .delta.neg { color: var(--error); }
.kpi .delta.flat { color: var(--text-muted); }

/* Toolbar / pagination */
.toolbar {
  display: flex; gap: var(--s-sm); align-items: center;
  padding: var(--s-md);
  background: var(--surface);
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.toolbar .search-box { flex: 1; max-width: 420px; }
.toolbar .spacer { flex: 1; }
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-md);
  background: var(--surface);
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-size: 13px; color: var(--text-secondary);
}
.pagination .pages { display: flex; gap: 4px; }
.pagination .pages button {
  width: 32px; height: 32px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--r-sm); cursor: pointer; color: var(--text-secondary);
}
.pagination .pages button.active { background: var(--primary-action); color: var(--surface); border-color: var(--primary-action); }

/* Status pill helpers */
.status-active::before { content: "● "; color: var(--success); }
.status-pending::before { content: "● "; color: var(--warning); }
.status-blocked::before { content: "● "; color: var(--error); }
.status-draft::before { content: "● "; color: var(--text-muted); }

/* Map placeholder */
.map-placeholder {
  background: linear-gradient(135deg, var(--surface-muted) 25%, #e9eef5 50%, var(--surface-muted) 75%);
  background-size: 200% 200%;
  border: 1px solid var(--border); border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px; text-align: center;
}

/* Footer pre-auth */
.footer-pre {
  text-align: center; font-size: 12px;
  color: var(--text-muted); padding: var(--s-lg);
}
.footer-pre a { color: var(--text-muted); }

/* Utility */
.row { display: flex; gap: var(--s-md); align-items: center; }
.row-sm { display: flex; gap: var(--s-sm); align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--s-md); }
.col { display: flex; flex-direction: column; gap: var(--s-md); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-md); }
.wrap { flex-wrap: wrap; }
.mt-sm { margin-top: var(--s-sm); }
.mt-md { margin-top: var(--s-md); }
.mt-lg { margin-top: var(--s-lg); }
.mb-sm { margin-bottom: var(--s-sm); }
.mb-md { margin-bottom: var(--s-md); }
.mb-lg { margin-bottom: var(--s-lg); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-gold { color: var(--accent-dark); }

@media (max-width: 1024px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
