:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --line: #e2e5ea;
  --accent: #f6821f;
  --accent-ink: #ffffff;
  --accent-soft: #fff2e6;
  --mark: #ffe08a;
  --danger: #d13b3b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 25, 40, .08), 0 8px 24px rgba(20, 25, 40, .06);
}
:root[data-theme="dark"] {
  --bg: #14171d;
  --panel: #1c2027;
  --ink: #e8eaf0;
  --ink-soft: #9aa3b2;
  --line: #2c313b;
  --accent: #f6821f;
  --accent-soft: #3a2a17;
  --mark: #7a5a12;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d; --panel: #1c2027; --ink: #e8eaf0; --ink-soft: #9aa3b2;
    --line: #2c313b; --accent-soft: #3a2a17; --mark: #7a5a12;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; cursor: pointer; white-space: nowrap; }
.search-wrap { flex: 0 1 420px; }
#q {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg); outline: none;
}
#q:focus { border-color: var(--accent); }
.spacer { flex: 1; }
.whoami { color: var(--ink-soft); font-size: 12px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.icon { padding: 7px 10px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

.new-menu { position: relative; }
.new-pop {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 160px; overflow: hidden; z-index: 30;
}
.new-pop[hidden] { display: none; }
.new-pop button { text-align: left; padding: 9px 14px; background: none; border: 0; cursor: pointer; }
.new-pop button:hover { background: var(--accent-soft); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.filters { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.filters select { flex: 1; min-width: 0; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.list-meta { display: flex; justify-content: space-between; padding: 6px 12px; color: var(--ink-soft); font-size: 12px; }
.mode { text-transform: none; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--accent-soft); }
.list li.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.li-title { font-weight: 600; margin-bottom: 3px; }
.li-sub { color: var(--ink-soft); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.li-snip { color: var(--ink-soft); font-size: 12px; margin-top: 4px; max-height: 2.8em; overflow: hidden; }
.li-snip mark, .md mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 2px; }
#more { margin: 10px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--line); white-space: nowrap;
}
.badge.t-case { background: #eaf3ff; color: #1a5fb4; border-color: #cfe2fb; }
.badge.t-investigation { background: #f0eaff; color: #6b3fb4; border-color: #ddd0fb; }
.badge.t-verification { background: #e9f8ee; color: #1c7d3f; border-color: #cdeed7; }
.badge.t-note { background: #f1f2f4; color: #5b6472; }
.badge.s-open { color: #b4670e; }
.badge.s-resolved { color: #1c7d3f; }
.badge.s-wontfix { color: var(--ink-soft); }
:root[data-theme="dark"] .badge.t-case,
:root[data-theme="dark"] .badge.t-investigation,
:root[data-theme="dark"] .badge.t-verification { background: #262b34; color: var(--ink); border-color: var(--line); }

/* ---------- pane ---------- */
.pane { overflow-y: auto; padding: 24px 28px; min-height: 0; }
.empty { color: var(--ink-soft); margin-top: 40px; }
.doc { max-width: 820px; margin: 0 auto; }
.doc h1.title { font-size: 22px; margin: 0 0 10px; }
.metatable { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 13px; }
.metatable th, .metatable td { text-align: left; padding: 6px 10px; border: 1px solid var(--line); vertical-align: top; }
.metatable th { background: var(--bg); width: 110px; color: var(--ink-soft); font-weight: 600; }
.doc-actions { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }

.md { word-wrap: break-word; }
.md img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--ink-soft); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; }
.md h2 { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 28px; }

/* ---------- editor ---------- */
.form { max-width: 900px; margin: 0 auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--ink-soft); }
.field input, .field select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; }
.editor-actions { display: flex; gap: 8px; margin: 14px 0; }
.EasyMDEContainer .CodeMirror { border-radius: 8px; border-color: var(--line); background: var(--panel); color: var(--ink); }
.editor-toolbar { border-color: var(--line); }
:root[data-theme="dark"] .editor-toolbar button { color: var(--ink) !important; }
:root[data-theme="dark"] .editor-preview, :root[data-theme="dark"] .editor-preview-side { background: var(--panel); }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.banner.warn { background: #fff6e6; border-color: #f3d18a; color: #8a5a06; }
.banner.err { background: #fdeaea; border-color: #f0b4b4; color: var(--danger); }

.rev-list { list-style: none; padding: 0; margin: 0; max-width: 820px; }
.rev-list li { display: flex; gap: 10px; align-items: baseline; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.rev-list .when { font-weight: 600; }
.rev-list .who { color: var(--ink-soft); font-size: 12px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .search-wrap { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
}
