/* ============================================================
   Docent Design System — v1.0
   Linear/Notion-inspired. Dark sidebar, white content.
   Color used only for status, danger, warning, toasts.
   All other UI: zinc/slate neutrals + one brand accent.
   ============================================================ */

@import url('/static/fonts/fonts.css');

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Brand — used sparingly: active nav, primary button, links */
  --brand:           #7c3aed;
  --brand-hover:     #6d28d9;
  --brand-subtle:    #f5f3ff;
  --brand-muted:     rgba(124, 58, 237, 0.12);

  /* Page surfaces */
  --bg:              #f4f4f5;   /* zinc-100 page background */
  --surface:         #ffffff;   /* cards, panels */
  --surface-2:       #f8f8f9;   /* table header, input bg, secondary surface */
  --surface-hover:   #f4f4f5;   /* row hover */

  /* Borders */
  --border:          #e4e4e7;   /* zinc-200 */
  --border-strong:   #d4d4d8;   /* zinc-300 */

  /* Text */
  --text:            #18181b;   /* zinc-900 */
  --text-muted:      #52525b;   /* zinc-600: 7.7:1 on white */
  --text-subtle:     #71717a;   /* zinc-500: 4.8:1 on white (WCAG AA) */

  /* Sidebar — dark contrast */
  --sb-bg:           #18181b;   /* zinc-900 */
  --sb-border:       #27272a;   /* zinc-800 */
  --sb-text:         #a1a1aa;   /* zinc-400 */
  --sb-text-active:  #ffffff;
  --sb-hover:        rgba(255,255,255,0.05);
  --sb-active:       rgba(255,255,255,0.09);
  --sb-label:        #52525b;   /* zinc-600 — section labels */

  /* Status — ONLY for badges, toasts, alerts */
  --success:         #15803d;
  --success-bg:      #f0fdf4;
  --success-border:  #bbf7d0;
  --warning:         #b45309;
  --warning-bg:      #fffbeb;
  --warning-border:  #fde68a;
  --danger:          #b91c1c;
  --danger-bg:       #fef2f2;
  --danger-border:   #fecaca;
  --info:            #2563eb;
  --info-bg:         #eff6ff;
  --info-border:     #bfdbfe;

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

  /* Shadow */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg:  0 4px 8px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-xl:  0 10px 20px rgba(0,0,0,0.07), 0 4px 8px rgba(0,0,0,0.04);

  /* Transitions */
  --transition: 150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────────────────────── */
body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 22px; font-weight: 600; line-height: 1.3; }
h2 { font-size: 18px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 15px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; }
p  { color: var(--text-muted); line-height: 1.6; }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout — sidebar + content ────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.3px;
}
.sidebar-logo-badge {
  font-size: 10px;
  font-weight: 600;
  background: var(--brand-muted);
  color: var(--brand);
  padding: 2px 6px;
  border-radius: var(--r-full);
  border: 1px solid rgba(124,58,237,0.3);
}
.nav-section {
  padding: 16px 8px 4px;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sb-label);
  padding: 0 8px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--sb-text);
  font-size: 13.5px;
  font-weight: 450;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--sb-hover); color: #e4e4e7; text-decoration: none; }
.nav-item.active { background: var(--sb-active); color: var(--sb-text-active); font-weight: 500; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon { font-size: 16px; opacity: 0.7; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px;
  border-top: 1px solid var(--sb-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
}
.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: var(--r-full);
  background: var(--brand-muted);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name  { font-size: 12.5px; font-weight: 500; color: #e4e4e7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role  { font-size: 11px; color: var(--sb-text); }

/* ── Header ─────────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Main content area ──────────────────────────────────────── */
.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.page-content {
  padding: 28px 28px;
  flex: 1;
}
.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Page header (title + description) ─────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-header h1 { margin-bottom: 4px; }
.page-header p  { font-size: 13.5px; color: var(--text-muted); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); text-decoration: none; color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-danger:hover { background: var(--danger); color: white; text-decoration: none; }

.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }

/* Legacy inline-style back button — override gracefully */
button[onclick*="location.href='/dashboard'"],
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 0;
}
button[onclick*="location.href='/dashboard'"]:hover,
.btn-back:hover { background: var(--surface-2); color: var(--text); }

/* ── Filter tabs ────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--r-md);
  width: fit-content;
}
.filters button {
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition);
}
.filters button:hover  { color: var(--text); background: rgba(0,0,0,0.04); }
.filters button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── Tables ──────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead tr {
  border-bottom: 1px solid var(--border);
}
th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  background: var(--surface-2);
}
th:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
th:last-child  { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }
td strong { font-weight: 500; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Priority badges */
.priority-high   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid var(--danger-border); }
.priority-medium { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.priority-low    { background: var(--surface-2);  color: var(--text-muted); border: 1px solid var(--border); }

/* Status badges */
.status-pending     { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.status-in_progress { background: var(--info-bg);    color: var(--info);    border: 1px solid var(--info-border); }
.status-completed   { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.status-overdue     { background: var(--danger-bg);  color: var(--danger);  border: 1px solid var(--danger-border); }
.status-active      { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.status-inactive    { background: var(--surface-2);  color: var(--text-muted); border: 1px solid var(--border); }

/* ── Form elements ──────────────────────────────────────────── */
input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
/* Keyboard focus: a solid ring in the brand colour, visible at 3:1 on every
   surface (WCAG 2.4.7 / 1.4.11). The soft shadow above stays for mouse focus. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
select { cursor: pointer; padding-right: 28px; appearance: auto; }
label { font-size: 13px; font-weight: 500; color: var(--text); display: block; margin-bottom: 4px; }

/* ── Activity feed ──────────────────────────────────────────── */
.activity-feed { display: flex; flex-direction: column; }
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.activity-content { flex: 1; min-width: 0; }
.activity-content strong { font-weight: 500; color: var(--text); }
.activity-time { font-size: 12px; color: var(--text-subtle); margin-top: 2px; }

/* ── Modals ──────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 28px;
  max-width: 520px;
  width: 90%;
  box-shadow: var(--shadow-xl);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: var(--r-md);
  border: none;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }

/* ── Alerts / Toasts ────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.alert-danger, .error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 13.5px;
}
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }

/* ── Empty / loading states ─────────────────────────────────── */
.loading, .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-subtle);
  font-size: 14px;
}
.empty-state-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3   { color: var(--text-muted); font-size: 15px; margin-bottom: 4px; }

/* ── Stat cards ──────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--text-subtle); margin-top: 6px; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition);
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Divider ─────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Utility ─────────────────────────────────────────────────── */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.mt-1   { margin-top: 4px; }
.mt-2   { margin-top: 8px; }
.mt-4   { margin-top: 16px; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.text-sm    { font-size: 12.5px; }
.text-muted { color: var(--text-muted); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.w-full     { width: 100%; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Section viewer (case study, briefing, guide) ───────────── */
.viewer-container { max-width: 860px; margin: 0 auto; padding: 32px 20px; }
.viewer-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.viewer-header h1 { font-size: 26px; margin-bottom: 8px; }
.viewer-meta { font-size: 13px; color: var(--text-muted); }
.viewer-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.viewer-section h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.viewer-overview {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-muted);
  padding: 16px;
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.viewer-list { list-style: none; margin-top: 12px; }
.viewer-list li {
  padding: 10px 14px;
  margin-bottom: 6px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  line-height: 1.6;
  border-left: 3px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}
.viewer-list.findings     li { border-left-color: var(--info);    background: var(--info-bg); }
.viewer-list.recommendations li { border-left-color: var(--success); background: var(--success-bg); }
.viewer-list.lessons      li { border-left-color: var(--warning); background: var(--warning-bg); }

/* ── Back button (standalone pages) ────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  margin-bottom: 20px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}
.back-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ── Standalone page layout (no sidebar) ───────────────────── */
body.standalone {
  padding: 28px 20px;
}
body.standalone .container {
  max-width: 1100px;
  margin: 0 auto;
}
body.standalone .page-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
body.standalone .page-header h1 { margin-bottom: 4px; }
body.standalone .page-header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .page-content { padding: 16px; }
  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; }
}


/* ── Reflow at 320 CSS px (WCAG 1.4.10) ───────────────────────────
   Measured with backend/a11y/keyboard_reflow.js: fixed-width search boxes,
   long <select> options, non-shrinking flex rows and wide tables made pilot
   pages scroll sideways on a phone or at 400% zoom. */
input, select, textarea { max-width: 100%; }
@media (max-width: 480px) {
  input, select, textarea, .search-box { min-width: 0; width: 100% !important; }
  form, .search-input-container, .form-row, .toolbar, .page-header, .page-header-actions, .header, .header-actions { flex-wrap: wrap; }
  .main-chat, .chat-container > * { min-width: 0; }
  .card { overflow-x: auto; }
  .card > table, .table-wrap > table { min-width: 0; }
}
