:root {
  --fg: #1a1a1a;
  --muted: #666;
  --bg: #fafaf7;
  --accent: #1f5c4a;
  --border: #e3e3df;
  --error: #b00020;
  --max: 720px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
}

.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  background: #fff;
}

.site-header .brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
}

.site-header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.site-header-email {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-header-logout { margin: 0; }

.icon-button {
  margin: 0;
  padding: 0.35rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-button:hover {
  color: var(--fg);
  border-color: var(--border);
  background: #f5f5f0;
  filter: none;
}
.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.container {
  max-width: var(--max);
  margin: 2rem auto;
  padding: 0 1.25rem;
}

.site-footer {
  max-width: var(--max);
  margin: 3rem auto 2rem;
  padding: 1rem 1.25rem 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

/* Admin shell: sidebar nav + main content. */
body.admin-shell .site-footer { max-width: none; margin: 3rem 1.5rem 2rem; }
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  align-items: start;
}
.admin-sidebar {
  position: sticky;
  top: 0;
  align-self: stretch;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: #fff;
  min-height: calc(100vh - 4rem);
}
.admin-sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.admin-sidebar nav a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.95rem;
}
.admin-sidebar nav a:hover { background: #f1f1ec; }
.admin-sidebar nav a.is-active {
  background: var(--accent);
  color: #fff;
}
.admin-main {
  padding: 1.5rem 2rem 0;
  max-width: 1000px;
  min-width: 0;
}

@media (max-width: 800px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: static;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
  }
  .admin-sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .admin-main { padding: 1.25rem 1.25rem 0; }
}

h1 { font-size: 1.7rem; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 0.75rem; }

a { color: var(--accent); }

p.meta, small { color: var(--muted); font-size: 0.9rem; }

.role-list { list-style: none; padding: 0; }
.role-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.role-list li small { display: block; margin-top: 0.15rem; }
.role-list li p { margin: 0.5rem 0 0; }

form label {
  display: block;
  margin: 1rem 0 0.5rem;
  font-weight: 500;
}
form label > input:not([type=checkbox]):not([type=radio]),
form label > textarea,
form label > select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  background: #fff;
}
form textarea { resize: vertical; min-height: 8rem; }
form label.checkbox {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-weight: 400;
}
form label.checkbox input { margin-top: 0.25rem; }

button, .button-link {
  display: inline-block;
  margin-top: 1.25rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button-link:hover { filter: brightness(1.1); }

.error {
  background: #fdecef;
  border: 1px solid #f5b7c0;
  color: var(--error);
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
}

.field-error {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--error);
}

.field-hint {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
}

form label.has-error {
  display: block;
  padding: 0.6rem 0.8rem;
  margin-left: -0.8rem;
  margin-right: -0.8rem;
  background: #fdecef;
  border: 1px solid #f5b7c0;
  border-radius: 4px;
}
form label.has-error > input,
form label.has-error > textarea {
  border-color: var(--error);
}
form label.checkbox.has-error {
  flex-wrap: wrap;
  background: #fdecef;
  border: 1px solid #f5b7c0;
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  margin-left: -0.8rem;
  margin-right: -0.8rem;
}
form label.checkbox.has-error .field-error {
  flex-basis: 100%;
  margin-top: 0.3rem;
}

.flash {
  background: #eaf5ee;
  border: 1px solid #bcdec7;
  color: #1f5c4a;
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
}

td form { margin: 0 0.25rem 0 0; }
td form button { margin-top: 0; padding: 0.25rem 0.6rem; font-size: 0.85rem; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 1rem 0; }
dl dt { color: var(--muted); }
dl dd { margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
th { background: #f1f1ec; font-weight: 600; }

.message-body { white-space: pre-wrap; }

.review-block { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.review-block h2 small { font-weight: 400; color: var(--muted); }

.stars-readonly { color: #d4a017; letter-spacing: 1px; }

.rating-summary { display: flex; gap: 0.6rem; align-items: baseline; }

.rating-list { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.rating-list li { padding: 0.3rem 0; display: flex; gap: 0.6rem; align-items: baseline; }

.rating-form { margin-top: 1.5rem; }
.rating-form select { width: auto; }

.comment-list { list-style: none; padding: 0; margin: 1rem 0; }
.comment { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment-meta { margin: 0; color: var(--muted); font-size: 0.9rem; }
.comment-body { margin: 0.4rem 0 0; white-space: pre-wrap; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  margin: 1rem 0 0.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.filter-bar label { margin: 0; font-size: 0.9rem; }
.filter-bar select,
.filter-bar input[type=search] { width: auto; min-width: 12rem; margin-top: 0.2rem; }
.filter-search { flex: 1; min-width: 14rem; }
.filter-search input[type=search] { width: 100%; }
.filter-actions { display: flex; gap: 0.5rem; align-items: center; }
.filter-actions button { margin-top: 0; }
.filter-reset { color: var(--muted); }

.result-count { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0; }
.empty-state { color: var(--muted); font-style: italic; padding: 1rem 0; }

.pagination {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.pagination .disabled { color: var(--muted); opacity: 0.6; }

.stage-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: #eef2ee;
  color: #1f5c4a;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid #cfdfd3;
}
.stage-pill.is-terminal {
  background: #f1ecec;
  color: #6b4040;
  border-color: #d8c4c4;
}

.stage-form { display: flex; gap: 0.6rem; align-items: end; }
.stage-form select { width: auto; }
.stage-form button { margin-top: 0; }

.stage-history { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.stage-history li { padding: 0.3rem 0; }
.stage-history small { color: var(--muted); margin-left: 0.4rem; }

.stages-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 1rem 0 0.5rem; }
.stages-row {
  display: grid;
  grid-template-columns: 1.75rem 1fr 4rem 4rem 8.5rem;
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.stages-row[draggable=true] { user-select: none; }
.stages-row.dragging { opacity: 0.4; }
.stages-head { background: #f1f1ec; font-size: 0.85rem; color: var(--muted); }
.stages-head > :nth-child(3),
.stages-head > :nth-child(4) { text-align: center; }
.stages-row .drag-handle {
  cursor: grab;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
  letter-spacing: -2px;
}
.stages-row .drag-handle:active { cursor: grabbing; }
.stages-row input[type=text] { margin: 0; padding: 0.35rem 0.5rem; }
.stages-row .terminal-cell { margin: 0; padding: 0; display: flex; justify-content: center; }
.stages-row .terminal-cell input { margin: 0; }
.stages-row .app-count { text-align: center; color: var(--muted); }
.stages-row .row-actions { display: flex; gap: 0.4rem; justify-content: end; align-items: center; }
.stages-row button { margin: 0; padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.stages-row button[disabled] { opacity: 0.5; cursor: not-allowed; }
.row-link-delete {
  font-size: 0.85rem;
  color: var(--error);
  text-decoration: none;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
}
.row-link-delete:hover { background: #fdecef; }

.gdpr-actions {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.gdpr-actions h2 small { font-weight: 400; color: var(--muted); }
.gdpr-actions p > a { margin-right: 0.5rem; }

.decline-form .radio-group label.radio { margin-bottom: 0.3rem; }
.decline-preview {
  margin: 0 0 0.75rem 1.6rem;
  font-size: 0.9rem;
}
.decline-preview summary { cursor: pointer; color: var(--muted); }
.decline-preview .decline-body {
  white-space: pre-wrap;
  margin: 0.5rem 0;
  padding: 0.6rem 0.8rem;
  background: #f9f9f5;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}

.email-log { list-style: none; padding: 0; margin: 0.5rem 0 1rem; }
.email-log li {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.email-log .email-kind {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: #eef2ee;
  color: #1f5c4a;
  border: 1px solid #cfdfd3;
  margin-right: 0.4rem;
}
.email-log .email-subject { margin-top: 0.2rem; color: var(--muted); }

tr.row-inactive { opacity: 0.55; }

.user-invite-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  margin: 0.5rem 0 1rem;
}
.user-invite-form label { margin: 0; }
.user-invite-form label.checkbox { padding-bottom: 0.55rem; }
.user-invite-form input[type=email],
.user-invite-form input[type=text] { width: auto; min-width: 14rem; }
.user-invite-form button { margin-top: 0; }

.users-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 1rem 0; }
.users-row {
  display: grid;
  grid-template-columns: 14rem 1fr 4rem 4rem 6rem 9rem;
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.users-head { background: #f1f1ec; font-size: 0.85rem; color: var(--muted); }
.users-head > :nth-child(3),
.users-head > :nth-child(4) { text-align: center; }
.users-row.is-inactive { opacity: 0.55; }
.users-row input[type=text] { margin: 0; padding: 0.3rem 0.5rem; width: 100%; }
.users-row .user-flag { display: flex; justify-content: center; }
.users-row .user-flag input { margin: 0; }
.users-row .user-last-login { color: var(--muted); font-size: 0.9rem; }
.users-row .row-actions { display: flex; gap: 0.4rem; justify-content: end; }
.users-row button { margin: 0; padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.users-row button[disabled] { opacity: 0.5; cursor: not-allowed; }

.stage-delete-form { margin-top: 1rem; }
.stage-delete-form .radio-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
  background: #fff;
}
.stage-delete-form .radio-group legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
}
.stage-delete-form .radio-group-danger { border-color: #f5b7c0; background: #fdecef; }
.stage-delete-form .radio-group-danger legend { color: var(--error); }
.stage-delete-form label.radio {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-weight: 400;
  margin: 0 0 0.5rem;
}
.stage-delete-form label.radio input { margin-top: 0.25rem; }
.stage-delete-form select { width: auto; min-width: 14rem; }
.stage-delete-form .form-actions { display: flex; gap: 0.75rem; align-items: center; }
.stage-delete-form .form-actions button { margin-top: 0; }

.reorder-status { min-height: 1.2em; color: var(--muted); font-size: 0.9rem; margin: 0 0 1.5rem; }
.reorder-status.error-text { color: var(--error); }

.stage-new-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; }
.stage-new-form label { margin: 0; }
.stage-new-form input[type=text] { width: auto; min-width: 10rem; }
.stage-new-form button { margin-top: 0; }

.view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin: 0.75rem 0 1rem;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.view-toggle-tab {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
}
.view-toggle-tab.is-active {
  background: var(--accent);
  color: #fff;
}
.view-toggle-kanban {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0;
  font-size: 0.9rem;
}
.view-toggle-kanban select { width: auto; margin-top: 0; padding: 0.25rem 0.4rem; }

/* Kanban board */
.kanban-wrap { /* normal-width header above the board */ }
.kanban-board {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  overflow-x: auto;
  margin: 1rem 0 1.5rem;
  padding: 0.25rem 0 1.5rem;
  scroll-padding: 1rem;
}
.kanban-col {
  flex: 0 0 280px;
  background: #f1f1ec;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 12rem);
}
.kanban-col.is-terminal { background: #f1ecec; border-color: #d8c4c4; }
.kanban-col-unassigned { background: #f5efe6; border-color: #e3d4b6; }
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.kanban-col-name { font-size: 0.95rem; }
.kanban-col-count {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}
.kanban-col-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  overflow-y: auto;
  min-height: 4rem;
}
.kanban-col.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
.kanban-card {
  display: block;
  padding: 0.55rem 0.7rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--fg);
  cursor: grab;
  font-size: 0.9rem;
  line-height: 1.35;
}
.kanban-card:hover { border-color: var(--accent); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card-name { font-weight: 600; margin-bottom: 0.15rem; }
.kanban-card-meta { color: var(--muted); font-size: 0.8rem; min-height: 0; }
.kanban-stars { color: #b07b00; }
.kanban-card-dates {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.role-team { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.role-team h2 { margin-top: 0; }
.role-team .capacity-key {
  list-style: disc;
  padding-left: 1.2rem;
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.assignments-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 1rem 0; }
.assignments-row {
  display: grid;
  grid-template-columns: 16rem 1fr 11rem 9rem;
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.assignments-head { background: #f1f1ec; font-size: 0.85rem; color: var(--muted); }
.assignments-row.is-inactive { opacity: 0.55; }
.assignments-row select { margin: 0; padding: 0.3rem 0.5rem; width: 100%; }
.assignments-row .row-actions { display: flex; gap: 0.4rem; justify-content: end; }
.assignments-row button { margin: 0; padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.assignment-add-form { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end; }
.assignment-add-form label { margin: 0; }
.assignment-add-form select { width: auto; min-width: 14rem; }
.assignment-add-form button { margin-top: 0; }
