/* ============================================================
   简法文书 v2.0 — 三栏对话工作台 (workspace.css)
   布局：左 260px 会话列表（可折叠）｜ 中 flex:1 对话窗口 ｜ 右 420px 预览编辑器
   设计：浅冰蓝 + 浅灰白，细分割线、少阴影、线性图标
   ============================================================ */

:root {
  --ws-bg: #f7f9fb;
  --ws-surface: #ffffff;
  --ws-surface-hover: #f0f4f8;
  --ws-border: #e2e8f0;
  --ws-border-light: #edf2f7;
  --ws-text: #1a202c;
  --ws-text-secondary: #4a5568;
  --ws-text-muted: #a0aec0;
  --ws-primary: #1a73e8;
  --ws-primary-light: #e8f0fe;
  --ws-primary-hover: #1557b0;
  --ws-success: #38a169;
  --ws-success-light: #f0fff4;
  --ws-warning: #ed8936;
  --ws-warning-light: #fffaf0;
  --ws-radius: 6px;
  --ws-radius-sm: 4px;
  --ws-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------- Workspace Container ---------- */
.jw-workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--ws-bg);
  font-family: var(--ws-font);
}
.jw-workspace__body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ---------- 全局导航 ---------- */
.jw-global-nav {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--ws-surface);
  border-bottom: 1px solid var(--ws-border);
  flex-shrink: 0;
  z-index: 200;
}
.jw-global-nav__left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.jw-global-nav__brand {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ws-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.jw-global-nav__brand i { font-size: 1.2rem; }
.jw-global-nav__badge {
  font-size: 0.62rem;
  font-weight: 600;
  background: var(--ws-primary-light);
  color: var(--ws-primary);
  padding: 2px 7px;
  border-radius: 4px;
}
.jw-global-nav__right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.jw-global-nav__hint {
  font-size: 0.78rem;
  color: var(--ws-text-muted);
}
.jw-global-nav__link {
  font-size: 0.82rem;
  color: var(--ws-text-secondary);
  background: transparent;
  border: none;
  padding: 6px 10px;
  border-radius: var(--ws-radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.jw-global-nav__link:hover { background: var(--ws-surface-hover); color: var(--ws-text); }

/* ---------- 面板通用 ---------- */
.jw-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: var(--ws-surface);
  border-right: 1px solid var(--ws-border);
}
.jw-panel:last-child { border-right: none; }
.jw-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 42px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--ws-border-light);
}
.jw-panel__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ws-text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.jw-panel__title i { color: var(--ws-primary); font-size: 0.9rem; }
.jw-panel__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.jw-panel__body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- 左栏：会话列表 ---------- */
.jw-panel--left {
  width: 260px;
  min-width: 260px;
  max-width: 380px;
  transition: width 0.22s ease, min-width 0.22s ease;
}
.jw-panel--left.jw-panel--collapsed {
  width: 40px;
  min-width: 40px;
  overflow: hidden;
}
.jw-panel--left.jw-panel--collapsed .jw-panel__title,
.jw-panel--left.jw-panel--collapsed .jw-session-new,
.jw-panel--left.jw-panel--collapsed .jw-session-list { display: none; }
.jw-panel--left.jw-panel--collapsed .jw-panel__header { justify-content: center; padding: 0; }

.jw-session-new { padding: 12px 14px; border-bottom: 1px solid var(--ws-border-light); }
.jw-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.jw-session-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 16px;
  color: var(--ws-text-muted);
  font-size: 0.8rem;
  text-align: center;
}
.jw-session-empty i { font-size: 1.8rem; opacity: 0.5; }
.jw-session-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px;
  border-radius: var(--ws-radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.jw-session-item:hover { background: var(--ws-surface-hover); }
.jw-session-item--active { background: var(--ws-primary-light); }
.jw-session-item--active:hover { background: var(--ws-primary-light); }
.jw-session-item__main { flex: 1; min-width: 0; }
.jw-session-item__title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ws-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.jw-session-item__preview {
  font-size: 0.74rem;
  color: var(--ws-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.jw-session-item__time {
  font-size: 0.68rem;
  color: var(--ws-text-muted);
}
.jw-session-item__delete {
  background: transparent;
  border: none;
  color: var(--ws-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--ws-radius-sm);
  flex-shrink: 0;
  opacity: 0;
  transition: all 0.15s;
}
.jw-session-item:hover .jw-session-item__delete { opacity: 1; }
.jw-session-item__delete:hover { color: var(--ws-danger); background: var(--ws-danger-light); }

/* ---------- 中栏：对话窗口 ---------- */
.jw-panel--center { flex: 1; min-width: 0; }

.jw-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--ws-surface);
  border-bottom: 1px solid var(--ws-border);
  flex-shrink: 0;
  gap: 12px;
}
.jw-toolbar__left { display: flex; align-items: center; min-width: 0; }
.jw-conversation-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ws-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.jw-toolbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.jw-toolbar__btn {
  padding: 5px 11px;
  font-size: 0.78rem;
  color: var(--ws-text-secondary);
  background: transparent;
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
  font-family: var(--ws-font);
  white-space: nowrap;
}
.jw-toolbar__btn:hover {
  background: var(--ws-surface-hover);
  border-color: var(--ws-primary-light);
  color: var(--ws-primary);
}
.jw-toolbar__btn--active {
  background: var(--ws-primary-light);
  border-color: var(--ws-primary);
  color: var(--ws-primary);
}
.jw-toolbar__divider {
  width: 1px;
  height: 20px;
  background: var(--ws-border);
  margin: 0 4px;
}

/* 法律工具下拉面板 */
.jw-toolkit-anchor { position: relative; }
.jw-toolkit-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 70vh;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius);
  box-shadow: var(--jw-shadow-lg);
  z-index: 500;
  overflow: hidden;
}
.jw-toolkit-content {
  max-height: 70vh;
  overflow-y: auto;
  padding: 10px 12px;
}
.jw-toolkit-group { margin-bottom: 14px; }
.jw-toolkit-group:last-child { margin-bottom: 0; }
.jw-toolkit-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--ws-border-light);
}
.jw-toolkit-group__title span:first-child {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ws-text-secondary);
}
.jw-toolkit-group__badge {
  font-size: 0.65rem;
  padding: 1px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.jw-toolkit-group__badge--free { background: var(--ws-success-light); color: var(--ws-success); }
.jw-toolkit-group__badge--premium { background: var(--ws-warning-light); color: var(--ws-warning); }
.jw-toolkit-items { display: flex; flex-direction: column; gap: 3px; }
.jw-toolkit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--ws-radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--ws-font);
  color: var(--ws-text-secondary);
}
.jw-toolkit-item:hover { background: var(--ws-surface-hover); border-color: var(--ws-border); }
.jw-toolkit-item i { font-size: 1rem; color: var(--ws-primary); flex-shrink: 0; width: 20px; text-align: center; }
.jw-toolkit-item span { font-size: 0.82rem; font-weight: 500; flex-shrink: 0; }
.jw-toolkit-item small { margin-left: auto; font-size: 0.7rem; color: var(--ws-text-muted); }
.jw-toolkit-results {
  margin-top: 10px;
  background: var(--ws-bg);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius-sm);
  font-size: 0.8rem;
  color: var(--ws-text);
  line-height: 1.6;
  max-height: 320px;
  overflow-y: auto;
}

/* 对话消息区 */
.jw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--ws-bg);
}
.jw-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  color: var(--ws-text-muted);
  text-align: center;
}
.jw-chat-empty i { font-size: 2.4rem; opacity: 0.4; }
.jw-chat-empty__title { font-size: 1rem; font-weight: 600; color: var(--ws-text-secondary); }
.jw-chat-empty__desc { font-size: 0.82rem; max-width: 320px; line-height: 1.6; }
.jw-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ws-text-secondary);
}
.jw-chat-typing__text { font-size: 0.8rem; }

/* 输入区 */
.jw-chat-input-area {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--ws-border);
  background: var(--ws-surface);
  flex-shrink: 0;
  align-items: flex-end;
}
.jw-chat-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.9rem;
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius);
  resize: none;
  font-family: var(--ws-font);
  color: var(--ws-text);
  background: var(--ws-bg);
  line-height: 1.5;
  min-height: 44px;
  max-height: 120px;
}
.jw-chat-input:focus {
  outline: none;
  border-color: var(--ws-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}
.jw-chat-input::placeholder { color: var(--ws-text-muted); }
.jw-chat-send { height: 44px; width: 48px; border-radius: var(--ws-radius); }

/* ---------- 右栏：预览编辑器 ---------- */
.jw-panel--right {
  width: 420px;
  min-width: 420px;
  max-width: 600px;
  transition: width 0.22s ease, min-width 0.22s ease;
}
.jw-panel--right.jw-panel--collapsed {
  width: 40px;
  min-width: 40px;
  overflow: hidden;
}
.jw-panel--right.jw-panel--collapsed .jw-panel__title,
.jw-panel--right.jw-panel--collapsed .jw-panel__body,
.jw-panel--right.jw-panel--collapsed #btnTogglePreview { display: none; }
.jw-panel--right.jw-panel--collapsed .jw-panel__header { justify-content: center; padding: 0; }

.jw-editor-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
  text-align: center;
  padding: 32px;
}
.jw-editor-empty i {
  font-size: 2.6rem;
  color: var(--ws-border);
  margin-bottom: 14px;
  opacity: 0.6;
}
.jw-editor-empty__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ws-text-secondary);
  margin-bottom: 6px;
}
.jw-editor-empty__desc {
  font-size: 0.8rem;
  color: var(--ws-text-muted);
  line-height: 1.6;
  max-width: 280px;
}
#editorTextarea { display: none; width: 100%; height: 100%; }

/* ---------- Scrollbar ---------- */
.jw-scroll-thin::-webkit-scrollbar { width: 4px; }
.jw-scroll-thin::-webkit-scrollbar-thumb { background: var(--ws-border); border-radius: 2px; }
.jw-scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--ws-text-muted); }

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .jw-panel--right { width: 360px; min-width: 360px; }
}
@media (max-width: 860px) {
  .jw-panel--left { display: none; }
  .jw-panel--right { width: 100%; min-width: 0; border-left: none; border-top: 1px solid var(--ws-border); }
  .jw-workspace__body { flex-direction: column; }
  .jw-panel--center { min-height: 55vh; }
  .jw-panel--right { min-height: 45vh; }
}
