:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e4e0d8;
  --hover: #f1eee8;
  --accent: #d9670a;
  --accent-text: #ffffff;
  --accent-weak: #fdf0e4;
  --chip: #efece6;
  --good: #2f7d32;
  --warn: #9a6400;
  --bad: #b3261e;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --panel: #242320;
    --text: #ece9e3;
    --muted: #a39d93;
    --line: #3a3833;
    --hover: #2e2c28;
    --accent: #f08a2e;
    --accent-text: #1b1a18;
    --accent-weak: #3a2a1a;
    --chip: #33312c;
    --good: #7cc47f;
    --warn: #e0b04f;
    --bad: #f08a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 22px; line-height: 1.35; margin: 4px 0 10px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); }
.search { flex: 1; display: flex; gap: 8px; max-width: 760px; }
.search input { flex: 1; }
input[type=search], input[type=text], select {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  height: 34px; padding: 0 14px; border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text); cursor: pointer; white-space: nowrap;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--hover); }
button.small, a.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
a.btn {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line); color: var(--text); background: var(--panel); white-space: nowrap;
}
a.btn:hover { background: var(--hover); text-decoration: none; }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
#index-btn.attention { border-color: var(--accent); color: var(--accent); }

/* layout */
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 56px); }
.catalog { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; }
.catalog-filters { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.catalog-filters .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.catalog-filters select { flex: 1 1 160px; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.cat-list { overflow-y: auto; padding: 4px 0 24px; }
.cat-head {
  position: sticky; top: 0; padding: 10px 12px 4px; font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--panel);
}
.cat-item { display: block; padding: 7px 12px 7px 16px; color: var(--text); border-left: 3px solid transparent; }
.cat-item:hover { background: var(--hover); text-decoration: none; }
.cat-item.active { background: var(--accent-weak); border-left-color: var(--accent); }
.cat-name { display: block; }
.cat-meta { display: block; font-size: 12px; color: var(--muted); }
main { overflow-y: auto; padding: 20px 28px 48px; min-width: 0; }
.wrap { max-width: 1100px; }

/* blocks */
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 > .block { margin-bottom: 0; }
.grid2 + .block, .grid2 + .grid2 { margin-top: 14px; }
.eyebrow { font-size: 12px; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge { padding: 1px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; }
.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }
.evidence { white-space: pre-wrap; color: var(--muted); }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.list-plain li:first-child { border-top: 0; }
.grow { flex: 1; min-width: 0; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.quick a { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); background: var(--panel); }
.quick a:hover { background: var(--hover); text-decoration: none; }
.quick b { display: block; }

/* chips & toggles */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-size: 12px;
}
.chip.on { background: var(--accent-weak); border-color: var(--accent); color: var(--text); }
.chip input { margin: 0; }
.filters { display: grid; gap: 8px; margin-bottom: 14px; }
.filters .label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.filters > div { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scope { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--accent-weak); }
.scope button { height: 22px; padding: 0 8px; }
.query-preview { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; background: var(--bg); border-radius: 6px; padding: 6px 8px; word-break: break-all; margin: 8px 0; }

/* tables */
table.files { width: 100%; border-collapse: collapse; }
table.files th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 400; padding: 4px 8px; border-bottom: 1px solid var(--line); }
table.files td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.files tr:hover td { background: var(--hover); }
td.num { white-space: nowrap; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; }
.fname { display: flex; gap: 8px; align-items: baseline; }
.fname .open { color: var(--text); cursor: pointer; background: none; border: 0; padding: 0; height: auto; text-align: left; white-space: normal; }
.fname .open:hover { color: var(--accent); text-decoration: underline; }
.fname .plain { color: var(--text); }
.path { font-size: 12px; color: var(--muted); word-break: break-all; }
.ext { flex: none; min-width: 42px; text-align: center; font-size: 11px; padding: 0 4px; border-radius: 4px; background: var(--chip); color: var(--muted); text-transform: uppercase; }
.ext.dir { background: var(--accent-weak); color: var(--accent); }
.kind { font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--chip); white-space: nowrap; }
.kind.k-contract, .kind.k-accept { background: var(--accent-weak); color: var(--accent); }
.more { margin-top: 8px; }
.counts { margin: 4px 0 10px; color: var(--muted); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }
.loading { color: var(--muted); padding: 12px 0; }

/* dialog & toast */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); display: grid; place-items: center; z-index: 20; }
.dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 64px); overflow: auto; background: var(--panel); border-radius: 12px; padding: 16px 20px 20px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: var(--radius); max-width: min(720px, 90vw);
}

.loc { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 4px; background: var(--chip); color: var(--muted); font-size: 11px; white-space: nowrap; }

/* PIN page (public site) */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  display: grid; gap: 10px; width: min(320px, 100%); padding: 24px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.login-card .brand { margin-bottom: 6px; }
.login-card input { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); font-size: 20px; letter-spacing: 6px; text-align: center; }
.login-card button { height: 40px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .catalog { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .top { gap: 8px; padding: 0 12px; }
}
@media (max-width: 600px) {
  .top .brand { font-size: 0; gap: 0; }
  .search button { padding: 0 10px; }
  table.files th:nth-last-child(2), table.files th:nth-last-child(3), td.num { display: none; }
}
.mt6 { margin-top: 6px; }
.full { width: 100%; }
