/* ==========================================================================
   女为 · PWA 编辑器 —— 样式
   原则：手机优先、触控友好（按钮 >= 44px）、不依赖 hover、原生 CSS 无框架。
   配色沿用主站的极简黑白灰。
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-sub: #f6f6f6;
  --text: #333333;
  --text-weak: #8a8a8a;
  --border: #ececec;
  --border-strong: #d8d8d8;
  --accent: #333333;
  --danger: #b3402f;
  --ok: #3f7d4f;
  --bar-h: 54px;
  --side-w: 280px;
  --radius: 4px;
}

* { box-sizing: border-box; }

/* 必须有这条：本文件里 .editor / .empty / .scrim 等都显式设了 display，
   它们的优先级高于 UA 的 [hidden]{display:none}，不加 !important 的话
   hidden 属性会被无声地架空——遮罩层会一直盖在编辑区上面吞掉点击。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  /* 移动端抽屉打开时禁止背景滚动由 JS 处理 */
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* ---------------------------------------------------------------- 顶部栏 */
.app-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--bar-h);
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 30;
}

.app-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

.save-state {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 12px;
  color: var(--text-weak);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.save-state.is-saving { color: var(--text); }
.save-state.is-saved  { color: var(--ok); }
.save-state.is-error  { color: var(--danger); }

button {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn, .primary-btn, .danger-btn, .ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
  white-space: nowrap;
}

.icon-btn {
  width: 44px;
  min-height: 44px;
  font-size: 20px;
  line-height: 1;
  border: 1px solid var(--border-strong);
  background: var(--bg);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font-weight: 600;
}
.primary-btn.big {
  min-height: 48px;
  padding: 0 22px;
  font-size: 16px;
}

.danger-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--danger);
}

.ghost-btn {
  width: 100%;
  border: 1px dashed var(--border-strong);
  background: var(--bg);
  color: var(--text);
}

/* ------------------------------------------------------------ 主体布局 */
body {
  flex-direction: row;
  align-items: stretch;
}

.app-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
}

/* 桌面：侧栏常驻 + 编辑区 */
.sidebar {
  flex: 0 0 var(--side-w);
  width: var(--side-w);
  display: flex;
  flex-direction: column;
  margin-top: var(--bar-h);
  border-right: 1px solid var(--border);
  background: var(--bg-sub);
  overflow-y: auto;
  height: calc(100% - var(--bar-h));
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  margin-top: var(--bar-h);
  height: calc(100% - var(--bar-h));
  display: flex;
  flex-direction: column;
}

.menu-only { display: none; }
.scrim { display: none; }

/* ------------------------------------------------------------ 侧栏内容 */
.sidebar-tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 46px;
  padding: 0 6px;
  font-size: 14px;
  color: var(--text-weak);
  border-bottom: 2px solid transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-btn.is-active {
  color: var(--text);
  font-weight: 700;
  border-bottom-color: var(--accent);
  background: var(--bg);
}

.tab-count {
  display: inline-block;
  font-size: 12px;
  color: var(--text-weak);
}

.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  overflow-y: auto;
}

.article-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
}
.article-item.is-active {
  background: var(--bg-sub);
  box-shadow: inset 3px 0 0 var(--accent);
}
.article-item-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: break-word;
}
.article-item-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-weak);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.article-item-sub span {
  flex: 0 1 auto;
  min-width: 0;
}

.list-empty {
  padding: 24px 14px;
  color: var(--text-weak);
  font-size: 14px;
  text-align: center;
}

.published-wrap { padding: 10px; }
.published-hint {
  margin: 2px 2px 10px;
  font-size: 12px;
  color: var(--text-weak);
  line-height: 1.5;
  overflow-wrap: break-word;
}
.published-wrap .article-list {
  max-height: 60vh;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

/* 设置面板 */
.settings {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  background: var(--bg);
}
.settings summary {
  min-height: 36px;
  line-height: 36px;
  font-size: 14px;
  color: var(--text-weak);
  cursor: pointer;
}
.settings .field {
  display: block;
  margin: 8px 0;
}
.settings .field span {
  display: block;
  font-size: 12px;
  color: var(--text-weak);
  margin-bottom: 4px;
}
.settings input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
}
.settings-note {
  margin: 6px 0 2px;
  font-size: 12px;
  color: var(--text-weak);
  line-height: 1.5;
}

/* ------------------------------------------------------------ 空状态 */
.empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.empty-title { margin: 0; font-size: 17px; font-weight: 700; }
.empty-sub { margin: 0; font-size: 14px; color: var(--text-weak); }

/* ------------------------------------------------------------ 编辑区 */
.editor {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-head {
  flex: 0 0 auto;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.title-input {
  width: 100%;
  min-height: 44px;
  padding: 4px 0;
  font-size: 20px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text);
  border: none;
  outline: none;
  background: transparent;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.meta-input {
  min-height: 40px;
  padding: 0 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  flex: 1 1 130px;
  /* 不设 min-width:0：宁愿换行，也不要把 "2026-09-16 21:30:00" 裁成半截 */
  min-width: 118px;
  max-width: 100%;
}
/* 日期要放下完整的 "YYYY-MM-DD HH:MM:SS"，窄屏时让它换到第二行 */
#f-date { flex: 1 1 175px; min-width: 158px; }
.meta-row .danger-btn {
  flex: 0 0 auto;
  margin-left: auto;
}

/* 编辑 / 预览 切换 */
.view-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 0;
  padding: 8px 14px 0;
}
.view-tab {
  flex: 0 0 auto;
  min-width: 88px;
  min-height: 42px;
  font-size: 15px;
  color: var(--text-weak);
  border: 1px solid var(--border-strong);
  background: var(--bg);
}
.view-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-tab:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.view-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.editor-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 10px 14px;
}

.content-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  resize: none;
  outline: none;
  -webkit-overflow-scrolling: touch;
}

.preview {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 4px 2px;
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: break-word;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

/* 预览里的 Markdown 排版 */
.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  margin: 1em 0 .5em;
  line-height: 1.35;
  overflow-wrap: break-word;
}
.preview h1 { font-size: 1.35rem; }
.preview h2 { font-size: 1.2rem; }
.preview h3 { font-size: 1.08rem; }
.preview h4, .preview h5, .preview h6 { font-size: 1rem; }
.preview p { margin: 0 0 .8em; }
.preview ul, .preview ol { margin: 0 0 .8em; padding-left: 1.4em; }
.preview li { margin: .2em 0; overflow-wrap: break-word; }
.preview blockquote {
  margin: 0 0 .8em;
  padding: .2em 0 .2em .9em;
  border-left: 3px solid var(--border-strong);
  color: #666;
}
.preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
  padding: .1em .3em;
  background: var(--bg-sub);
  border-radius: 3px;
  overflow-wrap: anywhere;
}
.preview pre {
  margin: 0 0 .8em;
  padding: .7em .8em;
  background: var(--bg-sub);
  border-radius: var(--radius);
  overflow-x: auto;
}
.preview pre code { padding: 0; background: none; }
.preview a { color: var(--text); text-decoration: underline; }
.preview hr { border: none; border-top: 1px solid var(--border-strong); margin: 1em 0; }

.editor-foot {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-weak);
}
#meta-id { overflow-wrap: anywhere; max-width: 100%; }

/* ================================================================ 发布 */
.publish-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

/* 发布结果文案：只在有内容时占位，避免空白行把编辑区顶下去 */
.publish-state {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: .78rem;
  line-height: 1.5;
  color: var(--text-weak);
  overflow-wrap: anywhere;
}
.publish-state.is-ok { color: var(--ok); }
.publish-state.is-error { color: var(--danger); }
.publish-state.is-saving { color: var(--text-weak); }

/* 侧栏草稿标签页底部的批量动作 */
.list-actions {
  flex: 0 0 auto;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
}
.list-actions .ghost-btn { width: 100%; }

/* ================================================================ 门（gate）
   登录 / 初始化编辑密钥 / 解锁 —— 功能优先，不做视觉花样。
   门未过时 #app 整体 hidden，所以编辑区的元素根本不会参与布局。 */
.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
  overflow-y: auto;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  padding: 20px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.gate-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 600;
}

.gate-hint {
  margin: 0 0 14px;
  font-size: .82rem;
  line-height: 1.6;
  color: var(--text-weak);
}
.gate-hint b { color: var(--text); font-weight: 600; }

.gate-field { display: block; margin: 0 0 12px; }
.gate-field span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-weak);
}
.gate-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
}

.gate-msg {
  margin: 10px 0 0;
  min-height: 1.2em;
  font-size: .82rem;
  line-height: 1.5;
  color: var(--text-weak);
}
.gate-msg.is-error { color: var(--danger); }

.gate-note {
  margin: 8px 0 0;
  font-size: .76rem;
  line-height: 1.5;
  color: var(--text-weak);
}

/* 顶部状态：只说状态，不显示任何密钥/凭据 */
.session-state {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--text-weak);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================================================ 手机端 */
@media (max-width: 800px) {
  .session-state { display: none; }

  .menu-only { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar {
    position: fixed;
    top: var(--bar-h);
    left: 0;
    bottom: 0;
    width: min(86vw, var(--side-w));
    z-index: 20;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 2px 0 12px rgba(0, 0, 0, .12);
    margin-top: 0;
    height: auto;
  }
  body.drawer-open .sidebar { transform: translateX(0); }

  .scrim {
    display: block;
    position: fixed;
    inset: var(--bar-h) 0 0 0;
    z-index: 15;
    background: rgba(0, 0, 0, .3);
  }

  .main { margin-top: var(--bar-h); height: calc(100% - var(--bar-h)); }

  .app-title { font-size: .95rem; }
  .primary-btn { padding: 0 12px; }

  /* 网页端 touch: hover 可能残留，这里禁用 hover 效果，全部靠 :active */
  .article-item:active { background: var(--bg-sub); }

  .title-input { font-size: 18px; }
  .content-input { font-size: 15px; }
  .view-tab { flex: 1 1 0; min-width: 0; }
}

/* 桌面端适当留白 */
@media (min-width: 801px) {
  .editor-head, .view-tabs, .editor-body, .editor-foot { max-width: 820px; }
  .empty { align-items: center; }
}
