/* =====================================================
   PCCCTrace Web DN — Design Tokens
   Source: 07-4-design.md (alpha-v2, 22 screens)
   ===================================================== */

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

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

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

  /* Soft tints (for badges/backgrounds) */
  --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 */
  --topbar-h: 56px;
  --sidebar-w: 240px;
  --sidebar-collapsed-w: 64px;
  --content-pad: 24px;
  --content-max: 1440px;
  --detail-panel-w: 360px;
}

/* 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; }

/* Typography helpers */
.h-lg { font-size: 30px; font-weight: 700; line-height: 1.2; letter-spacing: 0; }
.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 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  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:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* Input */
.input {
  height: 40px; 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: 48px; font-size: 16px; }

.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-phase2 { background: #f3e8ff; color: #6b21a8; }
.badge-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: var(--r-full);
  background: currentColor; display: inline-block;
}

/* 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:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }

/* Topbar (authenticated) */
.topbar {
  position: sticky; top: 0; z-index: 30;
  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-lg);
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar .brand img { height: 32px; }
.topbar .tenant {
  display: flex; flex-direction: column;
  padding-left: 12px; border-left: 1px solid var(--border);
}
.topbar .tenant b { font-size: 14px; color: var(--text-primary); }
.topbar .tenant span { font-size: 12px; color: var(--text-muted); }
.topbar .search { flex: 1; max-width: 360px; margin: 0 auto; }
.topbar .actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-md); }
.bell {
  position: relative; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-full); cursor: pointer;
  color: var(--text-secondary);
}
.bell:hover { background: var(--surface-muted); }
.bell.dot::after {
  content: ""; position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: var(--r-full);
  background: var(--error); border: 2px solid var(--surface);
}
.avatar {
  width: 32px; height: 32px; 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);
}
.topbar-pre .brand img { height: 32px; }
.topbar-pre .right { margin-left: auto; font-size: 14px; }

/* Sidebar */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar {
  background: var(--surface-muted);
  border-right: 1px solid var(--border);
  padding: var(--s-md) 0;
  display: flex; flex-direction: column;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar .section {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: var(--s-md) var(--s-lg) 6px;
}
.sidebar .section .ph { color: #9333ea; font-weight: 600; margin-left: 6px; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px var(--s-lg);
  color: var(--text-secondary);
  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: rgba(30, 64, 175, 0.06); color: var(--text-primary); text-decoration: none; }
.sidebar .nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidebar .nav-item.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.sidebar .nav-item .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar .nav-item .ref { margin-left: auto; font-size: 11px; color: var(--text-muted); font-family: "JetBrains Mono", monospace; }

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

/* 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); }

/* 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); }

/* Toolbar (filter row above tables) */
.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: 360px; }
.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); }

/* Utility */
.row { display: flex; gap: var(--s-md); 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); }
.mt-md { margin-top: var(--s-md); }
.mt-lg { margin-top: var(--s-lg); }
.mb-md { margin-bottom: var(--s-md); }
.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); }
