/* ============================================================================
   Linux 命令大全 — 样式
   主题用 CSS 变量切换；代码高亮主题由 index.html 里的 hljs CSS 链接切换。
   注意：CSP 为 style-src 'self'，因此本文件里不出现内联样式，JS 也不写
   element.style.*，一切状态变化都通过切换 class 完成。
   ========================================================================== */

:root[data-theme='dark'] {
  --bg: #12151c;
  --bg-panel: #171b24;
  --bg-elev: #1e2430;
  --bg-hover: #232b39;
  --border: #2a3341;
  --fg: #e6e9ef;
  --fg-dim: #9aa4b6;
  --fg-faint: #6b7688;
  --accent: #4ade80;
  --accent-dim: #2f9e5a;
  --mark: #f5c451;
}

:root[data-theme='light'] {
  --bg: #f6f7f9;
  --bg-panel: #ffffff;
  --bg-elev: #ffffff;
  --bg-hover: #eef1f5;
  --border: #d8dee7;
  --fg: #1b1f2a;
  --fg-dim: #5a6474;
  --fg-faint: #8b95a5;
  --accent: #1a8f4c;
  --accent-dim: #15703c;
  --mark: #b8860b;
}

* {
  box-sizing: border-box;
}

/* 按钮点击不应该选中文字 —— 避免误触时选中界面文字 */
button,
label.filter,
.chip,
.result-tag {
  -webkit-user-select: none;
  user-select: none;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC',
    'Hiragino Sans GB', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  /* 阅读命令时需要选中文字，但整个界面被拖动选中很难看 */
  -webkit-user-select: none;
  user-select: none;
}

/* ------------------------------------------------------------------ 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  padding: 0 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.prompt {
  color: var(--accent);
  font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-weight: 700;
  font-size: 15px;
}

.title {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-size: 12px;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-family: inherit;
  cursor: pointer;
}

.badge:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

/* ------------------------------------------------------------------ 数据面板 */
.panel {
  position: absolute;
  top: 46px;
  right: 12px;
  z-index: 20;
  width: 460px;
  max-width: calc(100vw - 24px);
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

/* hidden 属性优先，避免被上面的 display 规则覆盖 */
.panel[hidden] {
  display: none;
}

.data-row {
  display: flex;
  gap: 10px;
  padding: 3px 0;
  font-size: 12px;
}

.data-label {
  flex: 0 0 74px;
  color: var(--fg-faint);
}

.data-value {
  color: var(--fg-dim);
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}

.mono {
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 11.5px;
}

.data-help {
  margin: 10px 0;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 7px;
  color: var(--fg-faint);
  font-size: 11.5px;
  line-height: 1.7;
}

.data-help code {
  color: var(--accent);
  font-family: 'Cascadia Code', Consolas, monospace;
}

.data-actions {
  display: flex;
  gap: 7px;
}

.data-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--fg);
  font-size: 12px;
  font-family: 'Cascadia Code', Consolas, monospace;
  outline: none;
}

.data-input:focus {
  border-color: var(--accent-dim);
}

.data-msg {
  margin-top: 9px;
  font-size: 12px;
  min-height: 17px;
  color: var(--fg-faint);
}

.data-msg.ok {
  color: var(--accent);
}

.data-msg.err {
  color: #ef6b6b;
}

.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

/* ------------------------------------------------------------------ 布局 */
.layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  height: calc(100% - 46px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.search-wrap {
  position: relative;
  padding: 12px 12px 8px;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 46px 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent-dim);
}

.search-input::-webkit-search-cancel-button {
  display: none;
}

/* Esc 提示贴在输入框右侧 */
.kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--fg-faint);
  font-size: 11px;
  font-family: 'Cascadia Code', Consolas, monospace;
}

.search-wrap .kbd {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.status {
  padding: 0 14px 8px;
  color: var(--fg-faint);
  font-size: 12px;
}

/* ------------------------------------------------------------------ 结果表 */
.results {
  list-style: none;
  margin: 0;
  padding: 0 6px 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.result {
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.result:hover {
  background: var(--bg-hover);
}

.result.active {
  background: var(--bg-hover);
  border-left-color: var(--accent);
}

.result-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.result-name {
  font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-weight: 600;
  color: var(--fg);
}

.result-tag {
  font-size: 10px;
  color: var(--fg-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  white-space: nowrap;
}

.result-summary {
  color: var(--fg-dim);
  font-size: 12px;
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-snippet {
  margin-top: 4px;
  padding: 4px 7px;
  background: var(--bg);
  border-radius: 5px;
  color: var(--fg-faint);
  font-size: 11px;
  line-height: 1.5;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

mark {
  background: transparent;
  color: var(--mark);
  font-weight: 600;
}

/* ------------------------------------------------------------------ 详情区 */
.detail {
  /* 只有操作按钮浮动固定在右上角；命令名与正文一起滚动 */
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  -webkit-user-select: text;
  user-select: text;
}

.detail-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 34px 60px;
}

.placeholder {
  max-width: 420px;
  margin: 14vh auto 0;
  text-align: center;
  color: var(--fg-faint);
}

.placeholder-icon {
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 44px;
  color: var(--accent);
  opacity: 0.55;
}

.placeholder-title {
  margin: 14px 0 6px;
  font-size: 16px;
  color: var(--fg-dim);
}

.placeholder-hint {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.8;
}

.placeholder-keys {
  font-size: 12px;
}

.detail-head {
  padding: 18px 34px 14px;
  /* 右侧给浮动按钮留出位置，避免标题/说明被压到按钮底下 */
  padding-right: 330px;
  border-bottom: 1px solid var(--border);
}

.detail-title {
  font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  word-break: break-all;
}

.detail-summary {
  color: var(--fg-dim);
  margin: 4px 0 0;
  font-size: 13px;
}

.detail-actions {
  /* 浮动在详情区右上角，不随正文滚动 */
  position: absolute;
  top: 14px;
  right: 34px;
  z-index: 6;
  display: flex;
  gap: 7px;
  flex-shrink: 0;
  padding: 5px 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
}

/* 窗口不够宽时退回普通排布，免得标题被挤成一列窄条 */
@media (max-width: 1050px) {
  .detail-head {
    padding-right: 34px;
  }

  .detail-actions {
    position: static;
    margin: 12px 34px 0;
    justify-content: flex-end;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
  }
}

.act-btn {
  padding: 5px 11px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--fg-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.act-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.act-btn.done {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.act-btn.primary {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--bg);
}

.act-btn.primary:hover {
  background: var(--accent-dim);
  color: var(--bg);
}

.act-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.act-btn:disabled:hover {
  background: var(--bg-elev);
  color: var(--fg-dim);
}

/* 预渲染正文：内容来自数据库，样式在这里统一收口 */
.doc {
  /* 不设 max-width：窗口多宽就用多宽。
     之前限死 860px，结果在大窗口里正文只占一半，代码块反而因为太窄而出现横向滚动条。 */
  max-width: none;
  word-wrap: break-word;
}

.doc h2,
.doc h3,
.doc h4,
.doc h5,
.doc h6 {
  margin: 22px 0 9px;
  font-weight: 600;
  line-height: 1.4;
}

.doc h2 {
  font-size: 18px;
  color: var(--fg);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.doc h3 {
  font-size: 15px;
  color: var(--fg);
}

.doc h4,
.doc h5,
.doc h6 {
  font-size: 14px;
  color: var(--fg-dim);
}

.doc p {
  margin: 9px 0;
}

.doc a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-dim);
  cursor: pointer;
}

.doc a:hover {
  border-bottom-style: solid;
}

.doc code {
  font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.doc pre {
  margin: 11px 0;
  padding: 12px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  /* 长行换行而不是横向滚动。
     这些手册的代码块里经常是成段的说明文字（比如「选项」一节），
     横向滚动条既碍眼又要额外操作；换行保留缩进，读起来更顺。
     overflow-x 留 auto 只是兜底，正常情况下不会触发。 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: auto;
  -webkit-user-select: text;
  user-select: text;
}

.doc pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.65;
}

.doc ul,
.doc ol {
  margin: 9px 0;
  padding-left: 24px;
}

.doc li {
  margin: 3px 0;
}

.doc blockquote {
  margin: 11px 0;
  padding: 3px 14px;
  border-left: 3px solid var(--accent-dim);
  background: var(--bg-elev);
  border-radius: 0 7px 7px 0;
  color: var(--fg-dim);
}

.doc table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

.doc th,
.doc td {
  border: 1px solid var(--border);
  padding: 6px 11px;
  text-align: left;
}

.doc th {
  background: var(--bg-elev);
  font-weight: 600;
}

.doc hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.doc kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-size: 12px;
  font-family: 'Cascadia Code', Consolas, monospace;
}

/* ------------------------------------------------------------------ 工具类 */
/* 剪贴板 API 不可用时用的离屏 textarea，不可用 display:none（那样选不中） */
.offscreen {
  position: fixed;
  top: -1000px;
  left: -1000px;
  opacity: 0;
}

/* ------------------------------------------------------------------ 滚动条 */
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--fg-faint);
  background-clip: content-box;
}

/* ==========================================================================
   本地编辑 / 冲突 / 同步面板
   ========================================================================== */

/* 状态徽标 */
.badges {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-faint);
  white-space: nowrap;
}

.chip-modified {
  color: var(--mark);
  border-color: var(--mark);
}

.chip-local {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* 顶栏按钮 */
.tbtn {
  font-size: 12px;
  font-family: inherit;
  padding: 3px 11px;
  border-radius: 999px;
  border: 1px solid var(--mark);
  background: var(--bg-elev);
  color: var(--mark);
  cursor: pointer;
}

.tbtn:hover {
  background: var(--bg-hover);
}

/* 通用面板（数据 / 冲突共用） */
.panel {
  position: absolute;
  top: 46px;
  right: 12px;
  z-index: 20;
  width: 470px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
}

.panel-wide {
  width: 860px;
}

.panel-title {
  font-weight: 600;
  margin-bottom: 10px;
}

.panel-help {
  margin: 10px 0;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 7px;
  color: var(--fg-faint);
  font-size: 11.5px;
  line-height: 1.7;
}

.panel-help code {
  color: var(--accent);
  font-family: 'Cascadia Code', Consolas, monospace;
}

.panel-actions {
  display: flex;
  gap: 7px;
  margin-top: 8px;
}

.muted {
  color: var(--fg-faint);
  font-size: 12px;
  font-weight: 400;
}

/* 编辑器 */
.editor {
  width: 100%;
  min-height: 60vh;
  margin-top: 0;
  padding: 14px 16px;
  background: var(--bg-panel);
  color: var(--fg);
  border: 1px solid var(--accent-dim);
  border-radius: 9px;
  font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.65;
  resize: vertical;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

/* 冲突卡片 */
.conflict-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.conflict-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  background: var(--bg);
}

.conflict-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-family: 'Cascadia Code', Consolas, monospace;
}

.conflict-note {
  color: var(--fg-dim);
  font-size: 12.5px;
  margin: 6px 0;
}

.conflict-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 900px) {
  .conflict-cols {
    grid-template-columns: 1fr;
  }
}

.conflict-col-title {
  font-size: 11.5px;
  color: var(--fg-faint);
  margin-bottom: 4px;
}

.conflict-col.ours .conflict-col-title {
  color: var(--accent);
}

.conflict-col.theirs .conflict-col-title {
  color: var(--mark);
}

.conflict-pre {
  margin: 0;
  padding: 9px 11px;
  max-height: 190px;
  overflow: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}

.conflict-detail {
  margin-top: 9px;
  font-size: 12px;
  color: var(--fg-faint);
}

.conflict-detail summary {
  cursor: pointer;
}

.conflict-detail .conflict-pre {
  margin-top: 7px;
}

.conflict-actions {
  display: flex;
  gap: 7px;
  margin-top: 11px;
}

/* 侧栏过滤开关 */
.filters {
  display: flex;
  gap: 12px;
  padding: 0 14px 8px;
  font-size: 12px;
  color: var(--fg-dim);
  flex-wrap: wrap;
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.filter input {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ==========================================================================
   应用内对话框
   不用 window.prompt / confirm / alert —— webview 对脚本对话框的处理
   不一定可预期，而且单行 prompt 也不适合编辑 markdown。
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 560px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 18px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.modal-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field label {
  display: block;
  font-size: 12px;
  color: var(--fg-faint);
  margin-bottom: 5px;
}

.modal-input,
.modal-textarea {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.modal-input:focus,
.modal-textarea:focus {
  border-color: var(--accent-dim);
}

.modal-textarea {
  min-height: 300px;
  font-family: 'Cascadia Code', Consolas, monospace;
  line-height: 1.6;
  resize: vertical;
}

.modal-hint {
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 7px;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.act-btn.small {
  padding: 2px 9px;
  font-size: 11.5px;
}

.new-btn {
  margin-left: auto;
}

.chip-deleted {
  color: #ef6b6b;
  border-color: #ef6b6b;
  text-decoration: line-through;
}

.act-btn.danger {
  color: #ef6b6b;
  border-color: #7a3a3a;
}

.act-btn.danger:hover {
  background: #4a2626;
  color: #ffb3b3;
}

/* 设置面板：配置云端备份并展示任务状态。 */
.settings-panel { width: 660px; padding: 22px 24px; }
.settings-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.settings-heading h2 { font-size: 19px; margin: 0; }
.settings-heading p { color: var(--fg-faint); font-size: 12px; margin: 4px 0 16px; }
.settings-section { border-top: 1px solid var(--border); padding: 16px 0 0; margin-top: 6px; }
.settings-section h3 { font-size: 14px; margin: 0 0 12px; }
.settings-label { display: block; font-size: 12px; color: var(--fg-dim); margin: 12px 0 6px; }
.settings-note { color: var(--fg-faint); font-size: 12px; margin: 8px 0 14px; line-height: 1.7; }
@media (max-width: 760px) { .settings-panel { padding: 16px; } }

/* 未登录用户保留阅读入口，管理操作由后端再次校验权限。 */
body[data-role="reader"] [data-admin] { display: none !important; }
#webSettings > .data-input { width: 100%; box-sizing: border-box; }
#backupFiles { max-width: 100%; }
#backupStatus { overflow-wrap: anywhere; }

/* 登录入口和可选区域的隐藏状态优先于通用按钮布局。 */
[hidden] { display: none !important; }
