/* Memex web UI — one stylesheet, design tokens as CSS variables.
   Dark by default (every panel is a rounded card on a darker background);
   the light theme only overrides the tokens. */

:root {
  --bg: #0f0f10;
  --card: #1a1a1b;
  --card-2: #212123;
  --hover: #242427;
  --active: #26303b;
  --border: #2a2a2c;
  --border-strong: #3a3a3e;
  --text: #e8e8ea;
  --muted: #a0a0a7;
  --faint: #74747c;
  --accent: #6cb6ff;
  --accent-text: #6cb6ff;
  --accent-soft: rgba(108, 182, 255, 0.14);
  --on-accent: #0c1622;
  --ok: #5fd39a;
  --ok-soft: rgba(95, 211, 154, 0.16);
  --warn: #e3b85c;
  --warn-soft: rgba(227, 184, 92, 0.16);
  --danger: #f2777a;
  --danger-soft: rgba(242, 119, 122, 0.14);
  --code: #d7ba7d;
  --selection: rgba(108, 182, 255, 0.28);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 6px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #efefec;
  --card: #ffffff;
  --card-2: #f5f5f3;
  --hover: #f0f0ee;
  --active: #e3effc;
  --border: #e2e2de;
  --border-strong: #cfcfca;
  --text: #1b1b1e;
  --muted: #5d5d66;
  --faint: #85858e;
  --accent: #6cb6ff;
  --accent-text: #1767b8;
  --accent-soft: rgba(48, 136, 224, 0.13);
  --on-accent: #0c1622;
  --ok: #17824f;
  --ok-soft: rgba(23, 130, 79, 0.12);
  --warn: #96690a;
  --warn-soft: rgba(190, 140, 20, 0.16);
  --danger: #c5383c;
  --danger-soft: rgba(197, 56, 60, 0.1);
  --code: #8a5a00;
  --selection: rgba(48, 136, 224, 0.22);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 6px; }
::selection { background: var(--selection); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

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

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logo { flex: none; }
.logo path { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.logo .logo-human { stroke: #c9c9cc; }
:root[data-theme="light"] .logo .logo-human { stroke: #3b3b40; }
.logo .logo-ai { stroke: var(--accent); }
.logo .logo-node { fill: var(--accent); }
.logo.mono path { stroke: currentColor; }
.logo.mono .logo-node { fill: currentColor; }

/* ---------- buttons and form controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none !important;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; min-height: 38px; }
.btn.small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.small { width: 22px; height: 22px; }
.icon-btn.small .icon { width: 13px; height: 13px; }
.icon-btn.boxed { border: 1px solid var(--border); background: var(--card-2); }
.icon-btn.on { color: var(--accent-text); background: var(--accent-soft); }

.link-btn { border: 0; padding: 0; background: none; color: var(--accent-text); }
.link-btn:hover { text-decoration: underline; }
.link-btn.active { color: var(--text); font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"],
input[type="search"], input[type="tel"], textarea, .select {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus-visible, textarea:focus-visible, .select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.select { width: auto; padding-right: 26px; background: var(--card-2); min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; flex: none; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.field-hint { font-size: 12px; color: var(--faint); }
.check { display: flex; align-items: center; gap: 8px; }
.check.disabled { color: var(--faint); }
.form { display: flex; flex-direction: column; gap: 14px; }
.form h1 { font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 8px 10px; }
.notice { background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; color: var(--muted); overflow-wrap: anywhere; }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.notice.ok { background: var(--ok-soft); border-color: transparent; color: var(--text); }
.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: var(--mono); font-size: 12px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill.neutral { background: var(--card-2); color: var(--muted); border: 1px solid var(--border); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.accent { background: var(--accent); }
.dot.off { background: var(--danger); }
.ai-name { color: var(--accent-text); font-weight: 500; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: #2c3e57; color: #dbe9fb; font-size: 10px; font-weight: 700; letter-spacing: 0.02em; flex: none; }
.avatar.ai { background: var(--accent-soft); color: var(--accent-text); }
:root[data-theme="light"] .avatar { background: #d9e6f7; color: #1b3a61; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--card-2); border: 1px solid var(--border); color: var(--faint); }
.empty-icon .icon { width: 20px; height: 20px; }
.empty-title { color: var(--text); font-weight: 600; font-size: 15px; }
.empty-hint { max-width: 46ch; }

.skeleton { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
.skeleton-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--card-2), var(--hover), var(--card-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line { animation: none; } }

/* ---------- boot frame (also in index.html: no layout shift) ---------- */

.boot { display: grid; grid-template-columns: 44px 232px 1fr; gap: var(--gap); padding: var(--gap); height: 100vh; height: 100dvh; }
@media (max-width: 720px) { .boot { grid-template-columns: 1fr; } .boot-bar, .boot-side { display: none; } .boot-main { border: 0; background: transparent; } }

/* ---------- auth screens ---------- */

.auth { height: 100vh; height: 100dvh; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 56px 16px 32px; gap: 22px; }
.auth-brand { display: flex; align-items: center; gap: 8px; }
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.auth-card { width: 100%; max-width: 440px; padding: 26px 28px; }
.auth-card.wide { max-width: 480px; }
.auth-foot { color: var(--faint); font-size: 12px; text-align: center; }
.lang-links { display: inline-flex; gap: 8px; }
.lang-links .link-btn { color: var(--faint); }
.lang-links .link-btn.active { color: var(--muted); }

.consent h1 { font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; }
.consent-brain { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); font-weight: 600; margin: 4px 2px -6px; }
.consent-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card); }
.consent-row { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 6px 12px 6px 14px; border-top: 1px solid var(--border); }
.consent-row:first-child { border-top: 0; }
.consent-row label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; font-size: 14.5px; cursor: pointer; }
.consent-row.off label { color: var(--faint); cursor: default; }
.consent-row .select { min-width: 150px; font-size: 12.5px; }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.consent-actions .btn { min-height: 38px; font-size: 14px; }

/* ---------- desktop shell ---------- */

.shell {
  display: grid;
  grid-template-columns: 44px var(--explorer-w, 232px) minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: var(--gap);
  height: 100vh;
  height: 100dvh;
}
.shell.no-explorer { grid-template-columns: 44px minmax(0, 1fr) auto; }

.activity { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; min-height: 0; }
.activity .brand { display: grid; place-items: center; width: 30px; height: 30px; margin-bottom: 6px; border-radius: 8px; }
.act-btn { position: relative; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--faint); }
.act-btn:hover { color: var(--text); background: var(--hover); text-decoration: none; }
.act-btn.active { color: var(--accent-text); background: var(--active); }
.activity .spacer { flex: 1; }
.avatar-btn { border: 0; padding: 0; background: none; border-radius: 50%; }
.avatar-btn .avatar { width: 28px; height: 28px; }

.explorer { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.explorer-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 6px 10px; }
.brain-switch { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1; padding: 4px 6px; border: 0; border-radius: 7px; background: transparent; font-weight: 650; font-size: 13.5px; text-align: left; }
.brain-switch:hover { background: var(--hover); }
.brain-switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brain-switch .icon { width: 12px; height: 12px; color: var(--faint); }
.tree { flex: 1; overflow: auto; padding: 2px 6px 10px; min-height: 0; }
.tree.drop-root { box-shadow: inset 0 0 0 2px var(--accent-soft); border-radius: 8px; }
.tree-row { display: flex; align-items: center; gap: 4px; height: 27px; padding-right: 6px; border-radius: 7px; color: var(--text); cursor: pointer; user-select: none; white-space: nowrap; text-decoration: none !important; }
.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--active); }
.tree-row.drop { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tree-row .chev { width: 14px; height: 14px; display: grid; place-items: center; color: var(--faint); flex: none; }
.tree-row .chev .icon { width: 11px; height: 11px; }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-row.file .name { color: var(--muted); }
.tree-row.file.active .name, .tree-row.file:hover .name { color: var(--text); }
.tree-row .lock { color: var(--faint); display: grid; }
.tree-row .lock .icon { width: 11px; height: 11px; }
.tree-row .ext { color: var(--faint); font-size: 10.5px; font-family: var(--mono); }
.explorer-foot { border-top: 1px solid var(--border); padding: 9px 12px 10px; color: var(--muted); font-size: 11.5px; display: flex; flex-direction: column; gap: 3px; }
.explorer-foot .sync { display: flex; align-items: center; gap: 6px; }
.explorer-foot .host { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resizer { position: absolute; top: 12px; bottom: 12px; right: -5px; width: 5px; cursor: col-resize; z-index: 3; border-radius: 3px; }
.resizer:hover, .resizer.dragging { background: var(--accent-soft); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.tabbar { display: flex; align-items: stretch; height: 36px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--border); flex: none; gap: 8px; }
.tabs { display: flex; align-items: stretch; gap: 2px; min-width: 0; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tab { position: relative; display: flex; align-items: center; gap: 6px; padding: 0 4px 0 8px; margin-left: -8px; margin-right: 8px; color: var(--muted); white-space: nowrap; text-decoration: none !important; border: 0; background: none; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 600; }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 4px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.tab .tab-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.tab .tab-close { width: 16px; height: 16px; border: 0; border-radius: 4px; background: none; color: var(--faint); display: grid; place-items: center; padding: 0; opacity: 0; }
.tab .tab-close .icon { width: 10px; height: 10px; }
.tab:hover .tab-close, .tab.active .tab-close, .tab .tab-close:focus-visible { opacity: 1; }
.tab .tab-close:hover { background: var(--hover); color: var(--text); }
.tab .dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.tabbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.cmd-btn { display: inline-flex; align-items: center; gap: 8px; height: 24px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--card-2); color: var(--muted); font-size: 12px; }
.cmd-btn:hover { color: var(--text); border-color: var(--border-strong); }
.cmd-btn kbd { font-family: var(--font); font-size: 10.5px; color: var(--faint); }
.main-body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.main-body.flush { overflow: hidden; display: flex; flex-direction: column; }

.right { display: flex; flex-direction: column; gap: var(--gap); width: 232px; min-height: 0; overflow: auto; }
.info-card { padding: 11px 12px 10px; flex: none; }
.info-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.info-title .count { color: var(--faint); font-weight: 500; }
.info-list { display: flex; flex-direction: column; gap: 1px; margin: 0 -6px; }
.info-item { display: flex; align-items: baseline; gap: 5px; padding: 4px 6px; border-radius: 6px; color: var(--text); font-size: 12.5px; border: 0; background: none; text-align: left; width: 100%; min-width: 0; text-decoration: none !important; }
.info-item:hover { background: var(--hover); }
.info-item.active { background: var(--active); }
.info-item > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-item .sub { color: var(--muted); flex: none; }
.info-item.unresolved { color: var(--faint); }
.info-sub { font-size: 11px; color: var(--faint); font-weight: 600; margin: 8px 0 3px; }
.info-empty { color: var(--faint); font-size: 12px; padding: 2px 0; }
.info-more { font-size: 12px; margin-top: 4px; display: inline-block; }

/* ---------- note ---------- */

.note { max-width: 760px; margin: 0 auto; padding: 26px 40px 80px; }
.note-head { display: flex; align-items: center; gap: 8px; min-height: 28px; margin-bottom: 6px; }
.breadcrumb { color: var(--muted); font-size: 12.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { margin: 0 5px; color: var(--faint); }
.note-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.note-title { font-size: 28px; line-height: 1.2; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0 16px; overflow-wrap: anywhere; }
.presence { display: inline-flex; align-items: center; gap: 5px; padding: 1px 7px; border-radius: 5px; background: var(--ok-soft); color: var(--ok); font-size: 11px; font-weight: 600; white-space: nowrap; }
.presence.ai { background: var(--accent-soft); color: var(--accent-text); }
.presence .icon { width: 11px; height: 11px; }
.save-state { color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 14px; border-radius: 10px; background: var(--warn-soft); }
.banner .grow { min-width: 12ch; }

.props { display: grid; grid-template-columns: minmax(84px, max-content) 1fr; gap: 0; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; margin: 0 0 18px; }
.props dt, .props dd { margin: 0; padding: 5px 0; min-height: 30px; display: flex; align-items: center; }
.props dt { color: var(--muted); padding-right: 28px; }
.props dd { flex-wrap: wrap; gap: 4px 8px; overflow-wrap: anywhere; min-width: 0; }
.props .tag { color: var(--accent-text); }

.md { font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 26px 0 10px; line-height: 1.3; letter-spacing: -0.01em; }
.md h1 { font-size: 24px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 16.5px; }
.md h4, .md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { padding-left: 24px; }
.md li { margin: 3px 0; }
.md li > p { margin: 0; }
.md li:has(> input.task), .md li:has(> p > input.task) { list-style: none; margin-left: -20px; padding: 3px 0; }
.md input.task { margin: 0 12px 0 0; vertical-align: -2px; cursor: pointer; }
.md input.task:disabled { cursor: default; }
.md li:has(> input.task:checked), .md li:has(> p > input.task:checked) { color: var(--faint); text-decoration: line-through; }
.md li:has(> input.task:checked) ul { text-decoration: none; }
.md a.internal { color: var(--accent-text); }
.md a.unresolved { color: var(--faint); border-bottom: 1px dashed var(--faint); }
.md a.unresolved:hover { color: var(--accent-text); text-decoration: none; }
.md .blocked-link { color: var(--muted); border-bottom: 1px dotted var(--faint); }
.md .missing-embed { color: var(--faint); border: 1px dashed var(--border-strong); border-radius: 6px; padding: 0 6px; font-size: 13px; }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--card-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; color: var(--code); }
.md pre { background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow: auto; }
.md pre code { background: none; border: 0; padding: 0; color: var(--text); font-size: 13px; }
.md blockquote { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 14px; color: var(--muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--card-2); font-weight: 600; }
.md del { color: var(--faint); }
.md .footnote-definition { display: flex; gap: 8px; font-size: 13px; color: var(--muted); }
.md .footnote-definition p { margin: 0; }
.md sup { font-size: 0.75em; }

.editor-host { min-height: 50vh; }
.editor-host .cm-editor { min-height: 50vh; }
.editor-fallback { width: 100%; min-height: 60vh; resize: vertical; font-family: var(--mono); font-size: 14px; line-height: 1.6; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 12px; }

.viewer { padding: 20px 28px 60px; display: flex; flex-direction: column; gap: 14px; height: 100%; }
.viewer-media { flex: 1; min-height: 0; display: grid; place-items: center; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; overflow: auto; padding: 12px; }
.viewer-media img, .viewer-media video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.viewer-media iframe { width: 100%; height: 100%; min-height: 60vh; border: 0; border-radius: 6px; background: #fff; }
.viewer-media audio { width: min(520px, 100%); }
.viewer-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 13px; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow: auto; }
.download-card { display: flex; align-items: center; gap: 14px; padding: 16px; max-width: 520px; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; }

/* ---------- folder / home view ---------- */

.folder { max-width: 760px; margin: 0 auto; padding: 26px 40px 80px; display: flex; flex-direction: column; gap: 16px; }
.folder-title { display: flex; align-items: center; gap: 10px; }
.folder-title h1 { font-size: 28px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; overflow-wrap: anywhere; }
.folder-sub { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 12.5px; margin-top: -10px; }
.section-label { color: var(--muted); font-size: 12px; font-weight: 500; margin: 6px 4px -8px; }
.list { background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none !important; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list-row:first-child { border-top: 0; }
.list-row:hover { background: var(--hover); }
.list-row .title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { color: var(--muted); font-size: 12.5px; margin-left: auto; flex: none; display: flex; align-items: center; gap: 8px; }
.list-row .meta .icon { width: 13px; height: 13px; color: var(--faint); }
.list-row .folder-ico { color: var(--accent-text); display: grid; }
.list-row .folder-ico .icon { width: 19px; height: 19px; }
.badge-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.badge-ico .icon { width: 16px; height: 16px; stroke-width: 2; }
.badge-ico.c0 { background: #3b82f6; }
.badge-ico.c1 { background: #8b5cf6; }
.badge-ico.c2 { background: #10b981; }
.badge-ico.c3 { background: #f59e0b; }
.badge-ico.c4 { background: #ec4899; }
.badge-ico.c5 { background: #14b8a6; }
.badge-ico.big { width: 34px; height: 34px; border-radius: 9px; }
.recent-row { flex-direction: column; align-items: stretch; gap: 2px; padding: 11px 14px; }
.recent-row .top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.recent-row .excerpt { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.recent-row .foot { color: var(--faint); font-size: 12px; }
.resume { display: flex; flex-direction: column; gap: 2px; padding: 14px 124px 14px 16px; min-height: 92px; justify-content: center; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none !important; position: relative; overflow: hidden; }
.resume:hover { border-color: var(--border-strong); }
.resume .kicker { display: flex; align-items: center; gap: 6px; color: var(--accent-text); font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.resume .kicker .icon { width: 13px; height: 13px; }
.resume .title { font-size: 17px; font-weight: 700; line-height: 1.25; }
.resume .by { color: var(--muted); font-size: 12.5px; }
.resume .deco { position: absolute; right: 8px; top: 6px; width: 110px; height: 80px; color: var(--faint); opacity: 0.9; }
.ai-line { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none !important; font-weight: 600; }
.ai-line .ai-ico { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); flex: none; }
.ai-line .icon.chev { margin-left: auto; color: var(--faint); }
.searchbox { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 14px; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); width: 100%; text-align: left; font-size: 14.5px; }
.searchbox input { border: 0; background: none; padding: 0; min-height: 40px; }
.searchbox input:focus-visible { outline: none; }
.searchbox:focus-within { border-color: var(--accent); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--border); }
.segmented button, .segmented a { border: 0; border-radius: 7px; background: none; min-height: 30px; color: var(--muted); font-weight: 600; display: grid; place-items: center; text-decoration: none !important; }
.segmented .on { background: var(--border-strong); color: var(--text); }

/* ---------- dialogs, menus, toasts ---------- */

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; overflow: auto; }
.dialog { width: 100%; max-width: 460px; box-shadow: var(--shadow); }
.dialog.wide { max-width: 640px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 4px 20px; }
.dialog-head h2 { font-size: 16px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.dialog-body { padding: 10px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.menu { position: fixed; z-index: 60; min-width: 190px; padding: 5px; background: var(--card-2); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 30px; padding: 4px 9px; border: 0; border-radius: 6px; background: none; color: var(--text); text-align: left; text-decoration: none !important; white-space: nowrap; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item .icon { color: var(--muted); width: 14px; height: 14px; }
.menu-item.danger .icon { color: var(--danger); }
.menu-item .check { margin-left: auto; color: var(--accent-text); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.menu-label { font-size: 11px; color: var(--faint); padding: 4px 9px 2px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.menu-backdrop { position: fixed; inset: 0; z-index: 59; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 14px; background: var(--card-2); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); animation: toast-in 0.16s ease-out; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.toast.success { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.toast-text { flex: 1; overflow-wrap: anywhere; }
.toast-link { white-space: nowrap; font-weight: 600; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

.palette { width: 100%; max-width: 600px; box-shadow: var(--shadow); overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.palette-input input { border: 0; background: none; min-height: 48px; padding: 0; font-size: 15px; }
.palette-input input:focus-visible { outline: none; }
.palette-list { max-height: min(56vh, 460px); overflow: auto; padding: 6px; }
.palette-section { font-size: 11px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 5px 10px; border: 0; border-radius: 7px; background: none; text-align: left; color: var(--text); }
.palette-item.sel { background: var(--active); }
.palette-item .icon { color: var(--muted); }
.palette-item .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .detail { color: var(--faint); font-size: 12px; margin-left: auto; flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .col { display: flex; flex-direction: column; min-width: 0; }
.palette-item .snippet { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item b { color: var(--accent-text); font-weight: 600; }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.palette-foot { display: flex; gap: 14px; padding: 7px 14px; border-top: 1px solid var(--border); color: var(--faint); font-size: 11.5px; }
.palette-foot kbd, .kbd { font-family: var(--font); font-size: 10.5px; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--card-2); color: var(--muted); }

/* ---------- pages inside the main card ---------- */

.page { max-width: 900px; margin: 0 auto; padding: 26px 40px 80px; display: flex; flex-direction: column; gap: 18px; }
.page.wide { max-width: 1080px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
.subnav { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 2px; }
.subnav a { padding: 7px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--text); border-bottom-color: var(--accent); }
.panel { background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.panel h2 { font-size: 14.5px; font-weight: 650; }
.panel h3 { font-size: 13px; font-weight: 600; color: var(--muted); }
.panel > .muted { margin-top: -8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.table-wrap { overflow-x: auto; margin: 0 -6px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; padding: 6px; white-space: nowrap; }
.table td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: middle; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions > * { margin-left: 4px; }
.table .who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.table .who .names { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.table .who .names small { color: var(--muted); }
.table td.center, .table th.center { text-align: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.grant-row { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 0; border-top: 1px solid var(--border); }
.grant-row:first-child { border-top: 0; }
.grant-row .names { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.grant-row .names small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.theme-choice { display: grid; grid-template-columns: repeat(2, minmax(0, 180px)); gap: 12px; }
.theme-card { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); text-align: left; }
.theme-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-swatch { height: 64px; border-radius: 7px; border: 1px solid var(--border); display: grid; grid-template-columns: 14px 34px 1fr; gap: 3px; padding: 3px; }
.theme-swatch i { border-radius: 3px; }

.search-page .hit { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none !important; }
.search-page .hit:first-child { border-top: 0; }
.search-page .hit:hover { background: var(--hover); }
.search-page .hit .title { font-weight: 600; }
.search-page .hit .path { color: var(--faint); font-size: 12px; }
.search-page .hit .snippet { color: var(--muted); font-size: 13px; }

.graph { position: relative; flex: 1; min-height: 0; }
.graph canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.graph canvas.hovering { cursor: pointer; }
.graph-tools { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; pointer-events: none; }
.graph-tools > * { pointer-events: auto; }
.graph-tools .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card-2); }
.graph-tools .seg button { border: 0; background: none; padding: 4px 10px; min-height: 28px; color: var(--muted); }
.graph-tools .seg button.on { background: var(--active); color: var(--text); }
.graph-stats { position: absolute; left: 14px; bottom: 10px; color: var(--faint); font-size: 11.5px; pointer-events: none; }
.graph-legend { position: absolute; left: 10px; right: 10px; bottom: 30px; display: flex; flex-wrap: wrap; gap: 4px 6px; pointer-events: none; max-height: 56px; overflow: hidden; }
.legend-item { pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--card-2) 88%, transparent); color: var(--text); font-size: 11.5px; white-space: nowrap; }
.legend-item:hover { border-color: var(--border-strong); }
.legend-item .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend-item .legend-count { color: var(--faint); }
.legend-item.off { color: var(--faint); background: transparent; border-style: dashed; }
.legend-item.off .swatch { opacity: 0.25; }
.legend-item.reset { color: var(--accent-text); }

/* ---------- mobile ---------- */

.m-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.m-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.m-body > * { width: 100%; flex-shrink: 0; }
.m-body > .graph { flex: 1 1 auto; }
.m-tabbar { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--border); background: var(--card); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); flex: none; }
.m-tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none !important; }
.m-tabbar a .icon { width: 22px; height: 22px; }
.m-tabbar a.active { color: var(--accent-text); }
.m-top { display: flex; align-items: center; gap: 6px; padding: 12px 14px 4px; min-height: 52px; flex: none; }
.m-top .back { display: flex; align-items: center; gap: 2px; color: var(--accent-text); font-size: 15px; border: 0; background: none; padding: 6px 4px 6px 0; min-width: 0; text-decoration: none !important; }
.m-top .back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-top .back .icon { width: 20px; height: 20px; }
.m-top .icon-btn { width: 38px; height: 38px; color: var(--accent-text); }
.m-top .icon-btn .icon { width: 21px; height: 21px; }
.m-title { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; text-align: left; }
.m-title h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; overflow-wrap: anywhere; }
.m-title .icon { width: 18px; height: 18px; color: var(--muted); }

@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .note, .folder, .page { padding: 6px 14px 40px; }
  .note-title, .folder-title h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
  .folder { gap: 14px; }
  .list-row { min-height: 52px; }
  .list-row .title { font-size: 16px; }
  .icon-btn { width: 36px; height: 36px; }
  .icon-btn .icon { width: 19px; height: 19px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 32px; }
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], input[type="search"], textarea, .select { min-height: 42px; font-size: 16px; }
  .overlay { padding: 5vh 10px 10px; }
  .menu-item { min-height: 42px; font-size: 15px; }
  .grid2 { grid-template-columns: 1fr; }
  .auth { padding-top: 32px; }
  .auth-card { padding: 20px 18px; }
  .toasts { left: 12px; right: 12px; bottom: 76px; max-width: none; }
  .graph-tools { gap: 6px; top: 8px; left: 8px; right: 8px; }
  .graph-tools .select { min-height: 30px; font-size: 13px; flex: 1 1 90px; min-width: 0; width: auto; }
  .graph-tools .seg button { padding: 4px 8px; font-size: 13px; }
  .graph-tools .icon-btn { width: 30px; height: 30px; }
  .graph-tools .btn.small { min-height: 30px; }
  .graph-legend { max-height: 52px; bottom: 28px; }
  .legend-item { height: 22px; font-size: 11px; padding: 0 7px; }
  .consent-row { flex-wrap: wrap; }
  .viewer { padding: 8px 14px 30px; }
  .md { font-size: 16px; }
  .subnav { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .subnav a { white-space: nowrap; }
  .tree-row { height: 38px; font-size: 15px; }
  .table .hide-m { display: none; }
}

/* ---------- segmented controls, search modes ---------- */

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card-2); }
.seg button { border: 0; background: none; padding: 4px 10px; min-height: 28px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--active); color: var(--text); }
.mode-switch { align-self: flex-start; }
.palette-modes { padding: 0 12px 8px; display: flex; }
.palette-modes:empty { display: none; }
.pill.meaning { font-size: 11px; margin-left: 8px; vertical-align: 1px; }
.dot.warn { background: var(--warn); }
.model-card { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); }
.progress-row { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
progress { width: 100%; height: 6px; border: 0; border-radius: 999px; background: var(--border); overflow: hidden; accent-color: var(--accent); appearance: none; }
progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

/* ---------- history and diff ---------- */

.history { padding: 22px 28px 60px; max-width: 1280px; margin: 0 auto; }
.history-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 2px 0 16px; overflow-wrap: anywhere; }
.history .back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12.5px; }
.history .back:hover { color: var(--text); }
.history .back .icon { width: 14px; height: 14px; }
.history-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.timeline { display: flex; flex-direction: column; gap: 1px; position: sticky; top: 0; max-height: calc(100vh - 150px); overflow: auto; padding-right: 4px; }
.tl-count { color: var(--faint); font-size: 12px; margin-bottom: 4px; }
.tl-day { font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; margin: 10px 0 4px 2px; }
.tl-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--text); text-decoration: none !important; border: 1px solid transparent; }
.tl-item:hover { background: var(--hover); }
.tl-item.active { background: var(--active); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.tl-item.base:not(.active) { border-color: var(--border-strong); border-style: dashed; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.tl-dot.ai { background: var(--accent); }
.tl-dot.del { background: var(--danger); }
.tl-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.tl-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-meta { color: var(--muted); font-size: 12px; }
.tl-tags .pill { font-size: 10.5px; padding: 0 6px; }
.history-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.cmp-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cmp-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; min-width: 0; }
.cmp-field .select { max-width: 260px; font-size: 12.5px; }
.cmp-arrow { color: var(--faint); }
.diff-stats { display: inline-flex; gap: 8px; font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.diff-stats .plus { color: var(--ok); }
.diff-stats .minus { color: var(--danger); }
.diff-view { display: flex; flex-direction: column; gap: 14px; }
.diff-part-title { font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 4px 2px; }
.diff { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card-2); font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
.diff-row { display: grid; grid-template-columns: 40px 40px 18px minmax(0, 1fr); }
.diff-no { color: var(--faint); text-align: right; padding: 0 8px 0 0; user-select: none; font-size: 11px; line-height: 1.75; }
.diff-sign { color: var(--faint); user-select: none; text-align: center; }
.diff-text { white-space: pre-wrap; overflow-wrap: anywhere; padding-right: 10px; min-width: 0; }
.diff-row.add, .diff-cell.add { background: color-mix(in srgb, var(--ok) 13%, transparent); }
.diff-row.del, .diff-cell.del { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.diff-row.add .diff-sign { color: var(--ok); }
.diff-row.del .diff-sign { color: var(--danger); }
.add .w { background: color-mix(in srgb, var(--ok) 34%, transparent); border-radius: 3px; }
.del .w { background: color-mix(in srgb, var(--danger) 32%, transparent); border-radius: 3px; }
.diff-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.diff-cell { display: grid; grid-template-columns: 40px minmax(0, 1fr); border-right: 1px solid var(--border); }
.diff-cell:last-child { border-right: 0; }
.diff-cell.none { background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--border) 60%, transparent) 6px 7px); }
.diff-fold { display: block; width: 100%; border: 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--card); color: var(--muted); font-family: var(--font); font-size: 12px; padding: 4px 10px; text-align: center; }
.diff-fold:first-child { border-top: 0; }
.diff-fold:last-child { border-bottom: 0; }
.diff-fold:hover { color: var(--accent-text); }
.diff-note { color: var(--muted); padding: 10px 2px; font-family: var(--font); }
.restore-diff { max-height: 46vh; overflow: auto; }

/* ---------- desktop app: onboarding, sync ---------- */

.connect { display: flex; flex-direction: column; gap: 18px; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0; }
.steps li { flex: 1; height: 4px; border-radius: 999px; background: var(--border); transition: background 0.2s; }
.steps li.done { background: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.steps li.current { background: var(--accent); }
.lang-choice { display: flex; gap: 8px; }
.lang-choice .btn { flex: 1; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--card); }
.choice:hover { border-color: var(--border-strong); }
.choice.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-ico { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--card-2); color: var(--muted); flex: none; }
.choice.on .choice-ico { background: var(--accent-soft); color: var(--accent-text); }
.choice-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.choice-text small { color: var(--muted); }
.folder-box { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card-2); overflow-wrap: anywhere; }
.folder-box .icon { color: var(--muted); }
.sync-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card-2); }
.sync-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; border: 0; border-top: 1px solid var(--border); background: none; color: var(--text); text-align: left; width: 100%; }
.sync-row:first-child { border-top: 0; }
button.sync-row:hover { background: var(--hover); }
.sync-name { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sync-name small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.sync-name .sync-error { color: var(--danger); }
.sync-list .info-empty { padding: 10px 12px; }
.sync-panel { display: flex; flex-direction: column; gap: 10px; }
.sync-btn { display: flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); padding: 2px 4px; margin: -2px -4px; border-radius: 6px; font-size: 11.5px; text-align: left; }
.sync-btn:hover { background: var(--hover); color: var(--text); }
.dialog-actions.wrap { flex-wrap: wrap; align-items: center; }
.sheet-cards { display: flex; flex-direction: column; gap: 10px; }
.account-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none !important; }
.account-card .avatar { width: 40px; height: 40px; font-size: 14px; }
.account-card .names, .graph-card .names { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.account-card small, .graph-card small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card .icon { color: var(--faint); }
.row-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--card); border: 1px solid var(--border); color: var(--muted); flex: none; }
.more .list-row .title { font-weight: 500; }
.graph-card { position: absolute; left: 12px; right: 12px; bottom: 74px; display: flex; align-items: center; gap: 12px; padding: 10px 12px; box-shadow: var(--shadow); z-index: 2; }
.graph-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.format-bar { display: none; }
.ptr { display: none; }
.m-top-title { display: none; }

/* ---------- phones: app-like behavior ---------- */

html { -webkit-text-size-adjust: 100%; }
a, button, input, select, textarea, label, [role="button"] { touch-action: manipulation; }

@media (max-width: 720px) {
  .m-shell { height: calc(100dvh - var(--kb, 0px)); padding-top: env(safe-area-inset-top); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .m-body { -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
  .kb-open .m-tabbar { display: none; }
  .auth { padding-top: calc(28px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); height: calc(100dvh - var(--kb, 0px)); }

  /* Touch targets: at least 44 px. */
  .icon-btn, .m-top .icon-btn { width: 44px; height: 44px; }
  .avatar-btn { min-width: 44px; min-height: 44px; display: grid; place-items: center; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
  .list-row { min-height: 52px; }
  .legend-item, .seg button { min-height: 36px; }
  .m-tabbar a { min-height: 48px; justify-content: center; }
  .info-item { min-height: 40px; align-items: center; font-size: 14px; }
  .tl-item { min-height: 48px; }
  .consent-row { min-height: 48px; }
  .md input.task { width: 20px; height: 20px; vertical-align: -4px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

  /* Large titles that collapse into the bar on scroll. */
  .m-top { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: 0 -14px; padding: 6px 10px !important; min-height: 48px; }
  .m-top-title { display: block; position: absolute; left: 50%; transform: translateX(-50%); max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; font-size: 15px; opacity: 0; transition: opacity 0.15s; pointer-events: none; }
  .scrolled .m-top-title { opacity: 1; }
  .scrolled .m-top { border-bottom: 1px solid var(--border); }
  .note, .folder, .page, .history { padding: 0 14px 40px; }
  .viewer { padding: 0 14px 30px; }

  /* Pull to refresh. */
  .ptr { display: grid; place-items: center; overflow: hidden; color: var(--faint); flex: none; transition: height 0.15s; }
  .ptr .icon { width: 20px; height: 20px; }
  .ptr.ready { color: var(--accent-text); }
  .ptr.busy .icon { animation: spin 0.9s linear infinite; }

  /* Bottom sheets instead of dialogs and context menus. */
  .overlay { padding: 0; align-items: flex-end; }
  .dialog, .dialog.wide, .palette { max-width: none; border-radius: 16px 16px 0 0; border-bottom: 0; max-height: calc(92dvh - var(--kb, 0px)); display: flex; flex-direction: column; margin-bottom: var(--kb, 0px); animation: sheet-in 0.18s ease-out; }
  .dialog-head { padding-top: 18px; position: relative; }
  .dialog-head::before { content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 999px; background: var(--border-strong); }
  .dialog-body { overflow: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
  .palette { height: calc(86dvh - var(--kb, 0px)); }
  .palette-list { max-height: none; flex: 1; }
  .palette-foot { display: none; }
  .menu { left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; min-width: 0; border-radius: 16px 16px 0 0; border-bottom: 0; padding: 14px 8px calc(10px + env(safe-area-inset-bottom)); max-height: 80dvh; overflow: auto; animation: sheet-in 0.18s ease-out; }
  .menu-backdrop { background: rgba(0, 0, 0, 0.5); }
  .menu-item { min-height: 48px; font-size: 16px; border-radius: 10px; padding: 4px 12px; }
  .menu-item .icon { width: 18px; height: 18px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .btn { flex: 1 1 auto; }

  /* History and diff. */
  .history-grid { grid-template-columns: 1fr; gap: 12px; }
  .timeline { position: static; max-height: 34vh; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
  .cmp-field { flex: 1 1 100%; }
  .cmp-field .select { flex: 1; max-width: none; }
  .cmp-arrow { display: none; }
  .diff { font-size: 12px; }
  .diff-row { grid-template-columns: 30px 30px 16px minmax(0, 1fr); }

  /* Graph: full-bleed canvas, legend as one scrolling row. */
  .graph-tools { flex-wrap: wrap; }
  .graph-tools .select { flex: 1 1 100%; order: 5; min-height: 36px; }
  .graph-legend { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-height: none; pointer-events: auto; left: 0; right: 0; padding: 0 12px; bottom: 30px; scrollbar-width: none; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  .graph-legend::-webkit-scrollbar { display: none; }
  .legend-item { flex: none; height: 32px; font-size: 12.5px; }
  .graph-card { bottom: 76px; }

  /* Editor: formatting bar above the keyboard. */
  .format-bar { display: flex; position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 20; gap: 2px; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--border); overflow-x: auto; }
  .kb-open .format-bar { padding-bottom: 4px; }
  html:not(.kb-open) .format-bar { bottom: calc(60px + env(safe-area-inset-bottom)); border: 1px solid var(--border); border-radius: 12px; left: 10px; right: 10px; padding: 4px 6px; }
  .format-btn { flex: 1; min-width: 44px; min-height: 44px; border: 0; border-radius: 8px; background: none; color: var(--text); font-weight: 650; font-size: 15px; }
  .format-btn:active { background: var(--hover); }
  .format-btn[data-format="italic"] { font-style: italic; }
  .format-btn[data-format="link"] { font-family: var(--mono); font-size: 13px; color: var(--accent-text); }
  .editor-host .cm-content { padding-bottom: 50vh; }

  .connect h1 { font-size: 22px; }
  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0.6; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dialog, .palette, .menu { animation: none; } .ptr.busy .icon { animation: none; } }

@media (max-width: 720px) {
  * { -webkit-tap-highlight-color: transparent; }
  /* No room for words in the bar: the save state is a dot (its text stays for assistive technology). */
  .m-top .save-state { font-size: 0; width: 8px; height: 8px; border-radius: 50%; flex: none; margin: 0 4px; }
  .m-top .save-state[data-state="unsaved"] { background: var(--warn); }
  .m-top .save-state[data-state="saving"] { background: var(--accent); animation: pulse 0.9s ease-in-out infinite; }
  .scrolled .m-top .back span { visibility: hidden; }
  .m-top .back { max-width: 45%; }
  .conflict .row { flex-wrap: wrap; }
}
.conflict { display: flex; flex-direction: column; gap: 12px; }

@keyframes pulse { 50% { opacity: 0.35; } }
.tl-move { display: flex; align-items: center; gap: 6px; margin: -2px 0 4px 27px; padding: 2px 6px; font-size: 12px; color: var(--accent-text); border-radius: 6px; min-width: 0; }
.tl-move span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-move .icon { width: 12px; height: 12px; flex: none; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.danger-zone h2 { color: var(--danger); }
.sync-chip { display: none; }
@media (max-width: 720px) {
  .sync-chip { display: grid; place-items: center; width: 44px; height: 44px; flex: none; }
  .sync-chip .dot { width: 10px; height: 10px; }
  .tl-move { min-height: 36px; }
}
