/* =====================================================
   PCCCTrace Web Platform — Design Tokens
   Source: 07-6-design.md (alpha, AD-001..AD-035)
   Variant of Web DN tokens: RED admin accent + DARK sidebar
   + persistent PLATFORM badge + TOTP input.
   ===================================================== */

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

  /* Colors — Admin accent (the differentiator vs Web DN) */
  --admin-accent: #dc2626;
  --admin-accent-hover: #b91c1c;

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

  /* Sidebar (dark graphite — visual isolation from DN) */
  --sidebar-bg: #1f2937;
  --sidebar-bg-hover: #273241;
  --sidebar-text: #cbd5e1;
  --sidebar-section: #94a3b8;
  --sidebar-active-bg: #fee2e2;
  --sidebar-active-text: #b91c1c;

  /* 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-success { background: var(--success); color: var(--surface); }
.btn-danger { background: var(--admin-accent); color: var(--surface); }
.btn-danger:hover { background: var(--admin-accent-hover); }
.btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

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

/* TOTP input (6 mono boxes) */
.totp-row { display: flex; gap: 10px; justify-content: center; margin: var(--s-md) 0; }
.totp-row input {
  width: 48px; height: 56px;
  text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 24px; font-weight: 600;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
}
.totp-row input:focus { outline: 3px solid var(--focus-ring); outline-offset: -1px; border-color: var(--admin-accent); }

/* 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); }
.card-danger { border-top: 3px solid var(--admin-accent); }

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

/* PLATFORM badge — square red chip, never dismissible */
.platform-badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  background: var(--admin-accent); color: #ffffff;
  border-radius: var(--r-sm);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap;
}

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

/* SLA countdown chips */
.sla { font-weight: 600; font-variant-numeric: tabular-nums; }
.sla-ok { color: var(--success); }
.sla-warn { color: var(--warning); }
.sla-crit { color: var(--admin-accent); }

/* 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-md);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand img { height: 32px; }
.topbar .search { flex: 1; max-width: 380px; 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(--admin-accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
}

/* Topbar pre-auth (login) */
.topbar-pre {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 0 var(--s-lg);
}
.topbar-pre .brand { display: flex; align-items: center; gap: 10px; }
.topbar-pre .brand img { height: 32px; }

/* Sidebar (DARK graphite) */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar {
  background: var(--sidebar-bg);
  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(--sidebar-section);
  padding: var(--s-md) var(--s-lg) 6px;
}
.sidebar .section .ph { color: #c084fc; font-weight: 600; margin-left: 6px; font-size: 10px; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 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: #ffffff; text-decoration: none; }
.sidebar .nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--admin-accent);
  font-weight: 600;
}
.sidebar .nav-item.disabled { opacity: 0.45; 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(--sidebar-section); font-family: "JetBrains Mono", monospace; }

.sidebar .user-card {
  margin-top: auto;
  padding: var(--s-md);
  border-top: 1px solid rgba(255,255,255,0.08);
  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: #f1f5f9; }
.sidebar .user-card .info span { display: block; font-size: 11px; color: var(--sidebar-section); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .user-card .logout { color: var(--sidebar-section); font-size: 18px; cursor: pointer; padding: 4px; }
.sidebar .user-card .logout:hover { color: var(--admin-accent); }

/* 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(200px, 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.accent { border-left: 3px solid var(--warning); }
.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(--admin-accent); }
.kpi .delta.flat { color: var(--text-muted); }

/* Banner */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 16px; border-radius: var(--r-md);
  font-size: 13px; line-height: 1.5;
  margin-bottom: var(--s-md);
}
.banner-danger { background: var(--error-soft); color: #991b1b; border: 1px solid #fecaca; }
.banner-info { background: var(--info-soft); color: #075985; border: 1px solid #bae6fd; }
.banner-warn { background: var(--warning-soft); color: #92400e; border: 1px solid #fde68a; }
.banner .ico { flex-shrink: 0; }

/* 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: 320px; }
.toolbar .spacer { flex: 1; }
.table-wrap { border: 1px solid var(--border); border-top: 0; background: var(--surface); }
.table-wrap.rounded-top { border-top: 1px solid var(--border); border-radius: var(--r-lg) var(--r-lg) 0 0; }
.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(--admin-accent); color: var(--surface); border-color: var(--admin-accent); }

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

/* Dropdown menu (row actions) */
.menu-btn {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: transparent;
  cursor: pointer; color: var(--text-secondary);
}
.menu-btn:hover { background: var(--surface-muted); border-color: var(--border); }

/* Sticky action bar (bottom of detail screens) */
.action-bar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: var(--s-md);
  padding: var(--s-md) var(--s-lg);
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin: var(--s-lg) calc(-1 * var(--content-pad)) calc(-1 * var(--content-pad));
}
.action-bar .spacer { flex: 1; }

/* 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(--admin-accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
