:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --sidebar: #eef0f4;
  --text: #1d2330;
  --muted: #677085;
  --border: #d9dde5;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e3ecfc;
  --danger: #c93a3a;
  --missing: #b26a00;
  --code-bg: #f0f2f5;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e;
    --panel: #1c2028;
    --sidebar: #191c23;
    --text: #e4e7ee;
    --muted: #949cb0;
    --border: #2f3542;
    --accent: #5b8ff0;
    --accent-text: #0d1220;
    --accent-soft: #233251;
    --danger: #ef6b6b;
    --missing: #e6a23c;
    --code-bg: #252a34;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
.icon-btn { border: none; background: transparent; padding: 2px 8px; font-size: 18px; line-height: 1; }
input[type=text], input[type=password], input[type=search], input:not([type]), textarea, select {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
a { color: var(--accent); }
.error { color: var(--danger); margin: 0; }
.muted { color: var(--muted); }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; display: grid; gap: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100%; }
.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px; padding: 14px; min-height: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; font-size: 17px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 30px; z-index: 10; min-width: 210px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; display: grid;
}
.menu a, .menu button { text-align: left; padding: 7px 10px; border: none; background: none; border-radius: 6px; color: var(--text); text-decoration: none; }
.menu a:hover, .menu button:hover { background: var(--accent-soft); }
.menu-user { padding: 6px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-wrap: anywhere; }
.new-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters { display: flex; gap: 4px; }
.filters button { flex: 1; padding: 4px 6px; font-size: 13px; background: transparent; border-color: transparent; }
.filters button.active { background: var(--panel); border-color: var(--border); }
.note-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.note-list a {
  display: block; padding: 8px 10px; border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.note-list a:hover { background: var(--panel); }
.note-list a.active { background: var(--accent-soft); }
.note-list .title { display: flex; gap: 6px; align-items: baseline; font-weight: 500; overflow-wrap: anywhere; }
.note-list .meta { font-size: 12px; color: var(--muted); }
.type-icon { color: var(--muted); flex: none; width: 16px; text-align: center; }
.empty-list { color: var(--muted); font-size: 14px; padding: 8px 10px; }

.main { overflow-y: auto; min-width: 0; }
.page { max-width: 860px; margin: 0 auto; padding: 24px 28px 60px; }
.placeholder { height: 100%; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 16px; }

/* ---- editor ---- */
.editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.back-btn { display: none; }
.title-input {
  flex: 1; min-width: 0; font-size: 24px; font-weight: 700; border: 1px solid transparent !important;
  background: transparent !important; padding: 4px 6px !important; margin-left: -6px;
}
.title-input:hover { border-color: var(--border) !important; }
.editor-sub { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 1px 9px; font-weight: 600; font-size: 12px; }
.save-status { margin-left: auto; }
.tabs { display: flex; gap: 4px; }
.tabs button { padding: 3px 10px; font-size: 13px; background: transparent; border-color: transparent; }
.tabs button.active { background: var(--panel); border-color: var(--border); }

.editor-area { position: relative; }
.body-input {
  min-height: 55vh; resize: vertical; font: 14px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; padding: 14px;
}
.suggest {
  position: absolute; left: 12px; z-index: 5; min-width: 240px; max-width: 90%;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.15); list-style: none; margin: 0; padding: 4px;
}
.suggest li { padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--accent-soft); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.markdown { overflow-wrap: anywhere; }
.markdown pre, .markdown code { background: var(--code-bg); border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.markdown code { padding: 1px 4px; }
.markdown pre { padding: 10px 12px; overflow-x: auto; }
.markdown pre code { padding: 0; }
.markdown blockquote { border-left: 3px solid var(--border); margin-left: 0; padding-left: 14px; color: var(--muted); }
.markdown img { max-width: 100%; }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 4px 8px; }
.markdown li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.3em; }
a.wikilink { text-decoration: none; border-bottom: 1px solid currentColor; }
a.wikilink.missing { color: var(--missing); border-bottom-style: dashed; }

/* ---- checklist ---- */
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.items { list-style: none; margin: 0 0 10px; padding: 0; }
.item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.item input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.item .item-text { border-color: transparent; background: transparent; padding: 5px 8px; }
.item .item-text:hover { border-color: var(--border); }
.item.checked .item-text { text-decoration: line-through; color: var(--muted); }
.item .remove { border: none; background: none; color: var(--muted); opacity: 0; padding: 2px 8px; font-size: 18px; }
.item:hover .remove, .item .remove:focus-visible { opacity: 1; }
.item .remove:hover { color: var(--danger); }
.item-links { font-size: 13px; flex: none; }
.add-item { display: flex; gap: 8px; margin-bottom: 18px; }
.add-item input { flex: 1; }

/* ---- links panel ---- */
.links-panel { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.links-panel h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.links-panel ul { list-style: none; margin: 0; padding: 0; }
.links-panel li { padding: 2px 0; }

/* ---- admin / account ---- */
.page h2 { margin-top: 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.form-grid { display: grid; gap: 10px; max-width: 420px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.form-row label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; min-width: 160px; }
.form-row select { width: auto; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
table.users th, table.users td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
table.users td.actions { white-space: nowrap; text-align: right; }
table.users td.actions button { margin-left: 4px; padding: 4px 10px; font-size: 13px; }
.notice { font-size: 14px; margin: 8px 0 0; }
.notice.ok { color: var(--accent); }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: var(--radius); font-size: 14px;
}

/* ---- phones ---- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view=list] .main { display: none; }
  .app[data-view=detail] .sidebar { display: none; }
  .page { padding: 16px 16px 48px; }
  .back-btn { display: inline-block; }
  .title-input { font-size: 20px; }
  .links-panel { grid-template-columns: 1fr; }
  .item .remove { opacity: 1; }
}
