:root {
  --brand: #E30A17;
  --brand-hover: #B8081A;
  --success: #16a34a;
  --danger: #6b7280;
  --warn: #d97706;
  --ink: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --surface: #ffffff;
  --bg: #f9fafb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}

.muted { color: var(--muted); }
.error { color: var(--brand); }

button { font: inherit; cursor: pointer; }
button.link { background: none; border: 0; color: var(--brand); padding: 0; }

button.primary {
  background: var(--brand);
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
button.primary:hover { background: var(--brand-hover); }
button.primary:disabled { opacity: 0.6; cursor: not-allowed; }
button.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  color: var(--ink);
}
button.ghost:hover { background: var(--bg); }

.btn-mini {
  display: inline-block;
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  margin-right: 4px;
}
.btn-mini:hover { background: var(--bg); }
.btn-mini.btn-danger { color: var(--brand); border-color: rgba(227,10,23,0.3); }
.btn-mini.btn-danger:hover { background: rgba(227,10,23,0.06); }

/* --- login --- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.04);
}
.login-card h1 { color: var(--brand); margin: 0 0 8px; }
.login-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 16px 0 6px;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.login-card input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-card button[type="submit"] {
  margin-top: 20px;
  width: 100%;
  padding: 11px 16px;
  background: var(--brand);
  color: white;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
}
.login-card button[type="submit"]:hover { background: var(--brand-hover); }
.login-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- topbar / dashboard chrome --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--brand); }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.back-link { color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--ink); }

.dashboard { max-width: 1100px; margin: 0 auto; padding: 24px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 16px;
}
.page-header h2 { margin: 0; }

/* --- create form --- */
.create-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
  background: var(--surface);
}
.create-panel[open] { padding: 16px; }
.create-panel summary { display: none; }
.form-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.form-row { display: flex; gap: 12px; margin-bottom: 8px; }
.form-row .form-field { flex: 1; }
input:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}
.form-field { margin-bottom: 12px; }
.form-field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.form-field input, .form-field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.form-field textarea { resize: vertical; min-height: 90px; font-family: ui-monospace, monospace; }
.form-field input:focus, .form-field textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* --- projects table --- */
.projects-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.projects-table th, .projects-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 14px;
}
.projects-table thead th { background: var(--bg); font-weight: 600; }
.projects-table tbody tr:last-child td { border-bottom: 0; }
.projects-table tr.archived td { opacity: 0.55; }
.projects-table .origins { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); max-width: 320px; overflow-wrap: break-word; }
.projects-table .actions { white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* --- snippet modal --- */
.snippet-modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.snippet-modal[hidden] { display: none; }
.snippet-modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  max-width: 720px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.snippet-modal-card h3 { margin: 0 0 6px; }
.snippet-modal-card pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
}

.modal-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 12px 0;
  background: var(--bg);
}
.modal-section[open] { background: var(--surface); }
.modal-section summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
  list-style: none;
  position: relative;
  padding-left: 22px;
}
.modal-section summary::-webkit-details-marker { display: none; }
.modal-section summary::before {
  content: '▸';
  position: absolute;
  left: 4px;
  transition: transform 120ms ease;
  color: var(--muted);
  font-size: 12px;
}
.modal-section[open] summary::before { transform: rotate(90deg); }
.modal-section .small {
  font-size: 13px;
  margin: 8px 0;
}
.modal-section pre {
  /* Long prompts can be 80+ lines — limit visible height with internal scroll
     so the modal itself doesn't grow past the viewport. */
  max-height: 320px;
  overflow-y: auto;
}
.modal-section .btn-mini {
  margin-top: 8px;
}

/* --- dashboard tabs --- */
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  background: transparent;
  border: 0;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 500;
  position: relative;
}
.tab.active { color: var(--ink); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; bottom: -1px;
  height: 2px;
  background: var(--brand);
}
.count {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  margin-left: 6px;
}
.tabs-spacer { flex: 1; }

.export-menu summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.export-menu summary::-webkit-details-marker { display: none; }
.export-menu[open] summary { background: var(--bg); }
.export-menu ul {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 4px 0 0;
  padding: 6px;
  list-style: none;
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
  min-width: 200px;
}
.export-menu li button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 6px;
  font: inherit;
}
.export-menu li button:hover { background: var(--bg); }

/* --- filters --- */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters select, .filters input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.filters input { min-width: 240px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.panel[hidden] { display: none; }

/* --- decision groups --- */
.decision-group {
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}
.decision-group:last-child { border-bottom: 0; }
.decision-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.decision-group-id {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--muted);
}
.decision-group-title { font-weight: 600; }
.summary-pill {
  display: inline-flex;
  gap: 6px;
  font-size: 12px;
}
.summary-pill > span {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.summary-pill .pill-approved { color: var(--success); border-color: rgba(22,163,74,0.3); background: rgba(22,163,74,0.06); }
.summary-pill .pill-rejected { color: var(--danger); }
.summary-pill .pill-change_requested { color: var(--brand); border-color: rgba(227,10,23,0.3); background: rgba(227,10,23,0.06); }

.decision-list { margin-top: 8px; padding-left: 0; list-style: none; }
.decision-list li {
  padding: 6px 0;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}
.decision-list li:first-child { border-top: 0; }
.decision-icon { display: inline-block; width: 1.4em; }

.decision-actions { margin-top: 10px; display: flex; gap: 6px; }

.status-select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.status-open { color: var(--ink); background: var(--bg); }
.status-processing { color: var(--warn); background: rgba(217,119,6,0.08); border-color: rgba(217,119,6,0.3); }
.status-done { color: var(--success); background: rgba(22,163,74,0.08); border-color: rgba(22,163,74,0.3); }
.status-wontfix { color: var(--muted); background: var(--bg); }

/* --- comments --- */
.comment-row {
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}
.comment-row:last-child { border-bottom: 0; }
.comment-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.comment-text { white-space: pre-wrap; }
.comment-coords { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }
.comment-target {
  font-size: 12px;
  color: var(--ink);
  margin-bottom: 4px;
  padding: 4px 8px;
  background: rgba(227, 10, 23, 0.04);
  border-left: 3px solid var(--brand);
  border-radius: 0 4px 4px 0;
}
.comment-target code {
  background: transparent;
  padding: 0;
  font-size: 12px;
  color: var(--brand);
}
.comment-target em { color: var(--muted); font-style: italic; }

/* --- per-row edit/delete actions --- */
.row-actions { display: inline-flex; gap: 4px; }
.icon-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.55;
  transition: opacity 120ms ease, background 120ms ease;
}
.icon-btn:hover { opacity: 1; background: var(--bg); }
.inline-edit {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}
.inline-edit:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.inline-edit-actions { margin-top: 6px; display: flex; gap: 6px; justify-content: flex-end; }
