/* ---------------------------------------------------------------- theme */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-2: #eaeef2;
  --raised: #ffffff;
  --border: #d1d9e0;
  --border-strong: #b7c0c9;
  --text: #1f2328;
  --muted: #59636e;
  --faint: #818b96;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --accent-text: #ffffff;
  --open: #1a7f37;
  --open-soft: #dafbe1;
  --closed: #8250df;
  --closed-soft: #f5edff;
  --danger: #cf222e;
  --danger-soft: #ffebe9;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.08), 0 3px 8px rgba(31, 35, 40, 0.06);
  --shadow-lg: 0 8px 28px rgba(31, 35, 40, 0.18);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c2430;
    --raised: #151b23;
    --border: #2f3742;
    --border-strong: #444c56;
    --text: #e6edf3;
    --muted: #9198a1;
    --faint: #7d8590;
    --accent: #4493f8;
    --accent-soft: #121d2f;
    --accent-text: #ffffff;
    --open: #3fb950;
    --open-soft: #10271a;
    --closed: #ab7df8;
    --closed-soft: #1d1a2b;
    --danger: #f85149;
    --danger-soft: #2a1516;
    --shadow: 0 1px 2px rgba(1, 4, 9, 0.5), 0 3px 8px rgba(1, 4, 9, 0.4);
    --shadow-lg: 0 8px 28px rgba(1, 4, 9, 0.7);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1c2430;
  --raised: #151b23;
  --border: #2f3742;
  --border-strong: #444c56;
  --text: #e6edf3;
  --muted: #9198a1;
  --faint: #7d8590;
  --accent: #4493f8;
  --accent-soft: #121d2f;
  --accent-text: #ffffff;
  --open: #3fb950;
  --open-soft: #10271a;
  --closed: #ab7df8;
  --closed-soft: #1d1a2b;
  --danger: #f85149;
  --danger-soft: #2a1516;
  --shadow: 0 1px 2px rgba(1, 4, 9, 0.5), 0 3px 8px rgba(1, 4, 9, 0.4);
  --shadow-lg: 0 8px 28px rgba(1, 4, 9, 0.7);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--open);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { background: color-mix(in srgb, var(--open) 85%, #000); border-color: transparent; }
.btn-accent { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 6px; }

.input, .select, textarea {
  width: 100%;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.input:focus, .select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.select { cursor: pointer; }
textarea { resize: vertical; }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- chrome */

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand svg { display: block; }

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tab.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }

.header-search { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.header-search .input { padding-left: 32px; }
.header-search svg { position: absolute; left: 10px; top: 9px; color: var(--faint); }

.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 650;
  color: #fff;
  flex: 0 0 auto;
  user-select: none;
}
.avatar-lg { width: 34px; height: 34px; font-size: 13px; }
.avatar-sm { width: 20px; height: 20px; font-size: 9px; }

.main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.main-narrow { max-width: 1012px; }

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.page-head h1 { font-size: 20px; margin: 0; font-weight: 600; }
.page-head .grow { flex: 1; }

/* ---------------------------------------------------------------- board */

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(270px, 1fr);
  gap: 14px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 8px;
}

.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 140px;
  max-height: calc(100vh - 160px);
}
.column.drop { border-color: var(--accent); background: var(--accent-soft); }

.column-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.column-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.card {
  display: block;
  padding: 10px 11px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  cursor: grab;
  color: var(--text);
}
.card:hover { border-color: var(--border-strong); text-decoration: none; }
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.4; }
.card-title { font-weight: 550; line-height: 1.4; margin-bottom: 6px; word-break: break-word; }
.card-meta { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 12px; }
.card-num { font-variant-numeric: tabular-nums; }
.card-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 7px; }

.column-empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- list */

.listbox { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); }
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-link { color: var(--muted); font-weight: 550; display: inline-flex; align-items: center; gap: 5px; }
.filter-link.on { color: var(--text); }
.filter-link:hover { color: var(--text); text-decoration: none; }

.row {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-top: 1px solid var(--border);
  align-items: flex-start;
}
.row:first-child { border-top: none; }
.row:hover { background: var(--surface); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 550; color: var(--text); word-break: break-word; }
.row-title:hover { color: var(--accent); text-decoration: none; }
.row-sub { color: var(--faint); font-size: 12px; margin-top: 3px; }
.row-side { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; }

.empty {
  padding: 56px 20px;
  text-align: center;
  color: var(--muted);
}
.empty h2 { font-size: 16px; margin: 0 0 6px; color: var(--text); }
.empty p { margin: 0 auto 16px; max-width: 34ch; }

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

.label-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid;
  font-size: 11.5px;
  font-weight: 550;
  line-height: 18px;
  white-space: nowrap;
}
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
}
.state-open { background: var(--open); }
.state-closed { background: var(--closed); }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 550;
}

/* ---------------------------------------------------------------- issue page */

.issue-head { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.issue-title { font-size: 26px; font-weight: 400; margin: 0 0 8px; line-height: 1.3; word-break: break-word; }
.issue-title .num { color: var(--faint); font-weight: 300; }
.issue-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

.issue-grid { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 26px; align-items: start; }
@media (max-width: 900px) { .issue-grid { grid-template-columns: minmax(0, 1fr); } }

.timeline { display: flex; flex-direction: column; gap: 14px; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
  z-index: 0;
}
.entry { display: flex; gap: 12px; position: relative; z-index: 1; }

.comment { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.comment-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-radius: 9px 9px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.comment-head strong { color: var(--text); font-weight: 600; }
.comment-body { padding: 13px; }
.comment.is-author .comment-head { background: var(--accent-soft); }

.event-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  min-height: 26px;
  flex-wrap: wrap;
}
.event-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  border: 3px solid var(--bg);
  flex: 0 0 auto;
  margin-left: 1px;
}

.sidebar-block { padding: 14px 0; border-bottom: 1px solid var(--border); }
.sidebar-block:first-child { padding-top: 0; }
.sidebar-block:last-child { border-bottom: none; }
.sidebar-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 9px;
}

/* ---------------------------------------------------------------- editor */

.editor { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.editor.drag { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.editor-tab {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  margin-bottom: -1px;
}
.editor-tab.on { background: var(--bg); border-color: var(--border); color: var(--text); }
.editor-tools { margin-left: auto; display: flex; gap: 2px; padding-bottom: 6px; }
.tool {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.editor textarea {
  border: none; border-radius: 0;
  min-height: 130px;
  font: 13.5px/1.6 var(--mono);
  padding: 12px;
}
.editor textarea:focus { outline: none; }
.editor-preview { padding: 13px; min-height: 130px; }
.editor-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--faint);
  font-size: 12px;
}
.editor-foot .grow { flex: 1; }

/* ---------------------------------------------------------------- markdown */

.md { word-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 22px 0 12px; font-weight: 600; line-height: 1.3; }
.md h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md h3 { font-size: 1.1em; }
.md p, .md ul, .md ol, .md blockquote, .md table, .md pre { margin: 0 0 14px; }
.md ul, .md ol { padding-left: 1.8em; }
.md li + li { margin-top: 3px; }
.md li::marker { color: var(--faint); }
.md code {
  font: 0.86em var(--mono);
  background: var(--surface-2);
  padding: 0.16em 0.4em;
  border-radius: 5px;
}
.md pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
.md blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 0 0 0 14px;
  color: var(--muted);
}
.md img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--surface); font-weight: 600; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.md .task {
  display: inline-block;
  width: 13px; height: 13px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
}
.md .task-done {
  background: var(--accent);
  border-color: var(--accent);
  background-image: linear-gradient(transparent, transparent);
  position: relative;
}
.md .task-done::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 3px; height: 7px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}
.md li:has(> .task) { list-style: none; margin-left: -1.4em; }
.md .empty-body { color: var(--faint); font-style: italic; }

/* ---------------------------------------------------------------- modal */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(1, 4, 9, 0.55);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade 0.12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: min(760px, 100%);
  max-height: min(84vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }

.docs h3 { font-size: 14px; margin: 22px 0 8px; }
.docs h3:first-child { margin-top: 0; }
.docs p { margin: 0 0 10px; color: var(--muted); }
.docs table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 13px; }
.docs th, .docs td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.docs th { color: var(--muted); font-weight: 600; font-size: 12px; }
.docs td code { font: 12px var(--mono); white-space: nowrap; }
.docs pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; font: 12.5px/1.55 var(--mono); margin: 0 0 14px;
}

.token-strip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--open-soft);
  border: 1px solid var(--open);
  border-radius: 9px;
  margin-bottom: 14px;
  font: 12.5px var(--mono);
  word-break: break-all;
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  max-width: 360px;
  animation: rise 0.16s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- misc */

.app-loading { min-height: 100vh; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.rowflex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

.signin {
  min-height: 80vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
}
.signin-card { max-width: 380px; }
.signin-card h1 { font-size: 20px; margin: 14px 0 8px; }
.signin-card p { color: var(--muted); margin: 0 0 20px; }

/* ---------------------------------------------------------------- popover */

.popover {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.menu { width: 268px; max-height: 340px; display: flex; flex-direction: column; }
.menu-head {
  padding: 9px 13px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.menu-pad { padding: 9px; border-bottom: 1px solid var(--border); }
.menu-list { overflow-y: auto; }
.menu-empty { padding: 14px 13px; color: var(--faint); font-size: 12.5px; text-align: center; }
.menu-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 11px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-row:hover { background: var(--surface); }
.menu-row .grow { display: flex; align-items: center; gap: 7px; min-width: 0; }
.menu-check { width: 14px; display: grid; place-items: center; color: var(--accent); flex: 0 0 auto; }

/* ---------------------------------------------------------------- tables */

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface); font-size: 12px; color: var(--muted); font-weight: 650; }
.table tr:last-child td { border-bottom: none; }
