/* Corneliang Workspace — 三欄布局(資料夾 | 文件 | 對話) */
:root {
  --ink: #1c1f21;
  --ink-soft: #5c6468;
  --bg: #f0f1ee;
  --panel: #ffffff;
  --line: #e0e3df;
  --accent: #0d7a6c;
  --accent-soft: #e3f1ee;
  --danger: #b3352f;
  --radius: 10px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "Microsoft JhengHei", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.6;
}

/* ---------- 頂欄 ---------- */
.topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 0 18px;
}
.topbar-brand { font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.login-dot { color: var(--accent); padding: 0 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 13px; color: var(--ink-soft); background: var(--bg); padding: 4px 10px; border-radius: 20px; }

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid transparent; background: var(--bg); color: var(--ink);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 14px;
}
.btn:hover { border-color: var(--line); }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); background: var(--bg); }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; margin-top: 6px; }
.iconbtn {
  border: none; background: transparent; color: var(--ink-soft); cursor: pointer;
  width: 28px; height: 28px; border-radius: 7px; font-size: 15px; line-height: 1;
}
.iconbtn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- 登入頁 ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background:
  radial-gradient(1200px 500px at 80% -10%, #eef5f2 0%, transparent 60%), var(--bg); }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 34px 32px; box-shadow: 0 18px 40px rgba(28, 31, 33, .06);
}
.login-brand { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.login-sub { color: var(--ink-soft); font-size: 13px; margin: 2px 0 22px; }
.login-card label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 14px; }
.login-card input {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px; font-family: inherit;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-err { color: var(--danger); font-size: 13px; margin: 2px 0 10px; }

/* ============================================================
   三欄工作區(資料夾 10% | 文件 60% | 對話 30%)
   ============================================================ */
main.ws {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(0, 6fr) minmax(280px, 3fr);
  height: calc(100vh - 52px);
  overflow: hidden;
}
.col { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.col + .col { border-left: 1px solid var(--line); }

/* --- 各欄小標題列 --- */
.col-head {
  display: flex; align-items: center; gap: 2px; padding: 6px 8px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex: 0 0 auto;
}
.col-title {
  margin-left: auto; font-size: 11px; font-weight: 600; letter-spacing: .14em;
  color: #9aa19d; text-transform: uppercase; padding-right: 2px;
}

/* --- 左欄:資料夾樹 --- */
.col-tree { background: #fbfcfa; }
.vault-tree { flex: 1; overflow-y: auto; padding: 8px 6px 16px; font-size: 13.5px; }
.dir-node { margin-left: 2px; }
.dir-node summary { cursor: pointer; padding: 3px 6px; border-radius: 6px; list-style: none; user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-node summary:hover { background: var(--bg); }
.dir-node summary::before { content: '▸'; display: inline-block; width: 14px; color: #a9b0ad; }
.dir-node[open] > summary::before { content: '▾'; }
.dir-node div { margin-left: 10px; border-left: 1px solid var(--line); padding-left: 4px; }
.file-node { padding: 3px 6px 3px 20px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-node:hover { background: var(--bg); }
.file-node.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* --- 中欄:文件 --- */
.file-crumb {
  flex: 0 0 auto; min-height: 41px; padding: 8px 14px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.crumb-empty { color: #a9b0ad; }
.file-body { flex: 1; overflow-y: auto; padding: 22px 26px 40px; background: var(--panel); }
.file-empty { color: var(--ink-soft); text-align: center; padding-top: 60px; font-size: 14px; line-height: 2; }
.md-view {
  max-width: 860px; margin: 0 auto; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 26px 32px;
}
.md-view h1 { font-size: 24px; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 14px; }
.md-view h2 { font-size: 19px; margin: 18px 0 8px; }
.md-view p { margin: 8px 0; }
.md-view ul, .md-view ol { margin: 6px 0 10px 22px; }
.md-view img { max-width: 100%; border-radius: 8px; }
.md-view blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--ink-soft); margin: 8px 0; }
.md-view code { background: rgba(127,127,127,.12); padding: 1px 5px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.md-view pre { background: #1c1f21; color: #e8ece8; padding: 12px 14px; border-radius: 9px; overflow-x: auto; }
.md-view pre code { background: none; color: inherit; padding: 0; }
.md-view a { color: var(--accent); }
.note-editor {
  flex: 1; width: 100%; min-height: 62vh; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; font-family: ui-monospace, SFMono-Regular, Consolas, "PingFang HK", monospace;
  font-size: 14px; line-height: 1.7; resize: none; display: block;
}
.edit-bar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 10px; }
.preview-img { max-width: 100%; border-radius: 10px; }
.preview-frame { width: 100%; height: calc(100vh - 120px); border: none; border-radius: 8px; }

/* --- 右欄:對話 --- */
.col-chat { background: var(--panel); }
.chat-head { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.topic-select {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; background: #fff;
  text-overflow: ellipsis;
}
.chat-status { font-size: 11.5px; color: var(--accent); font-weight: 500; white-space: nowrap; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow-y: auto; padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 10px; background: #fbfcfa; }
.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.bubble {
  max-width: 92%; padding: 8px 12px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--line); white-space: normal;
  word-break: break-word; overflow-wrap: anywhere; font-size: 14px;
}
.msg-user .bubble { background: var(--accent); color: #fff; border: none; border-bottom-right-radius: 4px; }
.msg-agent .bubble { border-bottom-left-radius: 4px; }
.msg-error .bubble { border-color: #ecc; color: var(--danger); }
.bubble p { margin: 0 0 7px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px 18px; }
.bubble code { background: rgba(127,127,127,.14); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.bubble pre { background: #1c1f21; color: #e8ece8; padding: 9px 11px; border-radius: 9px; overflow-x: auto; margin: 6px 0; font-size: 12.5px; }
.bubble pre code { background: none; padding: 0; color: inherit; }
.bubble a { color: var(--accent); }
.bubble h1,.bubble h2,.bubble h3 { font-size: 15px; margin: 8px 0 4px; }
.typing { color: var(--ink-soft); }

.composer {
  flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px;
  font-family: inherit; font-size: 14px; line-height: 1.5; max-height: 130px; min-height: 38px;
}
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.composer .btn { padding: 8px 15px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1c1f21; color: #fff; padding: 9px 18px; border-radius: 20px; font-size: 13.5px;
  box-shadow: 0 10px 26px rgba(0,0,0,.2); z-index: 99;
}

/* ---------- 細螢幕 ---------- */
@media (max-width: 1240px) {
  main.ws { grid-template-columns: 170px minmax(0, 1fr) 320px; }
}
@media (max-width: 960px) {
  main.ws { grid-template-columns: 150px minmax(0, 1fr) 300px; }
  .md-view { padding: 18px 20px; }
  .file-body { padding: 16px 16px 30px; }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  main.ws {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 28vh) minmax(0, 60vh) minmax(0, 70vh);
    height: auto; overflow: visible;
  }
  .col + .col { border-left: none; border-top: 1px solid var(--line); }
  .preview-frame { height: 56vh; }
}

/* Back-to-Home links */
.login-back { display: inline-block; margin-bottom: 16px; font-size: 13px; color: var(--ink-soft); text-decoration: none; }
.login-back:hover { color: var(--accent); }
.topbar-home { font-size: 13px; color: var(--ink-soft); text-decoration: none; margin-right: 14px; white-space: nowrap; }
.topbar-home:hover { color: var(--accent); }
