/* note-web mobile-first: flomo-style drawer (collapsed by default) + FAB. */

* { box-sizing: border-box; }

/* hidden 属性必须压过 display:flex/overlay 类 */
[hidden] { display: none !important; }

:root {
  --fg: #1a1a1a;
  --fg-dim: #8a8a8a;
  --bg: #ffffff;
  --bg-soft: #f6f6f6;
  --border: #e6e6e6;
  --accent: #4a7ddb;
  --danger: #d9534f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font: 16px/1.6 -apple-system, "PingFang SC", "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

/* ── gate ─────────────────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  padding: 24px;
  z-index: 50;
}
.gate-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg);
  border-radius: 14px;
  padding: 28px 22px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  text-align: center;
}
.gate-title { margin: 0 0 4px; font-size: 24px; }
.gate-sub { margin: 0 0 18px; color: var(--fg-dim); font-size: 14px; }
.gate-card input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 12px;
}
.gate-err { color: var(--danger); font-size: 13px; margin: 8px 0 0; }

/* ── app shell ────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.icon-btn {
  border: none;
  background: none;
  font-size: 20px;
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 44px;
  min-height: 36px;
}
.icon-btn:active { background: var(--bg-soft); }
.icon-danger { color: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-on { background: #4caf50; }
.dot-off { background: #ccc; }

.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 96px;
}

/* ── drawer（默认收起，左侧滑出） ──────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 30;
}
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 78vw;
  max-width: 300px;
  background: var(--bg);
  z-index: 31;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--safe-bottom);
}
.drawer-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15); }

.drawer-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: none;
  background: var(--bg-soft);
  padding: calc(18px + var(--safe-top)) 16px 14px;
  text-align: left;
  min-height: 44px;
}
.drawer-vault-name { font-size: 17px; font-weight: 700; }
.drawer-conn-name { font-size: 12px; color: var(--fg-dim); }

.drawer-nav { display: flex; flex-direction: column; padding: 8px 0; }
.drawer-custom { display: flex; flex-direction: column; }
.drawer-item {
  border: none;
  background: none;
  text-align: left;
  padding: 12px 16px;
  font-size: 15px;
  min-height: 44px;
}
.drawer-item:active { background: var(--bg-soft); }
.drawer-item-active { background: var(--bg-soft); color: var(--accent); font-weight: 600; }

.sub-tree { display: flex; flex-direction: column; background: var(--bg-soft); }
.sub-item {
  border: none;
  background: none;
  text-align: left;
  padding: 9px 16px 9px 16px;
  font-size: 14px;
  color: var(--fg-dim);
  min-height: 40px;
}

.drawer-block { padding: 8px 16px 12px; border-top: 1px solid var(--bg-soft); }
.drawer-block-title { font-size: 12px; color: var(--fg-dim); font-weight: 600; margin-bottom: 8px; }
.drawer-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--accent);
  min-height: 28px;
}

.drawer-footer { margin-top: auto; border-top: 1px solid var(--bg-soft); }

/* ── FAB（底部中央快速记录） ───────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(74, 125, 219, 0.4);
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(0.94); }

/* ── compose sheet（Milkdown 编辑器） ─────────────────── */
.compose-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(14px + var(--safe-bottom));
  z-index: 32;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.compose-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.compose-hint { flex: 1; font-size: 12px; color: var(--fg-dim); }
.compose-count { font-size: 12px; color: var(--fg-dim); }
.compose-actions { display: flex; gap: 8px; }
.compose-actions .btn-ghost { margin: 0; width: auto; padding: 8px 14px; }
.compose-actions .btn-primary { width: auto; padding: 8px 18px; }

/* ── Milkdown 编辑器挂载 ─────────────────────────────── */
.md-editor-mount .milkdown { background: var(--bg); }
.md-editor-mount .milkdown .editor { padding: 0; outline: none; }
.md-editor-mount .milkdown p { font-size: 15px; line-height: 1.6; }
/* 组件浮层（latex/block-handle/link-bubble/slash-menu）隐藏，note-tab 同款 */
.md-editor-mount .milkdown [data-show='false'] { display: none !important; }
.compose-mount {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 130px;
  overflow-y: auto;
}
.detail-mount {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.lucky-again { margin: 0 0 12px; }

/* ── sheet（vault 选择） ───────────────────────────────── */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  z-index: 32;
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
}
.sheet-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.vault-list { display: flex; flex-direction: column; gap: 6px; }
.vault-row {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  font-size: 15px;
  min-height: 44px;
}
.vault-active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── markdown body ────────────────────────────────────── */
.md-body { font-size: 15px; word-break: break-word; }
.md-body h1 { font-size: 20px; } .md-body h2 { font-size: 18px; }
.md-body h3 { font-size: 16px; } .md-body h4, .md-body h5, .md-body h6 { font-size: 15px; }
.md-body p { margin: 8px 0; }
.md-body ul, .md-body ol { margin: 8px 0; padding-left: 24px; }
.md-body li { margin: 2px 0; }
.md-body li input[type="checkbox"] { margin-right: 4px; }
.md-body blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--border);
  color: var(--fg-dim);
}
.md-body code {
  background: var(--bg-soft);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}
.md-code {
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.md-code code { background: none; padding: 0; }
.md-body table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 5px 10px; }
.md-body img { max-width: 100%; border-radius: 8px; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.md-body a { color: var(--accent); text-decoration: none; }
.md-body a.wiki { border-bottom: 1px dashed var(--accent); }

.journal-card { margin-bottom: 18px; }
.journal-date { font-size: 13px; color: var(--fg-dim); margin-bottom: 4px; font-weight: 600; }

/* ── note list ────────────────────────────────────────── */
.note-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 12px 6px;
  border-bottom: 1px solid var(--bg-soft);
  min-height: 48px;
}
.note-row:active { background: var(--bg-soft); }
.note-name { font-size: 15px; font-weight: 500; }
.note-sub { font-size: 12px; color: var(--fg-dim); }

.empty-hint { text-align: center; color: var(--fg-dim); font-size: 14px; padding: 32px 0; }

/* ── 内容卡片（菜单视图，note-tab feed 风格） ──────────── */
.note-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.note-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.note-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-card-time { font-size: 12px; color: var(--fg-dim); flex-shrink: 0; }

/* ── cornell 卡片 ─────────────────────────────────────── */
.cornell-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
}
.cornell-cues { background: var(--bg-soft); padding: 10px 14px; }
.cornell-title { font-size: 12px; color: var(--fg-dim); font-weight: 600; margin-bottom: 6px; }
.cornell-cue-list { display: flex; flex-direction: column; gap: 4px; }
.cornell-cue { font-size: 14px; font-weight: 500; }
.cornell-body { padding: 10px 14px; }
.cornell-summary { padding: 10px 14px; border-top: 1px dashed var(--border); background: #fffdf5; }

/* ── search ───────────────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 8px;
}

/* ── buttons ──────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
}
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  color: var(--fg-dim);
  margin: 10px 0;
}

/* ── settings ─────────────────────────────────────────── */
.settings {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 33;
}
.settings-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(24px + var(--safe-bottom));
}
.me-block { margin-bottom: 22px; }
.me-title { font-size: 13px; color: var(--fg-dim); font-weight: 600; margin-bottom: 8px; }
.settings-hint { font-size: 12px; color: var(--fg-dim); line-height: 1.7; margin: 0 0 10px; }
.settings-status { display: block; text-align: center; font-size: 14px; color: var(--fg-dim); margin-top: 8px; }
.status-ok { color: #4caf7d; }

.conn-header {
  display: grid;
  grid-template-columns: 34px 1fr 1.4fr 70px 1fr 30px;
  gap: 6px;
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 4px;
}
.conn-row {
  display: grid;
  grid-template-columns: 34px 1fr 1.4fr 70px 1fr 30px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.conn-row input {
  width: 100%;
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  min-width: 0;
}
.conn-row input[type="radio"] { width: auto; justify-self: center; }

.s-del {
  border: none;
  background: var(--bg-soft);
  color: var(--fg-dim);
  border-radius: 6px;
  padding: 6px 0;
  font-size: 15px;
  min-height: 32px;
}

.menu-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}
.menu-row-head { display: flex; gap: 8px; align-items: center; }
.menu-row-head input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.menu-row-mid { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.menu-row-mid select, .menu-row-mid input[type="text"], .menu-row-mid input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.menu-row-mid select { flex: 0 0 auto; }
.s-menu-value { flex: 1; min-width: 140px; }
.menu-recent { display: flex; gap: 6px; }
.s-menu-days { width: 70px; }
.menu-order { display: flex; gap: 6px; margin-left: auto; }
.s-order {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  font-size: 14px;
  color: var(--fg-dim);
}

/* ── detail overlay ───────────────────────────────────── */
.detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 35;
}
.detail-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(24px + var(--safe-bottom));
}
.detail-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  gap: 8px;
}
.detail-editor-bar { display: flex; gap: 10px; }
.detail-editor-bar .btn-ghost { margin: 0; }
.detail-editor-bar .btn-primary { width: auto; flex: 1; }

/* ── toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(220, 53, 69, 0.95);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  max-width: 80vw;
}
.toast-ok { background: rgba(40, 40, 40, 0.9); }

/* ── desktop: center the phone-width column ───────────── */
@media (min-width: 640px) {
  .topbar, .main, .fab { max-width: 560px; margin-left: auto; margin-right: auto; width: 100%; left: 0; right: 0; }
  .fab { left: 50%; transform: translateX(-50%); }
  .detail, .settings { max-width: 560px; left: 50%; transform: translateX(-50%); }
  .compose-sheet, .sheet { max-width: 560px; margin: 0 auto; }
}
