@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans+Thai:wght@400;500;600&display=swap');

/* ---------- tokens (see .claude/skills/brand) ---------- */
:root {
  --bg: #FAFAF9; --surface: #FFFFFF; --surface-2: #F2F2EF; --border: #E4E4E0;
  --text: #1C1D21; --text-muted: #62646B; --accent: #3B5BDB;
  --asset-equity: #2563EB; --asset-gold: #B7791F; --asset-bond: #15803D; --asset-crypto: #7C3AED; --asset-stable: #6B7280;
  --up: #0F766E; --down: #B91C1C;
  --font: 'IBM Plex Sans Thai', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 8px;
  --topbar-h: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1115; --surface: #171A21; --surface-2: #1F232C; --border: #2A2F3A;
    --text: #E7E8EC; --text-muted: #9A9DA6; --accent: #7C93F0;
    --asset-equity: #60A5FA; --asset-gold: #F6C453; --asset-bond: #4ADE80; --asset-crypto: #A78BFA; --asset-stable: #9CA3AF;
    --up: #2DD4BF; --down: #F87171;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1115; --surface: #171A21; --surface-2: #1F232C; --border: #2A2F3A;
  --text: #E7E8EC; --text-muted: #9A9DA6; --accent: #7C93F0;
  --asset-equity: #60A5FA; --asset-gold: #F6C453; --asset-bond: #4ADE80; --asset-crypto: #A78BFA; --asset-stable: #9CA3AF;
  --up: #2DD4BF; --down: #F87171;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; letter-spacing: .01em; margin-right: 8px; }
.crumb { font-family: var(--mono); font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.status { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.status.dirty { color: var(--asset-gold); }
.actions { display: flex; gap: 6px; align-items: center; }
#menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 220px; min-height: calc(100vh - var(--topbar-h)); }
.layout.editing { grid-template-columns: 260px minmax(0, 1fr); }
.layout.editing #toc { display: none; }

#sidebar {
  border-right: 1px solid var(--border); background: var(--surface-2);
  padding: 12px; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.group-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 14px 8px 4px; }
.file-link {
  display: block; padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--text);
  font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-link .dir { color: var(--text-muted); }
.file-link:hover { background: var(--surface); }
.file-link.active { background: var(--surface); color: var(--accent); font-weight: 500; box-shadow: inset 2px 0 0 var(--accent); }

main { min-width: 0; padding: 32px 40px 80px; }
#toc { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 32px 16px; font-size: 13px; }
#toc .toc-title { font-weight: 600; color: var(--text-muted); margin-bottom: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
#toc a { display: block; color: var(--text-muted); text-decoration: none; padding: 3px 0; line-height: 1.4; }
#toc a:hover { color: var(--accent); }
#toc a.lvl-3 { padding-left: 12px; }

/* ---------- markdown ---------- */
.md { max-width: 78ch; margin: 0 auto; }
.md h1 { font-size: 1.9rem; line-height: 1.3; margin: 0 0 .6em; font-weight: 600; }
.md h2 { font-size: 1.4rem; line-height: 1.35; margin: 2em 0 .6em; padding-bottom: .3em; border-bottom: 1px solid var(--border); font-weight: 600; }
.md h3 { font-size: 1.15rem; margin: 1.6em 0 .5em; font-weight: 600; }
.md h4 { font-size: 1rem; margin: 1.4em 0 .4em; }
.md p, .md ul, .md ol { margin: 0 0 1em; }
.md li + li { margin-top: .2em; }
.md blockquote {
  margin: 0 0 1em; padding: 10px 16px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-muted);
}
.md blockquote p:last-child { margin-bottom: 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.md .table-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--border); border-radius: var(--radius); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.md input[type="checkbox"] { margin-right: 6px; }
.md img { max-width: 100%; }

/* ---------- editor ---------- */
#editor { display: grid; grid-template-columns: 1fr 1fr; gap: 0; height: calc(100vh - var(--topbar-h) - 32px); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
#editor textarea {
  width: 100%; height: 100%; resize: none; border: 0; outline: none; padding: 20px;
  font-family: var(--mono); font-size: 14px; line-height: 1.65; background: var(--surface); tab-size: 2;
}
#editor .preview { border-left: 1px solid var(--border); overflow-y: auto; padding: 20px 28px; background: var(--bg); }
.layout.editing main { padding: 16px; }
.edit-tabs { display: none; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 12px; }
.dlg-head h2 { margin: 0; font-size: 1.05rem; }
.dlg-body { padding: 18px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.field label { display: block; font-size: 14px; margin-bottom: 6px; }
.field input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.hint { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.error { color: var(--down); font-size: 14px; min-height: 1.4em; margin-top: 8px; }

/* ---------- git graph ---------- */
.git-body { max-height: 70vh; overflow: auto; padding: 8px 0; }
.git-row { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: baseline; padding: 0 18px; font-size: 13px; line-height: 1.75; white-space: nowrap; }
.git-row:hover { background: var(--surface-2); }
.git-graph { font-family: var(--mono); white-space: pre; }
.git-meta { overflow: hidden; text-overflow: ellipsis; }
.git-hash { font-family: var(--mono); color: var(--accent); margin-right: 8px; }
.git-subject { margin-right: 8px; }
.git-author, .git-date { color: var(--text-muted); margin-right: 8px; }
.git-ref { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); margin-right: 6px; color: var(--asset-bond); }
.lane-0 { color: var(--accent); } .lane-1 { color: var(--asset-gold); } .lane-2 { color: var(--asset-bond); }
.lane-3 { color: var(--asset-crypto); } .lane-4 { color: var(--down); } .lane-5 { color: var(--asset-stable); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-muted); cursor: pointer; }

/* ---------- states ---------- */
.empty { color: var(--text-muted); text-align: center; padding: 60px 20px; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}
#toast.err { background: var(--down); color: #fff; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-card h1 { font-size: 1.35rem; margin: 0 0 4px; }
.login-card p { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; }
.login-card .field + .field { margin-top: 14px; }
.login-card .btn { width: 100%; justify-content: center; height: 42px; margin-top: 18px; }
.login-theme { position: fixed; top: 12px; right: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  #toc { display: none; }
}
@media (max-width: 768px) {
  #menu-btn { display: inline-flex; }
  .brand { display: none; }
  .btn .label { display: none; }
  .btn:not(.icon):has(.label) { width: 34px; padding: 0; justify-content: center; }
  .status { display: none; }
  .layout, .layout.editing { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 82vw; max-width: 300px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.25); height: auto; }
  #sidebar.open { transform: none; }
  main { padding: 20px 16px 60px; }
  .md h1 { font-size: 1.5rem; }
  #editor { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - 80px); }
  #editor .preview { border-left: 0; }
  #editor[data-tab="edit"] .preview, #editor[data-tab="preview"] textarea { display: none; }
  .edit-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
  .edit-tabs .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
}
