:root {
  --bg: #f2f4ef;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #4b5563;
  --accent: #c27c00;
  --line: #d1d5db;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top right, #fff5dd, var(--bg) 35%);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

h1 { margin: 0; }
.sub { margin-top: 0.25rem; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.6rem;
}

.stage {
  display: inline-block;
  border: 1px solid #f0c572;
  background: #fff3d8;
  color: #8a5a00;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* ── Page header + nav ─────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.nav-links {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-links a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.88rem;
  transition: background 0.15s;
}

.nav-links a:hover { background: #f5f5f5; }
.nav-links a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Stats row ─────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.stat-box {
  flex: 1;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Filter bar ────────────────────────────────────────────── */
.filter-bar { padding: 0.9rem 1rem; }

.filter-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 140px;
}

.filter-group label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-group input,
.filter-group select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1.1rem;
  font-size: 0.9rem;
  cursor: pointer;
  align-self: flex-end;
  white-space: nowrap;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-ghost {
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  align-self: flex-end;
  white-space: nowrap;
}
.btn-ghost:hover { background: #f5f5f5; }

.btn-enrich {
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-enrich:hover { background: #fff8ec; }

/* ── Table tweaks ──────────────────────────────────────────── */
.bid-row { cursor: pointer; }
.bid-row:hover td { background: #fffbf3; }

.mono { font-family: monospace; font-size: 0.82rem; }
.project-name { max-width: 260px; font-weight: 500; }
.contractor-name { max-width: 180px; font-size: 0.88rem; }
.muted-cell { color: var(--muted); font-size: 0.87rem; max-width: 180px; }
.muted-text { color: var(--line); font-size: 0.85rem; }
.amount { text-align: right; font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* ── Tags ──────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.tag-type {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: #3730a3;
}

/* ── Score bar ─────────────────────────────────────────────── */
.score-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.score-bar {
  flex: 1;
  height: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}

.score-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s;
}

.score-high { background: #16a34a; }
.score-mid  { background: #d97706; }
.score-low  { background: #dc2626; }

.score-num {
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

/* ── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0 0.4rem;
}

.link-small {
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: underline;
}

/* ── AI document picker ────────────────────────────────────── */
.picker-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  font-size: 0.83rem;
}

.picker-check-all {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

.picker-hint { color: var(--muted); }

.doc-picker-list {
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 340px;
  overflow-y: auto;
}

.doc-picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}

.doc-picker-row:last-child { border-bottom: none; }
.doc-picker-row:hover { background: #fffbf3; }

.doc-picker-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.doc-picker-info {
  flex: 1;
  min-width: 0;
}

.doc-picker-project {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}

.doc-picker-meta {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ── Document download links ───────────────────────────────── */
.doc-links {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.doc-link {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  padding: 0.1rem 0.35rem;
  border: 1px solid #f0c572;
  border-radius: 5px;
  background: #fff9ec;
}

.doc-link:hover { background: #fff3d8; }

/* ── Pipeline stepper ─────────────────────────────────────── */
.pipeline-card h2 { margin-top: 0; margin-bottom: 0; }

.pipeline-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.pipeline-sub { font-size: 0.83rem; color: var(--muted); }

.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  display: flex;
  gap: 1rem;
}

.step-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f3f4f6;
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.step-num.done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.step-line {
  width: 2px;
  flex: 1;
  background: var(--line);
  margin: 4px 0;
  min-height: 16px;
}

.step-body {
  padding-bottom: 1.5rem;
  flex: 1;
  padding-top: 4px;
}

.step-last .step-body { padding-bottom: 0.25rem; }

.step-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.step-desc {
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.step-stat {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.step-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.inline-field input {
  width: 60px;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.88rem;
}

.step-status {
  margin-top: 0.5rem;
  font-size: 0.83rem;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  display: none;
}
.step-status:not(:empty) { display: block; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-header h3 { margin: 0; font-size: 1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.modal-footer-hint { font-size: 0.82rem; color: var(--muted); margin-left: auto; }

/* ── Admin panel ───────────────────────────────────────────── */
.admin-panel h2 { margin-top: 0; }

.admin-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.admin-action {
  flex: 1;
  min-width: 260px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-action-header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.admin-icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-top: 2px;
}

.admin-action-header strong { display: block; margin-bottom: 0.15rem; }
.admin-action-header p { margin: 0; font-size: 0.84rem; color: var(--muted); }

.admin-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.admin-controls label {
  font-size: 0.82rem;
  color: var(--muted);
}

.admin-controls input[type="number"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.9rem;
}

.admin-status {
  font-size: 0.84rem;
  border-radius: 7px;
  padding: 0.4rem 0.7rem;
  min-height: 1.6rem;
}

.status-running { background: #fef9c3; color: #854d0e; }
.status-ok      { background: #dcfce7; color: #166534; }
.status-err     { background: #fee2e2; color: #991b1b; }
