:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e0db;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --warn: #e67700;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1e1e21;
    --text: #ececef;
    --muted: #9a9aa2;
    --border: #2e2e33;
    --accent: #ff6b2c;
  }
}

* { box-sizing: border-box; }
/* The hidden attribute always wins over display rules below. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.topbar select { padding: 0.3rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { font-size: 2rem; font-weight: 700; }
.muted { color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--border);
}
.badge.done { background: var(--ok); color: #fff; }
.badge.in_progress { background: var(--warn); color: #fff; }

button, .button {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  cursor: pointer;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
.button:hover { text-decoration: none; }
.form-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

input, select, textarea {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}
form p { margin: 0 0 0.75rem; }
form label { display: block; font-size: 0.85rem; color: var(--muted); }
.inline-form { display: inline; }
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

.messages { list-style: none; padding: 0; }
.messages li { padding: 0.6rem 1rem; border-radius: var(--radius); background: var(--surface); border-left: 4px solid var(--accent); margin-bottom: 0.5rem; }
.errorlist { color: #c92a2a; }

@media (max-width: 640px) {
  main { padding: 1rem; }
  .topbar { padding: 0.75rem 1rem; }
}

dialog { max-width: 460px; color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
details summary { cursor: pointer; margin: 0.25rem 0; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented a { padding: 0.35rem 0.9rem; color: var(--text); }
.segmented a:hover { text-decoration: none; background: var(--bg); }
.segmented a[aria-current="true"] { background: var(--accent); color: var(--accent-text); }

/* Board view: wider than the page so all status columns fit */
main:has(.board) { max-width: none; }
.board { display: flex; gap: 0.75rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.board-column {
  flex: 0 0 260px;
  background: var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  max-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
}
.board-column header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; padding: 0.25rem 0.25rem 0.5rem; }
.board-column header .badge { background: var(--surface); }
.board-column.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.board-cards { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; min-height: 3rem; }
.board-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  font-size: 0.9rem;
}
.board-card[draggable="true"] { cursor: grab; }
.board-card.dragging { opacity: 0.4; }
.board-card.saving { opacity: 0.6; }
.board-card-meta { display: flex; gap: 0.35rem; margin: 0.35rem 0; flex-wrap: wrap; }
.board-card-move { margin-top: 0.4rem; width: 100%; font-size: 0.8rem; }
@media (hover: hover) and (pointer: fine) {
  .board-card-move { display: none; }
}

/* People picker (typeahead) */
.typeahead { position: relative; max-width: 360px; }
.typeahead input { width: 100%; }
.typeahead-list {
  position: absolute; z-index: 10; left: 0; right: 0; margin: 2px 0 0; padding: 0.25rem 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgb(0 0 0 / 12%);
  max-height: 240px; overflow-y: auto;
}
.typeahead-list li { padding: 0.35rem 0.6rem; cursor: pointer; }
.typeahead-list li.active { background: var(--bg); }
.typeahead-list li.typeahead-new { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.35rem; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0.3rem 0.15rem 0.6rem; border-radius: 999px; background: var(--border); }
.chip button { border: 0; background: transparent; color: var(--muted); padding: 0 0.3rem; cursor: pointer; font-size: 1rem; line-height: 1; }
.chip-new { font-size: 0.7rem; color: var(--accent); text-transform: uppercase; }
.credit-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.credit-person { min-width: 220px; flex: 1; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.required::after { content: " *"; color: var(--accent); }

/* Follow-up priorities */
.badge.priority-1 { background: #c92a2a; color: #fff; }
.badge.priority-2 { background: var(--warn); color: #fff; }
.badge.priority-5 { opacity: 0.6; }

/* Destructive actions */
button.danger { background: #c92a2a; border-color: #c92a2a; color: #fff; }
button.danger:disabled { opacity: 0.5; cursor: not-allowed; }
.danger-zone { border-color: #c92a2a; margin-top: 1rem; }

/* Dropdown menus (user menu, filters) built on <details> */
details.menu { position: relative; }
details.menu > summary {
  list-style: none; cursor: pointer; padding: 0.35rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); white-space: nowrap;
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after { content: " ▾"; color: var(--muted); }
details.menu[open] > summary { border-color: var(--accent); }
.menu-panel {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 200px; padding: 0.35rem 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 14%); max-height: 320px; overflow-y: auto;
}
.user-menu .menu-panel { left: auto; right: 0; }
.menu-panel > a, .menu-panel .menu-item {
  display: block; width: 100%; padding: 0.45rem 0.9rem; color: var(--text); text-align: left;
  background: none; border: 0; border-radius: 0; font: inherit; cursor: pointer;
}
.menu-panel > a:hover, .menu-panel .menu-item:hover { background: var(--bg); text-decoration: none; }
.menu-panel form { margin: 0; }
.menu-panel label { display: flex; gap: 0.5rem; align-items: center; padding: 0.3rem 0.9rem; color: var(--text); font-size: 0.95rem; cursor: pointer; }
.menu-panel label:hover { background: var(--bg); }
.menu-actions { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.4rem 0.9rem 0.2rem; border-top: 1px solid var(--border); margin-top: 0.25rem; }
.filter-active > summary { border-color: var(--accent); color: var(--accent); }
.user-menu { margin-left: auto; }

/* Combobox (searchable dropdown, static/app/combobox.js) */
.combobox { position: relative; max-width: 480px; }
.combobox-input { width: 100%; padding-right: 2.2rem; }
.combobox-toggle {
  position: absolute; top: 0; right: 0; bottom: 0; width: 2.2rem; padding: 0;
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
}
.combobox-toggle::after { content: "▾"; font-size: 1rem; }
.combobox.is-disabled .combobox-toggle { cursor: not-allowed; opacity: 0.5; }
.combobox-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 0.25rem 0;
  list-style: none; max-height: 340px; overflow-y: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / 14%);
}
.combobox-option { padding: 0.5rem 0.8rem; cursor: pointer; line-height: 1.35; }
.combobox-option.active { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.combobox-option[aria-selected="true"] strong::after { content: " ✓"; color: var(--accent); }
.combobox-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.combobox-head .badge { flex-shrink: 0; font-size: 0.75rem; }
.combobox-option .muted { font-size: 0.88rem; }
.combobox-create { color: var(--accent); border-top: 1px solid var(--border); }
.combobox-message { color: var(--muted); cursor: default; font-size: 0.88rem; }
.subform { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; margin: 0.75rem 0; max-width: 520px; }
.subform legend { padding: 0 0.35rem; font-weight: 600; }
.field { margin-bottom: 0.75rem; }

.search-filter { min-width: 220px; flex: 1 1 220px; max-width: 320px; }

.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.checkbox-label { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 1rem; color: var(--text); }
.password-row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-top: 0.25rem; }
.password-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; min-width: 16rem; }

.field-status { display: inline-block; margin-left: 0.5rem; font-size: 0.9rem; }
.field-status.is-info { color: var(--accent); }
.field-status.is-error { color: #c92a2a; }

/* Bulk edit of follow-ups */
.select-cell { width: 2rem; }
tr.is-selected td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.bulk-bar {
  position: sticky; bottom: 0; z-index: 15; display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: end;
  margin-top: 1rem; padding: 0.75rem 1rem; background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); box-shadow: 0 -6px 18px rgb(0 0 0 / 10%);
}
.bulk-bar label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.bulk-count { align-self: center; margin-right: auto; }
.link-button { background: none; border: 0; color: var(--accent); padding: 0 0.25rem; cursor: pointer; font: inherit; text-decoration: underline; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.change-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.change-list li { padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.change-list li:last-child { border-bottom: 0; }
dialog { width: min(460px, calc(100vw - 2rem)); }

.card-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.button.small, button.small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

/* App version */
.app-version { font-size: 0.75rem; color: var(--muted); margin-left: -1rem; align-self: flex-end; padding-bottom: 0.15rem; }
.menu-footer { padding: 0.45rem 0.9rem 0.2rem; margin-top: 0.25rem; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }
.login-version { margin: 0.5rem 0 0; font-size: 0.8rem; text-align: right; }
