[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #667085;
  --primary: #2563eb;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #d97706;
  --warn-soft: #fff4e0;
  --ok: #16a34a;
  --ok-soft: #e7f7ec;
  --purple: #7c3aed;
  --purple-soft: #f1eafe;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a;
    --surface: #171c25;
    --surface-2: #1f2531;
    --border: #2b3240;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --primary: #5b8cff;
    --primary-soft: #1d2a47;
    --danger: #f87171;
    --danger-soft: #3a1d1f;
    --warn: #fbbf24;
    --warn-soft: #3a2e15;
    --ok: #4ade80;
    --ok-soft: #173123;
    --purple: #a78bfa;
    --purple-soft: #2a2145;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* 版面 */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand-logo { width: 26px; height: 26px; border-radius: 7px; background: var(--primary); display: grid; place-items: center; color: #fff; font-size: 13px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-section { font-size: 11px; color: var(--muted); padding: 14px 10px 4px; letter-spacing: .04em; }
.nav-project { font-size: 13px; }
.nav-project .key { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.topbar-mobile { display: none; }

/* 元件 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-projects { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-2 { grid-template-columns: 1.4fr 1fr; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.b-task { background: var(--primary-soft); color: var(--primary); }
.b-bug { background: var(--danger-soft); color: var(--danger); }
.b-feedback { background: var(--purple-soft); color: var(--purple); }
.p-critical { background: var(--danger); color: #fff; }
.p-high { background: var(--danger-soft); color: var(--danger); }
.p-medium { background: var(--warn-soft); color: var(--warn); }
.p-low { background: var(--surface-2); color: var(--muted); }
.s-todo { background: var(--surface-2); color: var(--muted); }
.s-in_progress { background: var(--primary-soft); color: var(--primary); }
.s-review { background: var(--warn-soft); color: var(--warn); }
.s-done { background: var(--ok-soft); color: var(--ok); }
.ps-planning { background: var(--purple-soft); color: var(--purple); }
.ps-active { background: var(--primary-soft); color: var(--primary); }
.ps-paused { background: var(--warn-soft); color: var(--warn); }
.ps-done { background: var(--ok-soft); color: var(--ok); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress.done > span { background: var(--ok); }

.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff; flex: none; }
.avatar-lg { width: 32px; height: 32px; font-size: 13px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; 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; }
.tabs .count { font-size: 11px; background: var(--surface-2); border-radius: 999px; padding: 0 6px; margin-left: 4px; }

.project-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color .15s; }
.project-card:hover { border-color: var(--primary); }
.project-card .meta { display: flex; gap: 14px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.project-card .meta b { color: var(--text); }
.project-card .meta .warn b { color: var(--danger); }

/* 看板 */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; display: flex; flex-direction: column; gap: 8px; }
.column.drag-over { outline: 2px dashed var(--primary); outline-offset: -2px; }
.column-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; padding: 2px 4px 4px; }
.issue-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.issue-card:hover { border-color: var(--primary); }
.issue-card[draggable="true"] { cursor: grab; }
.issue-card.dragging { opacity: .4; }
.issue-card .title { font-weight: 500; word-break: break-word; }
.issue-card .foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.issue-key { white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }
.overdue { color: var(--danger) !important; font-weight: 600; }

/* 清單 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* 動態 */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .text { flex: 1; min-width: 0; word-break: break-word; }
.feed .time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 抽屜 */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 41; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); animation: slide .2s ease-out; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; display: grid; grid-template-columns: 1fr 220px; gap: 24px; align-content: start; }
.drawer-body .side .field { margin-bottom: 12px; }
.section-title { font-size: 12px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; letter-spacing: .03em; }
.prose { white-space: pre-wrap; word-break: break-word; }
.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment .body { flex: 1; min-width: 0; }
.comment .who { font-weight: 600; font-size: 13px; }

.modal { position: fixed; z-index: 51; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); animation: pop .15s; }
.modal .overlay-z { z-index: 50; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); animation: pop .15s; }
#toast div.err { background: var(--danger); color: #fff; }

/* 登入 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; }
.login-card .brand { padding: 0 0 18px; justify-content: center; font-size: 19px; }
.error { color: var(--danger); font-size: 13px; margin-bottom: 10px; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.role-help { font-size: 12px; color: var(--muted); line-height: 1.7; }
.role-help b { color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
#toast div { animation: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; z-index: 30; width: 260px; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .sidebar.open { display: flex; }
  .topbar-mobile { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .main { padding: 16px 16px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .drawer-body { grid-template-columns: 1fr; }
  .row { flex-direction: column; gap: 0; }
  .board { grid-template-columns: repeat(4, 260px); }
  .hide-sm { display: none; }
  .table th, .table td { padding: 8px; }
}
