:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #6b6b6b;
  --line: #dedbd4;
  --accent: #3d6b5c;
  --accent-text: #ffffff;
  --ok-bg: #eaf3ee;
  --warn-bg: #fbf1e0;
  --err: #b3261e;
  --err-bg: #fceceb;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1c1b; --card: #252726; --text: #ececec; --muted: #a4a4a4; --line: #3a3d3b;
    --accent: #6fae98; --accent-text: #12201a; --ok-bg: #223229; --warn-bg: #3a3122;
    --err: #f2b8b5; --err-bg: #3b2321;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}
.layout { display: flex; min-height: 100vh; }
.side {
  flex: 0 0 200px; padding: 24px 12px; background: var(--card); border-right: 1px solid var(--line);
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
}
.brand { font-size: 1.2rem; font-weight: 700; padding: 0 12px 20px; }
.brand span { display: block; font-size: 0.78rem; font-weight: 400; color: var(--muted); }
.nav-item {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none;
}
.nav-item:hover { background: var(--bg); }
.nav-item[aria-current="page"] { background: var(--ok-bg); color: var(--accent); font-weight: 600; }
.content { flex: 1; min-width: 0; }
.side { display: flex; flex-direction: column; }
.me { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); }
.me-name { font-weight: 600; word-break: break-all; }
button.small { min-height: 32px; padding: 4px 12px; margin-top: 8px; font-size: 0.88rem; }
.page { display: grid; gap: 16px; }
[hidden] { display: none !important; }
.btn-link {
  display: block; text-align: center; text-decoration: none; padding: 11px 18px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); margin-top: 8px;
}
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); }
.login-card .brand { padding: 0 0 8px; font-size: 1.4rem; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 20px; max-width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
td select { min-height: 34px; padding: 4px 8px; width: auto; }
td button { min-height: 34px; padding: 4px 12px; }
td .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag.pending { background: var(--warn-bg); }
.tag.disabled { background: var(--err-bg); color: var(--err); }
header, main { max-width: 860px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 28px; padding-bottom: 8px; }
h1 { margin: 0; font-size: 1.5rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
.sub, .hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }
main { display: grid; gap: 16px; padding-bottom: 48px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

.row { display: flex; gap: 8px; }
.field { margin-bottom: 12px; }
.field label, .label { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; }
.field .opt { font-size: 0.8rem; color: var(--muted); }

input, select, button { font: inherit; }
input[type="text"], input[type="search"], select {
  width: 100%; padding: 9px 11px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; min-height: 42px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  padding: 9px 18px; min-height: 42px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); white-space: nowrap;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; color: var(--text); border-radius: 0; min-height: 38px; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); }

.preview { margin: 16px 0; padding: 12px 14px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; }
.preview-label { font-size: 0.8rem; color: var(--muted); }
.preview-name { font-size: 1.05rem; word-break: break-all; margin-top: 2px; }
.preview-problem { font-size: 0.85rem; color: var(--muted); margin-top: 2px; min-height: 1.2em; }

.result { margin-top: 12px; padding: 12px 14px; border-radius: 8px; background: var(--warn-bg); }
.result.ok { background: var(--ok-bg); }
.result-title { margin-bottom: 4px; }
.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy-row code { flex: 1 1 260px; word-break: break-all; font-size: 0.95rem; }
.error { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--err-bg); color: var(--err); }

.filters { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 8px; margin-bottom: 8px; }
.table-wrap { overflow-x: auto; margin-top: 8px; max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--card); font-weight: 600; }
td.code { font-variant-numeric: tabular-nums; white-space: nowrap; }
th { white-space: nowrap; }
.tag { white-space: nowrap; display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 0.78rem; background: var(--ok-bg); }
.tag.void { background: var(--warn-bg); color: var(--muted); }
tr.void td { color: var(--muted); }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .side { flex: none; position: static; height: auto; width: 100%; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 0 8px; }
  nav { display: flex; gap: 4px; overflow-x: auto; }
}
@media (max-width: 560px) {
  .filters { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
}
