:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-text: #16181d;
  --color-text-muted: #6b7280;
  --color-text-faint: #9ca3af;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-bg: #eff6ff;

  --color-drafting-bg: #fef3c7;
  --color-drafting-text: #92400e;
  --color-review-bg: #dbeafe;
  --color-review-text: #1e40af;
  --color-submitted-bg: #dcfce7;
  --color-submitted-text: #166534;
  --color-failed-bg: #fee2e2;
  --color-failed-text: #991b1b;

  --radius-sm: 6px;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.08);
  --sidebar-width: 232px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.55;
}

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

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0 0.75rem 1.5rem;
  color: var(--color-text);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }

.sidebar-nav a {
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover { background: var(--color-bg); color: var(--color-text); }

.sidebar-nav a.active {
  background: var(--color-primary-bg);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
}

.sidebar-footer { padding-top: 1rem; border-top: 1px solid var(--color-border); }

.sidebar-footer form button {
  width: 100%;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  font-size: 0.88rem;
  cursor: pointer;
}
.sidebar-footer form button:hover { background: var(--color-bg); color: var(--color-text); }

.main {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 4rem;
  max-width: 1400px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.page-header h1 { margin: 0; font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--color-text-muted); margin-top: 0.3rem; font-size: 0.92rem; }

/* ---------- Cards & surfaces ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.card + .card { margin-top: 1.25rem; }

.empty-state {
  color: var(--color-text-muted);
  padding: 3rem 1.5rem;
  text-align: center;
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius);
}

/* ---------- Tables ---------- */

table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.75rem 1rem; }
th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--color-border);
}
tbody tr { border-bottom: 1px solid var(--color-border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--color-bg); }
.table-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto; /* scroll wide tables instead of silently clipping columns */
}
.table-card table { margin: 0; }
.table-card table th:first-child, .table-card table td:first-child { max-width: 420px; }

/* ---------- Status pills ---------- */

.status {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.status-Drafting { background: var(--color-drafting-bg); color: var(--color-drafting-text); }
.status-Under-Review { background: var(--color-review-bg); color: var(--color-review-text); }
.status-Submitted { background: var(--color-submitted-bg); color: var(--color-submitted-text); }
.status-Running { background: var(--color-review-bg); color: var(--color-review-text); }
.status-Completed { background: var(--color-submitted-bg); color: var(--color-submitted-text); }
.status-Failed { background: var(--color-failed-bg); color: var(--color-failed-text); }

/* ---------- Forms ---------- */

label { font-weight: 600; font-size: 0.85rem; color: var(--color-text); display: block; margin-bottom: 0.35rem; }

input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.field { margin-bottom: 1.1rem; max-width: 520px; }
.field-hint { color: var(--color-text-faint); font-size: 0.8rem; font-weight: 400; margin-top: 0.2rem; }

/* ---------- Buttons ---------- */

button, .btn {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover, .btn:hover { background: var(--color-primary-hover); text-decoration: none; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-bg); }

form.inline { display: inline; }

/* ---------- Checkbox pills (source picker) ---------- */

.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.75rem 0 1.25rem; }
.checkbox-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--color-surface);
}
.checkbox-pill input { margin: 0; }

/* ---------- Alerts ---------- */

.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-size: 0.9rem; }
.alert-success { background: var(--color-submitted-bg); color: var(--color-submitted-text); }
.alert-error { background: var(--color-failed-bg); color: var(--color-failed-text); }
.alert-info { background: var(--color-drafting-bg); color: var(--color-drafting-text); }
.alert-warning { background: var(--color-drafting-bg); color: var(--color-drafting-text); border-left: 3px solid var(--color-drafting-text); }

/* ---------- Meta grid (tender detail) ---------- */

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.meta-grid dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); font-weight: 600; margin-bottom: 0.2rem; }
.meta-grid dd { margin: 0 0 0.9rem; font-size: 0.95rem; }

/* ---------- Draft section editor ---------- */

.section-block { margin-bottom: 1.5rem; }
.section-block h3 { font-size: 1rem; margin: 0 0 0.6rem; }

/* Section editors are collapsible so a long draft stays navigable, and the
   textareas grow to fit their content (see the autogrow script in base.html)
   -- a fixed-height box for LLM-generated prose means scrolling inside a
   scrollable page, which is the worst of both. */
.section-editor > summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  list-style: none;
  padding: 0.15rem 0;
}
.section-editor > summary::-webkit-details-marker { display: none; }
.section-editor > summary::before {
  content: "\25be";
  color: var(--color-text-faint);
  font-size: 0.85rem;
  width: 0.8rem;
}
.section-editor:not([open]) > summary::before { content: "\25b8"; }
.section-flag { color: #9a6700; font-size: 0.9rem; }

.section-block textarea {
  font-size: 0.9rem;
  line-height: 1.5;
  /* Height is driven by content, so no inner scrollbar and no drag handle. */
  resize: none;
  overflow: hidden;
  min-height: 4rem;
  margin-top: 0.6rem;
}
.section-block textarea[readonly] { background: var(--color-surface-muted, #f6f7f9); }
.save-indicator { font-size: 0.8rem; color: var(--color-text-faint); margin-left: 0.5rem; }

/* ---------- Run log ---------- */

.run-log {
  background: #14161a;
  color: #d4d8de;
  padding: 1.25rem;
  border-radius: var(--radius);
  max-height: 65vh;
  overflow-y: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { font-size: 1.3rem; margin: 0 0 1.5rem; text-align: center; }
.status-Paused { background: var(--color-drafting-bg); color: var(--color-drafting-text); }
.status-Stopped { background: var(--color-drafting-bg); color: var(--color-drafting-text); }

/* Language marker on non-English tenders in the list -- the title shown is
   the English translation, so this says where it came from. */
.lang-tag {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.35rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-bg);
  color: var(--color-primary);
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}


/* A tender whose submission deadline has passed can't be bid on -- worth
   showing plainly rather than letting it read as live work. */
.deadline-expired { color: var(--color-failed-text, #cf222e); font-size: 0.85rem; }
.status-Archived { background: var(--color-border); color: var(--color-text-muted); }

/* Destructive actions (redo discards tenders) read as destructive. */
.btn-danger, button.btn-danger {
  background: var(--color-failed-text, #cf222e);
  border-color: var(--color-failed-text, #cf222e);
  color: #fff;
}
.btn-danger:hover, button.btn-danger:hover { filter: brightness(0.92); }
