:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #2f6bff;
  --accent-soft: #e8efff;
  --ok: #12b76a;
  --ok-soft: #e7f8ef;
  --warn: #f79009;
  --warn-soft: #fef4e6;
  --bad: #f04438;
  --bad-soft: #feeceb;
  --s-todo: #98a2b3;
  --s-doing: #2f6bff;
  --s-ready: #7a5af8;
  --s-submitted: #f79009;
  --s-done: #12b76a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --panel: #161b22;
    --panel-2: #1b2129;
    --line: #2a313c;
    --line-strong: #3a4250;
    --text: #e6e9ef;
    --muted: #9aa4b2;
    --faint: #6b7584;
    --accent: #5b8cff;
    --accent-soft: #1d2a4a;
    --ok: #32d583;
    --ok-soft: #13301f;
    --warn: #fdb022;
    --warn-soft: #3a2a0c;
    --bad: #f97066;
    --bad-soft: #3d1a17;
    --s-todo: #6b7584;
    --s-doing: #5b8cff;
    --s-ready: #9b8afb;
    --s-submitted: #fdb022;
    --s-done: #32d583;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: flex; gap: 2px; padding: 7px; align-items: flex-start; flex: none; }
.logo i { display: block; width: 5px; border-radius: 2px; background: #fff; }
.logo i:nth-child(1) { height: 18px; }
.logo i:nth-child(2) { height: 13px; opacity: .8; }
.logo i:nth-child(3) { height: 8px; opacity: .6; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.sync.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.sync.err .dot { background: var(--bad); }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer;
  font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.plus { font-size: 16px; line-height: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--panel); display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 4px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; font-weight: 550;
}

main { padding: 20px 24px 48px; max-width: 1600px; margin: 0 auto; }

/* Quota cards */
.quota { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.qcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.qcard::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--ok); }
.qcard.cool::before { background: var(--warn); }
.qcard.out::before { background: var(--bad); }
.qhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.qname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qcount { font-size: 13px; color: var(--muted); white-space: nowrap; }
.qcount b { font-size: 20px; color: var(--text); font-weight: 700; }
.pips { display: flex; gap: 4px; margin: 10px 0 10px; }
.pips i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.pips i.used { background: var(--accent); }
.qcard.out .pips i.used { background: var(--bad); }
.qstate { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); }
.badge.muted { color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.badge.accent { color: var(--accent); background: var(--accent-soft); }
.qlast { margin-top: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qcard .qbtn { margin-top: 10px; width: 100%; justify-content: center; }

/* Summary bar */
.summary { display: flex; gap: 6px; align-items: center; margin: 18px 0 4px; flex-wrap: wrap; }
.progress { flex: 1 1 240px; height: 8px; border-radius: 4px; overflow: hidden; display: flex; background: var(--line); min-width: 160px; }
.progress span { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-left: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0; flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input[type=search], .filters select, .field input, .field select, .field textarea, .inline-select, .inline-input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); outline: none;
}
.filters input[type=search] { width: 220px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); user-select: none; }
.toggle input { accent-color: var(--accent); }

/* Kanban */
.board { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 220px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; font-weight: 650; }
.col-head .n { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.col-body { flex: 1; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; border-radius: 0 0 var(--radius) var(--radius); transition: background .15s; }
.col.over .col-body { background: var(--accent-soft); }
.empty { color: var(--faint); font-size: 12px; text-align: center; padding: 18px 0; border: 1px dashed var(--line-strong); border-radius: 10px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  box-shadow: var(--shadow); cursor: grab; transition: box-shadow .15s, transform .15s, border-color .15s;
}
.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-lg); }
.card.dragging { opacity: .45; transform: rotate(1deg); }
.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.pid { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 0 6px; border-radius: 5px; }
.gname { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { font-weight: 600; line-height: 1.4; word-break: break-word; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.owner { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
.owner.none { color: var(--faint); }
.claim { border: 1px dashed var(--line-strong); background: transparent; border-radius: 999px; font-size: 12px; padding: 1px 8px; cursor: pointer; color: var(--muted); }
.claim:hover { border-color: var(--accent); color: var(--accent); }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; flex: none; }
.chip .avatar { width: 26px; height: 26px; font-size: 12px; }

/* Table */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; cursor: pointer; user-select: none; }
th.nosort { cursor: default; }
th .arrow { color: var(--faint); margin-left: 3px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.title { white-space: normal; min-width: 220px; font-weight: 550; }
td.title button { all: unset; cursor: pointer; }
td.title button:hover { color: var(--accent); }
td.wrap { white-space: normal; min-width: 160px; color: var(--muted); }
.inline-select, .inline-input { height: 30px; font-size: 13px; }
.inline-input { width: 110px; }
.inline-input.score { width: 90px; }
.status-sel { padding-left: 8px; font-weight: 600; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* Submission log */
.day { margin-bottom: 18px; }
.day h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }

/* Feed */
.feed { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.feed-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.feed-item:last-child { border-bottom: 0; }
.feed-item .t { color: var(--faint); font-size: 12px; margin-left: auto; white-space: nowrap; }
.feed-item b { font-weight: 600; }

/* Modal */
dialog {
  border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(620px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: var(--shadow-lg); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
.m-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 6px; }
.m-head h2 { font-size: 17px; margin: 0; }
.m-body { padding: 10px 22px 6px; display: grid; gap: 14px; grid-template-columns: 1fr 1fr; overflow: auto; max-height: calc(100vh - 200px); }
.m-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 22px 18px; border-top: 1px solid var(--line); margin-top: 10px; }
.m-foot .right { display: flex; gap: 8px; margin-left: auto; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.field .hint { font-size: 12px; color: var(--faint); }
.notice { grid-column: 1 / -1; border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.mini-list { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.mini-list .row { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.mini-list .row:last-child { border-bottom: 0; }
.mini-list .row .grow { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { grid-column: 1 / -1; font-size: 13px; font-weight: 650; margin-top: 4px; display: flex; justify-content: space-between; align-items: center; }
.rules { grid-column: 1 / -1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.group-row { display: grid; grid-template-columns: 70px 1fr 70px 70px 56px; gap: 8px; align-items: center; }
.group-row input { height: 32px; padding: 0 8px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--panel); width: 100%; min-width: 0; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: pop .2s ease-out; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .brand h1 { font-size: 15px; }
  .btn#btnSubmit .label-long { display: none; }
  main { padding: 16px 16px 40px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .tabs { display: flex; }
  .tabs button { flex: 1; padding: 6px 4px; }
  .filters input[type=search] { width: 100%; flex: 1 1 100%; }
  .filters select { flex: 1 1 40%; min-width: 0; }
  .board { grid-template-columns: repeat(5, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .m-body { grid-template-columns: 1fr; }
  .chip .uname { display: none; }
  .chip { padding: 0 4px; }
  .group-row { grid-template-columns: 1fr 1fr; }
}

/* Spreadsheet view */
.sheet-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 160px); }
.sheet { table-layout: fixed; width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.sheet th { position: sticky; top: 0; z-index: 3; border-right: 1px solid var(--line); padding: 8px 10px; }
.sheet th.sticky { left: 0; z-index: 4; }
.sheet .cell { padding: 0; height: 38px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .cell:not(.edit) { padding: 0 10px; }
.sheet .cell.sticky { position: sticky; left: 0; background: var(--panel); z-index: 2; }
.sheet tr.row:hover .cell, .sheet tr.row:hover .cell.sticky { background: var(--panel-2); }
.sheet .num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet .small { font-size: 12px; }
.dim { color: var(--muted); }
.sheet .act { text-align: center; }
.sheet .pid { border: 0; cursor: pointer; }
.sheet .pid:hover { filter: brightness(.95); text-decoration: underline; }
.cell-input {
  width: 100%; height: 100%; min-height: 37px; border: 0; background: transparent; padding: 0 10px; outline: none;
  text-overflow: ellipsis; border-radius: 0;
}
.cell-input::placeholder { color: var(--faint); }
.cell-input:hover { background: var(--panel-2); }
.cell-input:focus { background: var(--panel); box-shadow: inset 0 0 0 2px var(--accent) !important; }
.sheet .inline-select { border-color: transparent; background: transparent; height: 28px; }
.sheet .inline-select:hover { border-color: var(--line-strong); }
.group-head td { background: var(--panel-2); border-bottom: 1px solid var(--line); padding: 0; position: sticky; left: 0; }
.gh { display: flex; align-items: center; gap: 10px; padding: 9px 12px; position: sticky; left: 0; width: max-content; max-width: 100vw; }
.gh-name { font-weight: 700; }
.gh-quota { font-size: 13px; color: var(--muted); }
.gh-quota b { color: var(--text); }
.gh-rules { font-size: 12px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-row .cell-input { color: var(--muted); font-size: 13px; }
.add-row .cell { background: var(--panel); }
.empty-cell { text-align: center; color: var(--faint); padding: 32px !important; }
.sheet-wrap .table-foot { position: sticky; left: 0; bottom: 0; background: var(--panel); }
