/* 內建字型：全字庫正楷體（標楷體的替代，見 packaging/fetch-fonts.sh）。
   電腦上有真的標楷體就用 local() 的，沒有才用內建的；「TW-Kai」是內建
   字型本身的名字。編輯器字型選單的「標楷體」寫的是
   "DFKai-SB", "BiauKai", "TW-Kai"，所以三個名字都登記。 */
@font-face { font-family: "DFKai-SB"; src: local("DFKai-SB"), local("標楷體"), url("vpndoc://app/fonts/TW-Kai.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "標楷體"; src: local("DFKai-SB"), local("標楷體"), url("vpndoc://app/fonts/TW-Kai.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "BiauKai"; src: local("BiauKai"), url("vpndoc://app/fonts/TW-Kai.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "TW-Kai"; src: local("TW-Kai"), url("vpndoc://app/fonts/TW-Kai.ttf") format("truetype"); font-display: swap; }

/* 文書 / 試算表 / 簡報 三個 app 共用的外殼樣式：側欄列表、頁首、選單列、
   工具列底、修改紀錄側板、對話框、狀態列。各 app 自己的部分在各自的 css。 */
:root {
  color-scheme: light;
  --accent: #1a73e8;
  --accent-dark: #1765cc;
  --bg: #f8f9fa;
  --side-bg: #f7f8fa;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --hover: #f1f3f4;
  --active: #e8f0fe;
  --active-text: #1967d2;
  --danger: #c5221f;
  --danger-bg: #fce8e6;
  --tool-bg: #edf2fa;
  --tool-hover: #d3e3fd;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", "Noto Sans TC", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button, input, select, textarea { font-family: inherit; }
.layout { display: flex; height: 100vh; }
.spacer { flex: 1; }
.icon-btn { border: none; background: transparent; cursor: pointer; border-radius: 50%; width: 28px; height: 28px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); }

/* 側欄 */
.sidebar { width: 260px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--side-bg); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.sidebar[hidden] { display: none; }
.new-btn { height: 36px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px; cursor: pointer; flex-shrink: 0; }
.new-btn:hover { background: var(--accent-dark); }
.search { height: 32px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; font-size: 13px; background: #fff; outline: none; flex-shrink: 0; }
.search:focus { border-color: var(--accent); }
.doc-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.doc-item { position: relative; padding: 8px 30px 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1.35; }
.doc-item:hover { background: #e8eaed; }
.doc-item.active { background: var(--active); color: var(--active-text); }
.doc-item .doc-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-item .doc-excerpt { display: block; font-size: 12px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.doc-item .doc-time { display: block; font-size: 11px; opacity: 0.65; margin-top: 3px; }
.doc-item .doc-delete { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border: none; border-radius: 6px; background: transparent; color: inherit; opacity: 0.55; cursor: pointer; font-size: 12px; line-height: 1; display: none; }
.doc-item:hover .doc-delete, .doc-item.active .doc-delete { display: block; }
.doc-item .doc-delete:hover { opacity: 1; background: rgba(0,0,0,0.12); }
.empty-hint { font-size: 12px; color: var(--muted); text-align: center; padding: 16px 0; }
.sidebar-footer { font-size: 11px; color: var(--muted); padding-top: 8px; border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }

/* 主區 */
.editor-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #fff; }
.docs-header { display: flex; align-items: flex-start; gap: 10px; padding: 8px 16px 2px 12px; flex-shrink: 0; }
.docs-logo { width: 40px; height: 40px; border: none; background: transparent; font-size: 26px; cursor: pointer; border-radius: 8px; margin-top: 2px; }
.docs-logo:hover { background: var(--hover); }
.docs-logo.back { font-size: 22px; font-weight: 600; color: var(--muted); }
.docs-header-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.docs-title-row { display: flex; align-items: center; gap: 10px; }
.title-input { border: 1px solid transparent; border-radius: 4px; outline: none; font-size: 18px; padding: 2px 6px; color: var(--text); background: transparent; min-width: 120px; max-width: 520px; width: 40%; }
.title-input:hover { border-color: var(--border); }
.title-input:focus { border-color: var(--accent); }
.title-input::placeholder { color: #9aa0a6; }
.saved-at { font-size: 12px; color: var(--muted); white-space: nowrap; }
.docs-header-right { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.header-btn { height: 36px; padding: 0 12px; border: none; border-radius: 18px; background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); white-space: nowrap; }
.header-btn:hover, .header-btn.on { background: var(--hover); color: var(--text); }
.share-btn { height: 36px; padding: 0 18px; border: none; border-radius: 18px; background: #c2e7ff; color: #001d35; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.share-btn:hover { background: #a8dafb; }

/* 選單列 */
.menubar { display: flex; gap: 2px; margin-top: 2px; position: relative; }
.menubar > button { height: 26px; padding: 0 8px; border: none; border-radius: 4px; background: transparent; cursor: pointer; font-size: 13.5px; color: var(--text); }
.menubar > button:hover, .menubar > button.open { background: var(--hover); }
.dropdown { position: absolute; z-index: 20; min-width: 230px; background: #fff; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.16), 0 8px 24px rgba(0,0,0,0.12); padding: 6px 0; }
.dropdown .item { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; height: 32px; padding: 0 16px 0 32px; border: none; background: transparent; text-align: left; font-size: 13.5px; cursor: pointer; color: var(--text); white-space: nowrap; }
.dropdown .item:hover, .dropdown .item.open { background: var(--hover); }
.dropdown .item[disabled] { color: #b0b4ba; cursor: default; }
.dropdown .item[disabled]:hover { background: transparent; }
.dropdown .item.danger { color: var(--danger); }
.dropdown .item .check { position: absolute; left: 12px; font-size: 12px; }
.dropdown .item .label { flex: 1; }
.dropdown .item .shortcut { color: var(--muted); font-size: 12px; }
.dropdown .item .arrow { color: var(--muted); font-size: 11px; }
.dropdown .sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown .submenu { position: absolute; left: 100%; top: -6px; }
.context-menu { position: fixed; z-index: 25; }

/* 工具列 */
.toolbar { display: flex; align-items: center; gap: 2px; height: 40px; margin: 6px 16px 0; padding: 0 10px; border-radius: 20px; background: var(--tool-bg); flex-shrink: 0; }
.toolbar button { height: 28px; min-width: 28px; padding: 0 6px; border: none; border-radius: 6px; background: transparent; cursor: pointer; font-size: 12.5px; color: var(--text); white-space: nowrap; }
.toolbar button:hover { background: var(--tool-hover); }
.toolbar button.active { background: var(--tool-hover); color: var(--active-text); }
.toolbar .sep { width: 1px; height: 18px; background: #c4c7c5; margin: 0 4px; flex-shrink: 0; }
.toolbar select { height: 28px; border: none; border-radius: 6px; background: transparent; font-size: 12.5px; cursor: pointer; padding: 0 4px; }
.toolbar select:hover { background: var(--tool-hover); }
.toolbar input[type="color"] { width: 28px; height: 24px; border: none; background: transparent; padding: 0; cursor: pointer; }
.toolbar .num-input { width: 40px; height: 26px; text-align: center; border: 1px solid #c4c7c5; border-radius: 6px; background: #fff; font-size: 12.5px; outline: none; }
/* 格式刷（文件、試算表、簡報共用）；--brush-cursor 是刷子游標，各頁面自己決定用在哪裡 */
:root { --brush-cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M4 21c2 0 4-1 4-3 0-1 1-2 2-2s2-1 2-2l8-8-3-3-8 8c-1 0-2 1-2 2s-1 2-2 2c-2 0-3 2-3 4 1 1 1 2 2 2z' fill='%231a73e8' stroke='white' stroke-width='1'/></svg>") 3 21; }
.toolbar .paint-btn.active { background: var(--tool-hover); color: var(--active-text); }
.toolbar .paint-btn.sticky { box-shadow: inset 0 0 0 2px var(--accent); }
.status { font-size: 12px; color: var(--muted); padding-right: 6px; }
.status.error { color: var(--danger); }

/* 工作區 + 修改紀錄側板 */
.workspace { flex: 1; display: flex; min-height: 0; background: var(--bg); margin-top: 8px; border-top: 1px solid var(--border); }
.history-panel { width: 300px; flex-shrink: 0; border-left: 1px solid var(--border); background: #fff; display: flex; flex-direction: column; }
.history-panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; gap: 4px; padding: 8px 10px 8px 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.panel-head .header-btn { height: 30px; padding: 0 10px; font-size: 12.5px; }
.history-list { flex: 1; overflow-y: auto; padding: 8px; }
.history-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.history-item:hover { background: var(--hover); }
.history-item.active { background: var(--active); color: var(--active-text); }
.history-item .h-time { font-weight: 600; }
.history-item .h-meta { font-size: 12px; opacity: 0.7; margin-top: 2px; }
.history-item.current .h-time::after { content: "（目前版本）"; font-weight: normal; font-size: 12px; opacity: 0.7; }
.panel-foot { font-size: 11px; color: var(--muted); padding: 10px 16px; border-top: 1px solid var(--border); }
.preview-banner { background: #fef7e0; border: 1px solid #f9d976; border-radius: 8px; padding: 8px 14px; display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 10px 16px 0; }
.preview-banner[hidden] { display: none; }
.preview-banner button { height: 30px; padding: 0 12px; border: none; border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; }
.preview-banner .restore { background: var(--accent); color: #fff; }

/* 狀態列 */
.statusbar { display: flex; align-items: center; gap: 14px; height: 26px; padding: 0 24px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); flex-shrink: 0; background: #fff; }

/* 對話框 */
.dialog { position: fixed; inset: 0; z-index: 30; background: rgba(32,33,36,0.45); display: flex; align-items: center; justify-content: center; padding: 24px; }
.dialog[hidden] { display: none; }
.dialog-box { background: #fff; border-radius: 12px; padding: 20px 22px; width: 440px; max-width: 100%; max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.2); font-size: 13.5px; line-height: 1.55; }
.dialog-title { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.dialog-body { margin-bottom: 12px; }
.dialog-body:empty { display: none; }
.dialog-body table { border-collapse: collapse; width: 100%; }
.dialog-body th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 10px 4px 0; white-space: nowrap; vertical-align: top; }
.dialog-body td { padding: 4px 0; word-break: break-all; }
.dialog-body kbd { background: #f1f3f4; border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 12px; }
.dialog-body .choice { display: block; width: 100%; text-align: left; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; margin-bottom: 6px; font-size: 13.5px; }
.dialog-body .choice:hover { background: var(--hover); }
.dialog-body .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.dialog-body .row input[type="number"], .dialog-body .row input[type="text"], .dialog-body .row select { height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; }
.dialog-body .row input[type="number"] { width: 80px; }
.dialog-input { width: 100%; height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; font-size: 13px; outline: none; margin-bottom: 14px; }
.dialog-input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button { height: 32px; padding: 0 14px; border: none; border-radius: 8px; background: var(--hover); cursor: pointer; font-size: 13px; }
.dialog-actions .dialog-ok { background: var(--accent); color: #fff; }
.dialog-actions .dialog-ok:hover { background: var(--accent-dark); }
.dialog-actions .dialog-ok.danger { background: var(--danger-bg); color: var(--danger); }
.dialog-cancel[hidden] { display: none; }
