@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Inter:wght@400;500;600&display=swap');

/* ============================================================
   TenderFlow — Dutch Procurement Command
   Design system stylesheet
   ============================================================ */

:root {
  /* Palette */
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #dbeafe;
  --secondary: #0f172a;
  --accent: #0ea5e9;
  --accent-soft: #e0f2fe;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --error: #dc2626;
  --error-soft: #fee2e2;

  /* Typography */
  --font-body: 'Plus Jakarta Sans', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-heading: 'Plus Jakarta Sans', sans-serif;
  --weight-heading: 700;
  --body-size: 15px;

  /* Layout */
  --sidebar-width: 256px;
  --header-height: 64px;
  --max-width: 1320px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);

  --gradient-primary: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
  --gradient-accent: linear-gradient(135deg, #0ea5e9 0%, #1d4ed8 100%);

  --transition: 150ms ease;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: 1.55;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--weight-heading);
  line-height: 1.25;
  color: var(--secondary);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }

ul, ol { list-style-position: inside; }

small { font-size: 0.8125rem; }

code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  background: var(--surface-alt);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-size: 0.875em;
  color: var(--primary-dark);
}

/* ============================================================
   App shell — sidebar + header layout
   ============================================================ */
.app {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--secondary);
  background: linear-gradient(180deg, #0f172a 0%, #131f38 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1.25rem;
  height: var(--header-height);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.2rem;
  color: #fff;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.sidebar-brand .logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--gradient-accent);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.sidebar-nav {
  padding: 0.75rem 0.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  font-weight: 700;
  padding: 1rem 0.75rem 0.4rem;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  font-weight: 500;
  font-size: 0.92rem;
  transition: background var(--transition), color var(--transition);
}
.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.sidebar-nav a.active {
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
}
.sidebar-nav a .icon { width: 18px; text-align: center; opacity: 0.9; }

/* Main column */
.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  z-index: 40;
}
.topbar-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--secondary);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.content {
  padding: 1.75rem;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

/* ============================================================
   Top nav (horizontal, alternative to sidebar)
   ============================================================ */
.nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: var(--header-height);
  box-shadow: var(--shadow-sm);
}
.nav-brand {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary-dark);
  margin-right: 1rem;
}
.nav a {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--surface-alt); color: var(--primary); }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav .nav-right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

/* ============================================================
   Page header
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--secondary);
}
.page-title .subtitle,
.page-subtitle {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 0.25rem;
  letter-spacing: 0;
}
.page-header-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.5rem;
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.card.card-flat:hover { transform: none; box-shadow: var(--shadow); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: -1.35rem -1.5rem 1.25rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--secondary);
}
.card-body { font-size: 0.95rem; }
.card-footer {
  margin: 1.25rem -1.5rem -1.35rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1.1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.3rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--gradient-primary);
}
.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat-value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 800;
  color: var(--secondary);
  line-height: 1.1;
  margin-top: 0.35rem;
}
.stat-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.25rem; }

/* Generic grid */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.65rem 1.15rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--transition), box-shadow var(--transition),
              background var(--transition), border-color var(--transition), color var(--transition);
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.28);
}
.btn-primary:hover {
  box-shadow: 0 6px 18px rgba(29, 78, 216, 0.42);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--secondary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--surface-alt);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn-accent {
  background: var(--gradient-accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}
.btn-accent:hover { box-shadow: 0 6px 18px rgba(14, 165, 233, 0.45); color: #fff; }

.btn-danger {
  background: var(--error);
  color: #fff;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}
.btn-danger:hover { background: #b91c1c; color: #fff; box-shadow: 0 6px 18px rgba(220, 38, 38, 0.4); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--primary); }

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
  gap: 0.35rem;
}
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1rem; }
.btn-block { display: flex; width: 100%; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 1.15rem; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.15rem;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--secondary);
  margin-bottom: 0.4rem;
}
.form-label .req { color: var(--error); margin-left: 2px; }
.form-hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem; }

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
.form-input::placeholder,
.form-textarea::placeholder { color: #94a3b8; }
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}
.form-textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.4rem;
}
.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled { background: var(--surface-alt); color: var(--muted); cursor: not-allowed; }

.form-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* Auth / login card */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--gradient-primary);
}
.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
}
.auth-card .auth-brand {
  text-align: center;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--primary-dark);
  margin-bottom: 0.35rem;
}
.auth-card .auth-sub { text-align: center; color: var(--muted); margin-bottom: 1.75rem; font-size: 0.9rem; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  border-left-width: 4px;
  font-size: 0.9rem;
  margin-bottom: 1.1rem;
}
.alert strong { font-weight: 700; }
.alert-success {
  background: var(--success-soft);
  border-color: var(--success);
  color: #14532d;
}
.alert-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: #78350f;
}
.alert-error {
  background: var(--error-soft);
  border-color: var(--error);
  color: #7f1d1d;
}
.alert-info {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #075985;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.table-wrap .table { border: 0; box-shadow: none; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface);
}
.table thead th {
  background: var(--surface-alt);
  text-align: left;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.8rem 1rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:nth-child(even) { background: var(--surface-alt); }
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td .muted { color: var(--muted); font-size: 0.84rem; }
.table-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }

/* Qualify (discovery) table — one primary action (Advance to Decide) plus a
   compact AI Summary icon button and an overflow "⋯" menu for Save/Dismiss,
   all on one compact row that fits without wrapping. */

/* Let this page's table/card use more of the page width, and use a fixed
   column layout so long titles wrap into a constrained column instead of
   stretching row height and squeezing the other columns. */
.content:has(.qualify-table) {
  max-width: 1600px;
}
.qualify-table {
  table-layout: fixed;
}
.qualify-table th:nth-child(1),
.qualify-table td:nth-child(1) { width: 2.4rem; }
.qualify-table th:nth-child(2),
.qualify-table td:nth-child(2) { width: 30%; }
.qualify-table td:nth-child(2) a {
  overflow-wrap: break-word;
  word-break: break-word;
}
.qualify-table th:nth-child(3),
.qualify-table td:nth-child(3) { width: 12%; overflow-wrap: break-word; }
.qualify-table th:nth-child(4),
.qualify-table td:nth-child(4) { width: 9%; overflow-wrap: break-word; }
.qualify-table th:nth-child(5),
.qualify-table td:nth-child(5) { width: 9%; }
.qualify-table th:nth-child(6),
.qualify-table td:nth-child(6) { width: 13%; }
.qualify-table th:nth-child(7),
.qualify-table td:nth-child(7) { width: 8%; }
.qualify-table th:last-child,
.qualify-table td:last-child {
  width: 190px;
}
/* Actions are laid out via the inner .table-actions div (not the <td>
   itself) so the cell keeps its normal table-cell box — applying flex
   directly to a <td> used to break it out of table layout and left a
   stray border/divider artifact under the buttons on some rows. */
.qualify-table td:last-child {
  vertical-align: middle;
}
.qualify-table .table-actions {
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-wrap: nowrap;
  position: relative;
}
.qualify-table .table-actions form {
  margin: 0;
}
.qualify-table .table-actions .btn {
  white-space: nowrap;
}
.qualify-table .table-actions .btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

/* Qualify fold-out ▶ toggle — only rendered visible on rows with an
   already-generated AI summary; clicking expands the inline .ai-fold-row
   below it showing the stored summary text. */
.fold-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  margin-right: 0.3rem;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}
.fold-toggle:hover {
  background: var(--surface-alt);
  color: var(--text);
}
.ai-fold-row td {
  background: var(--surface-alt);
  border-top: 0;
}

/* Compact square icon buttons (AI Summary, overflow trigger) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1;
  flex: 0 0 auto;
}

/* Overflow "⋯" menu holding secondary actions (Save / Dismiss) */
.overflow-menu {
  position: relative;
  display: inline-flex;
}
.overflow-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  z-index: 20;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 0.3rem;
  text-align: left;
}
.overflow-menu.open .overflow-dropdown {
  display: block;
}
.overflow-dropdown form {
  margin: 0;
}
.overflow-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  background: none;
  border: 0;
  border-radius: 6px;
  font-size: 0.84rem;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.overflow-item:hover {
  background: var(--surface-alt);
}

/* Decide — bulk-select table (checkbox, title, buyer, CPV, dates, value,
   relevance score carried over from Qualify, status, minimal actions). */
.content:has(.decide-table) {
  max-width: 1600px;
}
.decide-table {
  table-layout: fixed;
}
.decide-table th:nth-child(1),
.decide-table td:nth-child(1) { width: 2.4rem; }
.decide-table th:nth-child(2),
.decide-table td:nth-child(2) { width: 22%; }
.decide-table td:nth-child(2) a {
  overflow-wrap: break-word;
  word-break: break-word;
}
.decide-table th:nth-child(3),
.decide-table td:nth-child(3) { width: 13%; overflow-wrap: break-word; }
.decide-table th:nth-child(4),
.decide-table td:nth-child(4) { width: 8%; overflow-wrap: break-word; }
.decide-table th:nth-child(5),
.decide-table td:nth-child(5) { width: 9%; }
.decide-table th:nth-child(6),
.decide-table td:nth-child(6) { width: 9%; }
.decide-table th:nth-child(7),
.decide-table td:nth-child(7) { width: 9%; }
.decide-table th:nth-child(8),
.decide-table td:nth-child(8) { width: 12%; }
.decide-table th:nth-child(9),
.decide-table td:nth-child(9) { width: 8%; }
.decide-table th:last-child,
.decide-table td:last-child {
  width: 150px;
  vertical-align: middle;
}
.decide-table .table-actions {
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-wrap: nowrap;
}
.decide-table .table-actions form {
  margin: 0;
}
.decide-table .table-actions .btn {
  white-space: nowrap;
}

/* ============================================================
   Badges / pills
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.badge-neutral { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-accent  { background: var(--accent-soft); color: #075985; }
.badge-success { background: var(--success-soft); color: #14532d; }
.badge-warning { background: var(--warning-soft); color: #78350f; }
.badge-error,
.badge-danger  { background: var(--error-soft); color: #7f1d1d; }
.badge-info    { background: var(--accent-soft); color: #075985; }
.badge.badge-plain::before { display: none; }

/* Tender stage badge variants (map via stage_badge_class) */
.badge-discovered       { background: #e2e8f0; color: #475569; }
.badge-evaluating       { background: var(--accent-soft); color: #075985; }
.badge-go_no_go_pending { background: var(--warning-soft); color: #78350f; }
.badge-in_preparation   { background: var(--primary-soft); color: var(--primary-dark); }
.badge-under_review     { background: #ede9fe; color: #5b21b6; }
.badge-submitted        { background: #cffafe; color: #155e75; }
.badge-awaiting_result  { background: #fef3c7; color: #854d0e; }
.badge-won              { background: var(--success-soft); color: #14532d; }
.badge-lost             { background: var(--error-soft); color: #7f1d1d; }
.badge-withdrawn        { background: #f1f5f9; color: #64748b; }

/* Role badges */
.badge-role-admin       { background: #ede9fe; color: #5b21b6; }
.badge-role-bid_manager { background: var(--primary-soft); color: var(--primary-dark); }
.badge-role-bid_writer  { background: var(--accent-soft); color: #075985; }
.badge-role-reviewer    { background: var(--warning-soft); color: #78350f; }

/* ============================================================
   Progress bars (relevance / probability / quality scores)
   ============================================================ */
.progress {
  position: relative;
  height: 8px;
  background: #e2e8f0;
  border-radius: var(--radius-pill);
  overflow: hidden;
  width: 100%;
  min-width: 80px;
}
.progress-bar {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--gradient-primary);
  transition: width var(--transition);
}
.progress-bar.is-low    { background: linear-gradient(90deg, #f87171, #dc2626); }
.progress-bar.is-medium { background: linear-gradient(90deg, #fbbf24, #d97706); }
.progress-bar.is-high   { background: linear-gradient(90deg, #4ade80, #16a34a); }
.score-cell { display: flex; align-items: center; gap: 0.6rem; min-width: 130px; }
.score-cell .score-num { font-weight: 700; font-size: 0.85rem; min-width: 32px; text-align: right; }

/* Portfolio Fit card (Requirements Matrix): tightened padding/spacing so the
   card takes noticeably less vertical space while keeping both progress
   bars, scores, badges and labels legible. */
.portfolio-fit-card { padding: 0.75rem 1.25rem; }
.portfolio-fit-card .card-header {
  margin: -0.75rem -1.25rem 0.6rem;
  padding: 0.55rem 1.25rem;
}
.portfolio-fit-card .card-title { font-size: 0.92rem; }
.portfolio-fit-card .score-dual { gap: 1.5rem; }
.portfolio-fit-card .score-dual .score-col { gap: 0.15rem; }

/* Two-column "Human reviewed" + "AI estimate" bars shown side by side in the
   folded requirement row (once a reviewed score exists) and in the top
   Portfolio Fit summary card. */
.score-dual { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: nowrap; }
.score-dual .score-col { display: flex; flex-direction: column; gap: 0.2rem; flex: 1 1 0; min-width: 0; width: 50%; }
.score-dual .score-col .score-cell { min-width: 0; width: 100%; }
.score-col-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted, #64748b);
}

/* ============================================================
   Kanban board
   ============================================================ */
.kanban {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  align-items: flex-start;
}
.kanban-col {
  flex: 0 0 290px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
}
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--secondary);
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  border-radius: var(--radius) var(--radius) 0 0;
}
.kanban-col-count {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
  font-weight: 700;
}
.kanban-col-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 0.85rem;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}
.kanban-card-title { font-weight: 700; font-size: 0.88rem; color: var(--secondary); margin-bottom: 0.3rem; }
.kanban-card-meta { font-size: 0.78rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--muted); line-height: 1;
}
.modal-close:hover { color: var(--error); }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.6rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  background: var(--surface-alt);
}

/* ============================================================
   Utilities
   ============================================================ */
.muted { color: var(--muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.78rem; }
.fw-bold { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.divider { height: 1px; background: var(--border); border: 0; margin: 1.25rem 0; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.toolbar .form-input,
.toolbar .form-select { width: auto; min-width: 160px; }
.toolbar .spacer { margin-left: auto; }

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; opacity: 0.4; margin-bottom: 0.75rem; }
.empty-state h3 { color: var(--secondary); margin-bottom: 0.4rem; }

.flash-stack { margin-bottom: 1.25rem; }

/* AI accent panel */
.ai-panel {
  border: 1px solid var(--accent);
  background: linear-gradient(135deg, #f0f9ff 0%, #ffffff 100%);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.ai-panel .ai-tag {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: #075985; background: var(--accent-soft);
  padding: 0.25rem 0.6rem; border-radius: var(--radius-pill);
  margin-bottom: 0.6rem;
}

/* ============================================================
   Responsive — 768px breakpoint
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .content { padding: 1.1rem; }
  .topbar { padding: 0 1rem; }

  .menu-toggle { display: inline-flex; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-title { font-size: 1.35rem; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .form-row { grid-template-columns: 1fr; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .form-input,
  .toolbar .form-select { width: 100%; }
  .toolbar .spacer { margin-left: 0; }

  /* Tables become horizontally scrollable */
  .table-wrap { overflow-x: auto; }
  .table { min-width: 640px; }

  .kanban-col { flex-basis: 82vw; }

  .modal { max-width: 100%; }
  .auth-card { padding: 1.75rem 1.35rem; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .user-name { display: none; }
}

/* ============================================================
   Dashboard — Tender Flow bar + Data Source cards
   ============================================================ */
.flow-bar {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 0.4rem;
  row-gap: 1rem;
}

.flow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  flex: 1 1 120px;
  min-width: 120px;
  padding: 0.85rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.flow-step:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  color: var(--text);
}
.flow-step.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.flow-step.is-disabled:hover { transform: none; box-shadow: none; border-color: var(--border); }
.flow-step-end {
  background: var(--primary-soft);
  border-color: var(--primary-soft);
}
.flow-step-icon { font-size: 1.3rem; line-height: 1; }
.flow-step-label { font-weight: 700; font-size: 0.85rem; margin-top: 0.15rem; }
.flow-step-count { font-size: 1.05rem; font-weight: 800; color: var(--primary-dark); }
.flow-step-value { font-size: 0.72rem; color: var(--muted); }

.flow-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border-strong);
  font-weight: 700;
  font-size: 1.1rem;
  flex: 0 0 auto;
  align-self: center;
}
.flow-arrow:last-of-type { display: none; }
.flow-arrow-slash { color: var(--muted); }

.grid-4 { grid-template-columns: repeat(4, 1fr); }

.data-source-card {
  display: block;
  text-decoration: none;
  color: inherit;
  text-align: center;
}
.data-source-card.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.data-source-card .data-source-icon { font-size: 1.8rem; margin-bottom: 0.4rem; }

@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .flow-arrow { display: none; }
}

.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  color: var(--secondary);
  font-size: 1.1rem;
  line-height: 1;
  margin-right: 0.75rem;
}

/* ---- Document upload mode toggle (single file vs ZIP archive) ---- */
.upload-mode-toggle {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.upload-mode-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
}
.upload-mode-option input { cursor: pointer; }

/* ---- Uploaded documents tree view ---- */
.doc-tree { display: flex; flex-direction: column; gap: 0.35rem; }
.doc-tree-folder {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 0.15rem 0.6rem;
}
.doc-tree-summary {
  cursor: pointer;
  list-style: none;
  padding: 0.5rem 0.1rem;
  font-weight: 600;
  color: var(--secondary);
  user-select: none;
}
.doc-tree-summary::-webkit-details-marker { display: none; }
.doc-tree-children {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 0 0.5rem 1.1rem;
  border-left: 2px solid var(--border);
  margin-left: 0.3rem;
}
.doc-tree-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.doc-tree-file-main { flex: 1 1 260px; min-width: 0; }
.doc-tree-file-status { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.doc-tree-file-actions { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }

/* ---- Requirements Matrix: document tree + main panel layout ---- */
/* Let this page's content fill the full remaining viewport width next to the
   fixed sidebar instead of being capped/centered like the default .content. */
.content:has(.matrix-layout) {
  max-width: none;
  width: auto;
  margin: 0;
  height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Sticky top section: tender info, actions, alerts/portfolio card and the
   Requirements/Q&A toggle. It sits above the scrollable body below and never
   scrolls out of view, since .content itself no longer scrolls as a whole. */
.matrix-sticky-header { flex: 0 0 auto; }
/* Everything below the sticky header (the requirements tab's tree + main
   panel, or the Q&A tab) shares the remaining height. */
.matrix-scroll-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#matrix-qa-tab { height: 100%; overflow-y: auto; }
/* Requirements tab wrapper: the filter bar sits on top (auto height), full
   width, above both the Documents tree panel and the requirements list; the
   tree+main-panel row (.matrix-layout) fills the remaining height below it. */
#matrix-requirements-tab {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.matrix-layout {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}
.matrix-tree-panel {
  flex: 0 0 auto;
  width: 300px;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  margin-right: 0.65rem;
}
/* Draggable resize handle between the tree panel and the main panel. Width is
   controlled purely by JS (mousedown/mousemove/mouseup) writing an inline
   style + localStorage value onto .matrix-tree-panel; this just supplies the
   grabbable/visual affordance. */
.matrix-resize-handle {
  flex: 0 0 10px;
  width: 10px;
  align-self: stretch;
  cursor: col-resize;
  position: relative;
}
.matrix-resize-handle::before {
  content: '';
  position: absolute;
  top: 6%;
  bottom: 6%;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  background: var(--border);
  border-radius: 3px;
  transition: background 0.15s;
}
.matrix-resize-handle:hover::before,
.matrix-resize-handle.is-dragging::before { background: var(--primary); }
.matrix-main-panel {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  padding-left: 0.65rem;
}
@media (max-width: 1100px) {
  .content:has(.matrix-layout) { height: auto; overflow: visible; }
  .matrix-scroll-body { overflow: visible; }
  #matrix-qa-tab { height: auto; overflow-y: visible; }
  .matrix-layout { flex-direction: column; height: auto; }
  .matrix-tree-panel {
    width: 100% !important;
    height: auto;
    max-height: 340px;
    margin-right: 0;
    margin-bottom: 0.75rem;
  }
  .matrix-resize-handle { display: none; }
  .matrix-main-panel { height: auto; padding-left: 0; overflow-y: visible; }
}

/* Selectable tree nodes (Requirements Matrix) reuse the Documents page's
   doc-tree markup but as clickable buttons instead of static rows. */
button.doc-tree-file-select {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
button.doc-tree-file-select:hover { border-color: var(--primary); }
button.doc-tree-file-select.active {
  border-color: var(--primary);
  background: var(--surface-alt);
  box-shadow: inset 0 0 0 1px var(--primary);
}

/* Compact tree styling scoped to the Matrix tree panel only (the Documents/
   upload page keeps its roomier card-style tree — this is a denser variant
   for the narrower sidebar-like panel here). */
.matrix-tree-panel .doc-tree { gap: 0.15rem; }
.matrix-tree-panel .doc-tree-folder { padding: 0.1rem 0.4rem; }
.matrix-tree-panel .doc-tree-summary {
  padding: 0.3rem 0.1rem;
  font-size: 0.8rem;
}
.matrix-tree-panel .doc-tree-children {
  gap: 0.15rem;
  padding: 0 0 0.3rem 0.6rem;
  margin-left: 0.15rem;
  border-left: 1px solid var(--border);
}
.matrix-tree-panel .doc-tree-file {
  padding: 0.32rem 0.5rem;
  gap: 0.4rem;
}
.matrix-tree-panel .doc-tree-file-main {
  font-size: 0.8rem;
  flex-basis: 160px;
  line-height: 1.3;
}
.matrix-tree-panel .doc-tree-file-status .badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
}
.matrix-tree-panel #doc-tree-all .doc-tree-file-main { font-size: 0.83rem; }

/* Slightly denser type-safe text sizing for the Matrix main panel (table
   content, headers, type-filter chip labels) to fit more comfortably. */
.matrix-main-panel .table { font-size: 0.83rem; }
.matrix-main-panel .table thead th {
  font-size: 0.68rem;
  padding: 0.6rem 0.85rem;
}
.matrix-main-panel .table tbody td { padding: 0.6rem 0.85rem; }
.matrix-main-panel .table td .muted { font-size: 0.78rem; }
.matrix-main-panel .card-title { font-size: 0.92rem; }
#matrix-type-chips .badge {
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
}
.matrix-main-panel .matrix-type-count { font-size: 0.78rem; }

/* Collapsed-by-default requirement rows: the chevron toggle button that
   expands/collapses the sibling .matrix-req-detail row. */
.matrix-row-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 0.35rem 0 0;
  line-height: 1;
  vertical-align: middle;
}
.matrix-row-toggle:hover { color: var(--primary); }
.matrix-req-detail > td { background: var(--surface-alt); }
