:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --open: #64748b;
  --progress: #2563eb;
  --done: #059669;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 8%);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Author `display` rules would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

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

h1 { font-size: 1.5rem; margin: 0; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.danger-text { color: var(--danger); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }

/* ------------------------------------------------------------ layout */

.topbar {
  background: #111827;
  color: #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.brand { color: #fff; font-weight: 700; letter-spacing: .02em; }
.brand span, .auth-title span { color: #a5b4fc; }
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #d1d5db;
  padding: .35rem .7rem;
  border-radius: 6px;
}
.nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.nav a.active { background: #374151; color: #fff; }

.user-menu { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.user-menu form { margin: 0; }
.user-name { color: #e5e7eb; padding: .3rem .5rem; border-radius: 6px; }
.user-name:hover, .user-name.active { background: #374151; text-decoration: none; }
.topbar .btn.ghost { color: #d1d5db; border-color: #4b5563; background: transparent; }
.topbar .btn.ghost:hover { background: #1f2937; }

@media (max-width: 720px) {
  .topbar-inner { gap: .4rem .75rem; padding: .5rem .75rem; }
  /* Brand and actions on the first row, navigation as one scrollable row below. */
  .nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav a { white-space: nowrap; }
  .user-name { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .container { padding: 1rem .75rem 2.5rem; }
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.narrow { max-width: 440px; padding-top: 10vh; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.stack { display: grid; gap: 1rem; }

@media (max-width: 860px) {
  .grid-main { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
}

.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.card-head h2 { margin-bottom: .25rem; }

.empty { color: var(--muted); padding: 1rem 0; margin: 0; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  padding: .45rem .9rem;
  border-radius: 7px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn:focus-visible, .seg:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #c7d2fe;
  outline-offset: 1px;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #fca5a5; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.small { padding: .3rem .7rem; font-size: .88rem; }
.btn.tiny { padding: .15rem .5rem; font-size: .8rem; border-radius: 6px; }
.btn.block { width: 100%; }

input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  padding: .45rem .6rem;
  background: #fff;
  min-width: 0;
}
textarea { resize: vertical; }
input[type="color"] { padding: .15rem; height: 2.4rem; width: 4rem; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

.form { display: grid; gap: .9rem; }
.form label { display: grid; gap: .3rem; font-weight: 500; }
.form small, .form label small { color: var(--muted); font-weight: 400; font-size: .82rem; }
.form label.check { display: flex; align-items: center; gap: .5rem; }
.form fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: .5rem; }
.form legend { font-weight: 500; margin-bottom: .35rem; padding: 0; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.form > .btn { justify-self: start; }
.auth-card .form > .btn { justify-self: stretch; }
.narrow-page { max-width: 560px; margin-left: auto; margin-right: auto; }

form.inline { display: inline-flex; gap: .35rem; align-items: center; margin: 0; }

.issue-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) {
  .issue-form { grid-template-columns: 1fr; }
}

.radio-card {
  display: flex !important;
  gap: .6rem;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
  cursor: pointer;
  font-weight: 400 !important;
}
.radio-card span { display: grid; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

.chip-options { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-option { display: inline-flex !important; align-items: center; gap: .25rem; cursor: pointer; font-weight: 400 !important; }
/* Visually hidden but still reachable by keyboard and screen readers. */
.chip-option input { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
.chip-option .chip { opacity: .45; padding: .2rem .65rem; font-size: .85rem; }
.chip-option input:checked + .chip { opacity: 1; box-shadow: 0 0 0 2px var(--c); }
.chip-option input:focus-visible + .chip { outline: 3px solid #c7d2fe; }

.reminder { display: grid; gap: .5rem; }

/* ------------------------------------------------------------ feedback */

.flash {
  border-radius: 8px;
  padding: .7rem .9rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.flash ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.flash-ok { background: var(--ok-soft); border-color: #a7f3d0; color: var(--ok); }
.flash-err { background: var(--danger-soft); border-color: #fecaca; color: #b91c1c; }

.callout { border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
.callout.warn { background: var(--warn-soft); border: 1px solid #fde68a; color: #92400e; }
.callout.info { background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; }

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: .5rem;
  z-index: 50;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  background: #111827;
  color: #f9fafb;
  border-radius: 10px;
  padding: .8rem 2.2rem .8rem 1rem;
  box-shadow: 0 10px 25px rgb(0 0 0 / 25%);
  position: relative;
  animation: toast-in .2s ease-out;
}
.toast a { color: #c7d2fe; font-weight: 600; }
.toast p { margin: .15rem 0 0; font-size: .85rem; color: #d1d5db; }
.toast-close {
  position: absolute;
  top: .35rem;
  right: .4rem;
  background: none;
  border: 0;
  color: #9ca3af;
  font-size: 1.1rem;
  cursor: pointer;
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------ issues */

.chip {
  --c: #64748b;
  display: inline-block;
  padding: .05rem .5rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, white);
  border: 1px solid color-mix(in srgb, var(--c) 35%, white);
  line-height: 1.5;
}
a.chip:hover { text-decoration: none; filter: brightness(.95); }

.badge {
  display: inline-block;
  padding: .05rem .5rem;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.s-open { background: #f1f5f9; color: var(--open); }
.badge.s-in_progress { background: #eff6ff; color: var(--progress); }
.badge.s-done { background: var(--ok-soft); color: var(--done); }
.muted-badge { background: #f3f4f6; color: var(--muted); }
.series-badge { background: #eef2ff; color: #4338ca; }
a.series-badge:hover { text-decoration: none; filter: brightness(.95); }
.repeat { display: grid; gap: .5rem; }
.warn-badge { background: var(--warn-soft); color: var(--warn); }

.status-dot { width: .7rem; height: .7rem; border-radius: 50%; flex: none; margin-top: .45rem; background: var(--open); }
.status-dot.s-in_progress { background: var(--progress); }
.status-dot.s-done { background: var(--done); }

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-item {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  padding: .7rem .25rem;
  border-top: 1px solid var(--line);
}
.issue-item:first-child { border-top: 0; }
.issue-main { flex: 1; min-width: 0; }
.issue-side { display: grid; justify-items: end; gap: .3rem; }
.issue-side form { margin: 0; }
.issue-title { font-weight: 600; color: var(--text); word-break: break-word; }
.issue-title.done { color: var(--muted); text-decoration: line-through; }
.issue-meta { display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: center; font-size: .82rem; color: #4b5563; margin-top: .2rem; }
.unassigned { color: var(--warn); font-style: normal; }

.due { font-size: .82rem; color: var(--muted); white-space: nowrap; margin-top: .15rem; }
.due.soon { color: var(--warn); font-weight: 600; }
.due.overdue { color: var(--danger); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem 1.1rem;
  display: grid;
  color: var(--text);
}
.stat:hover { text-decoration: none; border-color: #c7d2fe; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .88rem; }
.stat.danger .stat-value { color: var(--danger); }
.stat.warn .stat-value { color: var(--warn); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.filters input[type="search"] { flex: 1 1 220px; }

.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li { display: grid; padding: .45rem 0; border-top: 1px solid var(--line); }
.simple-list li:first-child { border-top: 0; }

.crumb { margin: 0 0 .5rem; font-size: .9rem; }
.issue-head { align-items: flex-start; }
.issue-heading { word-break: break-word; }
.head-actions { display: flex; gap: .5rem; }
.head-actions form { margin: 0; }
.body-text { white-space: pre-wrap; word-break: break-word; }

.details { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

.segmented { display: flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.segmented form { flex: 1; margin: 0; display: flex; }
.seg {
  flex: 1;
  border: 0;
  border-left: 1px solid #d1d5db;
  background: #fff;
  padding: .5rem;
  font: inherit;
  cursor: pointer;
}
.segmented form:first-child .seg { border-left: 0; }
.seg:hover { background: #f9fafb; }
.seg.active { background: var(--primary); color: #fff; cursor: default; }

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

.board { display: grid; grid-template-columns: repeat(3, minmax(260px, 1fr)); gap: 1rem; align-items: start; overflow-x: auto; }
.column { background: #eceef4; border-radius: var(--radius); padding: .75rem; min-height: 200px; }
.column h2 { display: flex; align-items: center; gap: .5rem; font-size: .95rem; }
.column .count { background: #fff; border-radius: 999px; padding: 0 .55rem; font-size: .8rem; color: var(--muted); }
.col-open h2 { color: var(--open); }
.col-in_progress h2 { color: var(--progress); }
.col-done h2 { color: var(--done); }
.board-card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: .65rem .75rem;
  margin-bottom: .6rem;
  display: grid;
  gap: .35rem;
}
.board-card-foot { display: flex; justify-content: space-between; gap: .5rem; font-size: .82rem; color: #4b5563; }
.moves { display: flex; gap: .35rem; flex-wrap: wrap; }
.moves form, .board-card > form { margin: 0; }
@media (max-width: 860px) {
  .board { grid-template-columns: 1fr; }
}

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

.table-card { overflow-x: auto; margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .5rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .82rem; color: var(--muted); font-weight: 600; border-top: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.table tr.inactive td { color: var(--muted); }
.reset-form input { width: 9rem; padding: .2rem .45rem; font-size: .82rem; }
.w-bar { width: 28%; min-width: 140px; }

.bar { display: flex; height: .65rem; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.bar-progress { background: var(--progress); }
.bar-open { background: #94a3b8; }
.legend { display: flex; gap: .4rem; align-items: center; font-size: .8rem; color: var(--muted); margin: .75rem 0 0; }
.legend .dot { width: .7rem; height: .7rem; border-radius: 3px; display: inline-block; margin-left: .5rem; }

.label-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.label-list li { display: flex; align-items: center; gap: .6rem; }
.label-list .chip { font-size: .85rem; padding: .15rem .7rem; }

/* ------------------------------------------------------------ auth */

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgb(15 23 42 / 8%);
  padding: 2rem;
}
.auth-title { text-align: center; font-size: 1.6rem; margin-bottom: .25rem; }
.auth-card .form { margin-top: 1.25rem; }
.error-code { font-size: 3rem; font-weight: 700; margin: 0; color: var(--primary); }
