/* R&D Board (D-017): patterns from Linear, GitHub Projects, Plane and Jira (Design references.md).
   Neutral surface, colour only where it means something, FAB Slate as the one strong colour, teal for
   focus and progress. System font; nothing under 15 px (the user's readability floor).
   D-018: every colour is a variable; the dark set is one block below. Same 4.5:1 floor in both. */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --column: #eef1f4;
  --line: #e1e5ea;
  --line-strong: #c9d1d9;
  --hover: #eef1f4;
  --ink: #1d2733;
  --muted: #5a6572;          /* 6.0:1 on white */
  --icon: #7a8591;           /* icons only, never text */
  --slate: #243746;
  --primary-bg: #243746;
  --primary-ink: #ffffff;
  --primary-hover: #31495c;
  --mark: #243746;
  --teal: #1ecad3;
  --red: #c0362c;            /* 5.6:1 on white */
  --red-wash: #fdecea;
  --red-line: #f5c2bd;
  --urgent-bg: #c0362c;
  --amber-ink: #8a5a00;      /* 6.2:1 on white */
  --amber-wash: #fdf3dc;
  --amber-line: #f1dca8;
  --info-bg: #e3f6f7;
  --info-line: #b9e6e9;
  --tabs-bg: #e6e9ed;
  --tab-on: #ffffff;
  --dev-bg: #fff3c4;
  --dev-ink: #5c4400;
  --backdrop: rgba(16, 24, 40, .35);
  --shadow: rgba(16, 24, 40, .06);
  --shadow-lift: rgba(16, 24, 40, .1);
  --st-requests: #b7791f;
  --st-todo: #7a8591;
  --st-doing: #0e9aa7;
  --st-waiting: #c2410c;
  --st-done: #2f855a;
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, Arial, sans-serif;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
/* Dark: greys lean towards FAB Slate, not pure black. The primary button turns teal with dark text,
   because a slate button disappears on a slate-dark page. */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #12171d;
  --surface: #1a2028;
  --column: #161c23;
  --line: #29313b;
  --line-strong: #3a4450;
  --hover: #232a33;
  --ink: #e5e9ed;
  --muted: #9ea9b5;          /* 6.6:1 on the dark surface */
  --icon: #7f8a96;
  --primary-bg: #1ecad3;
  --primary-ink: #0d1a20;
  --primary-hover: #4fd7de;
  --mark: #2c4256;
  --red: #ff8f85;            /* 7.0:1 on the dark surface */
  --red-wash: #3a1d1d;
  --red-line: #6a2a2a;
  --urgent-bg: #c0362c;
  --amber-ink: #f0c56a;
  --amber-wash: #33290f;
  --amber-line: #5e4b1c;
  --info-bg: #0f3035;
  --info-line: #1e5961;
  --tabs-bg: #232a33;
  --tab-on: #313a45;
  --dev-bg: #3a3014;
  --dev-ink: #f3dc93;
  --backdrop: rgba(0, 0, 0, .55);
  --shadow: rgba(0, 0, 0, .3);
  --shadow-lift: rgba(0, 0, 0, .45);
  --st-requests: #e2a640;
  --st-todo: #8b97a3;
  --st-doing: #2fc6d1;
  --st-waiting: #f27a42;
  --st-done: #4cb57a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: var(--ink); }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
svg.i { width: 16px; height: 16px; flex: none; display: block; }

/* ---------- controls ---------- */
button { cursor: pointer; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 6px 12px; display: inline-flex; align-items: center; gap: 6px; }
button:hover { background: var(--hover); }
.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); font-weight: 600; }
.primary:hover { background: var(--primary-hover); }
.ghost { background: transparent; border-color: transparent; color: var(--ink); }
.ghost:hover { background: var(--hover); }
.ghost-dark { background: transparent; border-color: transparent; color: var(--muted); }
.ghost-dark:hover { background: var(--hover); color: var(--ink); }
.icon-btn { background: transparent; border-color: transparent; padding: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.danger-ghost { background: transparent; border-color: transparent; color: var(--red); }
.danger-ghost:hover { background: var(--red-wash); }
input, select, textarea { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 9px; background: var(--surface); }
textarea { width: 100%; resize: vertical; }

.devbar { background: var(--dev-bg); color: var(--dev-ink); padding: 4px 16px; display: flex; gap: 8px; align-items: center; }
.devbar select { padding: 2px 6px; }

/* ---------- app bar + view bar ---------- */
.appbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .mark { width: 22px; height: 22px; border-radius: 6px; background: var(--mark); position: relative; }
.brand .mark::after { content: ""; position: absolute; inset: 6px 5px 6px 9px; background: var(--teal); border-radius: 2px; }
.brand .org { color: var(--muted); }
.brand .slash { color: var(--line-strong); }
.brand h1 { font-size: 17px; }
.search { flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 10px; background: var(--surface); color: var(--icon); }
.search:focus-within { outline: 2px solid var(--teal); outline-offset: 1px; }
.search input { border: none; padding: 6px 0; width: 100%; outline: none; background: transparent; }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
#bell, #theme-btn { position: relative; padding: 6px 9px; }
.count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--urgent-bg); color: #fff; font-weight: 600; text-align: center; line-height: 20px; }

.viewbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px 0; }
.tabs { display: flex; gap: 2px; background: var(--tabs-bg); border-radius: 8px; padding: 3px; }
.tabs button { border: none; background: transparent; padding: 4px 12px; border-radius: 6px; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--tab-on); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px var(--shadow-lift); }
.viewbar select { max-width: 240px; }

.status-line { margin: 10px 20px 0; padding: 8px 12px; border-radius: 6px; background: var(--info-bg); color: var(--ink); border: 1px solid var(--info-line); }
.status-line.error { background: var(--red-wash); color: var(--red); border-color: var(--red-line); font-weight: 600; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(250px, 1fr)); gap: 12px; padding: 12px 20px 32px; overflow-x: auto; align-items: start; }
.column { background: var(--column); border-radius: 10px; padding: 6px 8px 8px; min-height: 120px; }
.column.drop-target { outline: 2px dashed var(--teal); outline-offset: -2px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 6px 4px 8px; }
.col-head h2 { font-size: 15px; }
.col-head .n { color: var(--muted); }
.col-head .add { margin-left: auto; padding: 3px; }
.st-icon { color: var(--st-todo); display: inline-flex; }
.st-icon.requests { color: var(--st-requests); }
.st-icon.doing { color: var(--st-doing); }
.st-icon.waiting { color: var(--st-waiting); }
.st-icon.done { color: var(--st-done); }
.cards { display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--muted); padding: 8px 6px; margin: 0; }

/* ---------- card ---------- */
.card { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px var(--shadow); }
.card:hover { background: var(--surface); border-color: var(--line-strong); box-shadow: 0 2px 6px var(--shadow-lift); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
.key { color: var(--muted); }
.card-title { display: block; font-weight: 600; margin: 2px 0 8px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; color: var(--muted); max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip svg { color: var(--icon); width: 14px; height: 14px; }
.chip.late { color: var(--red); border-color: var(--red-line); background: var(--red-wash); }
.chip.late svg { color: var(--red); }
.chip.high { color: var(--red); }
.chip.high svg { color: var(--red); }
.chip.urgent { color: #fff; background: var(--urgent-bg); border-color: var(--urgent-bg); font-weight: 600; }
.chip.urgent svg { color: #fff; }
.chip.wait { color: var(--amber-ink); background: var(--amber-wash); border-color: var(--amber-line); }
.chip.wait svg { color: var(--amber-ink); }
.progress { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); }
.progress .track { flex: 1; display: block; height: 6px; border-radius: 3px; background: var(--column); overflow: hidden; }
.progress .fill { display: block; height: 100%; background: var(--teal); }

.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 15px; letter-spacing: -.03em; flex: none; }
.avatar.none { background: transparent; border: 1.5px dashed var(--line-strong); }
.av0 { background: #4f5fb0; } .av1 { background: #2b7568; } .av2 { background: #a34b28; }
.av3 { background: #6e4f9a; } .av4 { background: #346495; } .av5 { background: #7a5f12; }

/* ---------- dialogs ---------- */
dialog { border: none; padding: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: var(--backdrop); }
/* max-width: the browser's own dialog style caps it below the screen width (seen on a phone). */
.panel { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(640px, 100vw); max-width: 100vw; border-left: 1px solid var(--line); }
.panel.narrow { width: min(420px, 100vw); }
.modal { width: min(620px, 94vw); border-radius: 12px; max-height: 90vh; box-shadow: 0 20px 50px var(--shadow-lift); border: 1px solid var(--line); }
@media (prefers-reduced-motion: no-preference) {
  .panel[open] { animation: slide-in .16s ease-out; }
  @keyframes slide-in { from { transform: translateX(20px); opacity: .7; } to { transform: none; opacity: 1; } }
}
.panel-head, .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px 10px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.panel-head h2, .modal-head h2 { font-size: 15px; }
.panel-head form, .modal-head form { margin: 0; }
.panel-tools { display: flex; align-items: center; gap: 2px; }
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 400; }
.crumbs .here { color: var(--ink); font-weight: 600; }
.crumbs button { padding: 2px 6px; color: var(--muted); border-color: transparent; background: transparent; }
.crumbs button:hover { background: var(--hover); color: var(--ink); }

.panel-body { padding: 18px 24px 32px; }
.title-edit { width: 100%; font-size: 22px; font-weight: 600; border: 1px solid transparent; padding: 4px 6px; margin-left: -7px; border-radius: 6px; line-height: 1.3; background: transparent; }
.title-edit:hover { border-color: var(--line); }
.title-read { font-size: 22px; line-height: 1.3; overflow-wrap: anywhere; }
.pending { margin: 10px 0 0; padding: 8px 12px; border-radius: 6px; background: var(--red-wash); color: var(--red); font-weight: 600; border: 1px solid var(--red-line); }
.props { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 16px 0 6px; align-items: center; }
.props dt { color: var(--muted); display: flex; align-items: center; gap: 8px; min-height: 34px; }
.props dt svg { color: var(--icon); }
.props dd { margin: 0; min-width: 0; }
.props select, .props input { width: 100%; max-width: 320px; border-color: transparent; background: transparent; padding: 5px 8px; margin-left: -9px; }
.props select:hover, .props input:hover { border-color: var(--line); background: var(--surface); }
.props .static { padding: 5px 0; display: inline-flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.props .needs { border-color: var(--red) !important; background: var(--red-wash) !important; }
.section-title { font-size: 15px; margin: 20px 0 8px; display: flex; align-items: center; gap: 8px; }
.details-edit { min-height: 90px; border-color: var(--line); }
.details-read { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); margin: 0; }
.muted { color: var(--muted); }

.tasks { list-style: none; margin: 0 0 8px; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.tasks li + li { border-top: 1px solid var(--line); }
.tasks button { width: 100%; border: none; border-radius: 0; background: transparent; display: flex; align-items: center; gap: 8px; padding: 8px 10px; text-align: left; }
.tasks button:hover { background: var(--hover); }
.tasks .key { flex: none; }
.tasks .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.activity { list-style: none; margin: 0; padding: 0 0 0 8px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.activity li { position: relative; padding-left: 16px; }
.activity li::before { content: ""; position: absolute; left: -6px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); }
.activity li.event { color: var(--muted); }
.activity li.event b { color: var(--ink); font-weight: 600; }
.activity li.update::before { background: var(--teal); border-color: var(--teal); }
.activity .bubble { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--surface); }
.activity .who { display: block; color: var(--muted); }
.activity .who b { color: var(--ink); }
.activity .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.activity .when { color: var(--muted); }
.composer { margin-top: 12px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px; background: var(--surface); }
.composer textarea { border: none; padding: 4px; min-height: 64px; outline: none; background: transparent; }
.composer:focus-within { outline: 2px solid var(--teal); outline-offset: 1px; }
.composer .row { display: flex; justify-content: flex-end; }

.new-form { padding: 16px 20px 18px; }
.new-title { width: 100%; font-size: 20px; font-weight: 600; border: none; padding: 4px 0; outline: none; background: transparent; }
.new-details { width: 100%; border: none; padding: 4px 0; min-height: 80px; outline: none; background: transparent; }
.new-props { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; padding: 14px 0; border-top: 1px solid var(--line); margin-top: 8px; }
.new-props label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.new-props select, .new-props input { width: 100%; }
.form-error { color: var(--red); font-weight: 600; margin: 0; min-height: 1.4em; }
.form-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.form-foot .form-error { margin-right: auto; }

.notes { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.notes button { width: 100%; border: none; background: transparent; text-align: left; display: grid; grid-template-columns: 10px 1fr; gap: 2px 10px; padding: 8px 10px; border-radius: 8px; }
.notes button:hover { background: var(--hover); }
.notes .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; }
.notes li.unread .dot { background: var(--teal); }
.notes li.unread .txt { font-weight: 600; }
.notes .when { grid-column: 2; color: var(--muted); }
.archive { list-style: none; margin: 0; padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 6px; }
.archive li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .appbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .brand .org, .brand .slash { display: none; }
  .search { order: 3; flex: 1 1 100%; max-width: none; }
  .hide-sm { display: none; }
  .viewbar { padding: 8px 12px 0; }
  .viewbar select { flex: 1; min-width: 0; max-width: none; }
  .board { display: flex; scroll-snap-type: x mandatory; padding: 10px 12px 24px; gap: 10px; }
  .column { flex: 0 0 86vw; scroll-snap-align: start; }
  .panel, .panel.narrow { width: 100vw; border-left: none; }
  .panel-body { padding: 14px 16px 28px; }
  .props { grid-template-columns: 104px 1fr; }
}
