/* ============================================================
   简法文书 v2.0 — 全局样式 (common.css)
   设计语言：浅冰蓝 + 浅灰白，细分割线、少阴影、线性图标
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --jw-primary: #1a73e8;
  --jw-primary-light: #e8f0fe;
  --jw-primary-dark: #1557b0;

  --jw-success: #38a169;
  --jw-success-light: #f0fff4;
  --jw-warning: #f9ab00;
  --jw-warning-light: #fffaf0;
  --jw-danger: #ea4335;
  --jw-danger-light: #fce8e6;

  --jw-gray-50: #f8f9fa;
  --jw-gray-100: #f1f3f4;
  --jw-gray-200: #e8eaed;
  --jw-gray-300: #dadce0;
  --jw-gray-400: #bdc1c6;
  --jw-gray-500: #9aa0a6;
  --jw-gray-600: #80868b;
  --jw-gray-700: #5f6368;
  --jw-gray-800: #3c4043;
  --jw-gray-900: #202124;

  --jw-bg: #ffffff;
  --jw-bg-secondary: #f7f9fb;
  --jw-text: #1a202c;
  --jw-text-secondary: #4a5568;
  --jw-text-muted: #a0aec0;
  --jw-border: #e2e8f0;
  --jw-border-light: #edf2f7;

  --jw-radius-sm: 6px;
  --jw-radius: 10px;
  --jw-radius-lg: 16px;
  --jw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --jw-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --jw-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);

  --jw-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --jw-font-mono: "SF Mono", "Fira Code", "Consolas", "Monaco", monospace;

  --jw-transition: 0.18s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--jw-font-sans);
  color: var(--jw-text);
  background-color: var(--jw-bg);
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

a { color: var(--jw-primary); text-decoration: none; }
a:hover { text-decoration: none; }

/* ---------- Buttons ---------- */
.jw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--jw-radius-sm);
  cursor: pointer;
  transition: all var(--jw-transition);
  white-space: nowrap;
  user-select: none;
  font-family: var(--jw-font-sans);
}
.jw-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.jw-btn--primary { background: var(--jw-primary); color: #fff; border-color: var(--jw-primary); }
.jw-btn--primary:hover:not(:disabled) { background: var(--jw-primary-dark); border-color: var(--jw-primary-dark); }
.jw-btn--outline { background: transparent; border-color: var(--jw-border); color: var(--jw-text-secondary); }
.jw-btn--outline:hover:not(:disabled) { background: var(--jw-gray-50); color: var(--jw-primary); border-color: var(--jw-primary); }
.jw-btn--success { background: var(--jw-success); color: #fff; }
.jw-btn--success:hover:not(:disabled) { background: #2f855a; }
.jw-btn--ghost { background: transparent; border-color: transparent; color: var(--jw-text-secondary); }
.jw-btn--ghost:hover:not(:disabled) { background: var(--jw-gray-100); color: var(--jw-text); }
.jw-btn--sm { padding: 5px 10px; font-size: 0.75rem; }
.jw-btn--full { width: 100%; justify-content: center; }
.jw-btn--icon { padding: 6px; border-radius: 50%; }

/* ---------- Loading Spinner ---------- */
.jw-loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--jw-gray-200);
  border-top-color: var(--jw-primary);
  border-radius: 50%;
  animation: jw-spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes jw-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Pulse ---------- */
.jw-pulse {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.jw-pulse__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--jw-primary);
  animation: jw-pulse-bounce 1.4s ease-in-out infinite both;
}
.jw-pulse__dot:nth-child(1) { animation-delay: -0.32s; }
.jw-pulse__dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes jw-pulse-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---------- Chat Bubble ---------- */
.jw-chat-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--jw-radius);
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
  animation: jw-fade-in 0.25s ease;
  white-space: normal;
}
.jw-chat-bubble--assistant {
  background: var(--jw-gray-100);
  color: var(--jw-text);
  border-top-left-radius: 2px;
  align-self: flex-start;
}
.jw-chat-bubble--user {
  background: var(--jw-primary);
  color: #fff;
  border-top-right-radius: 2px;
  align-self: flex-end;
  margin-left: auto;
}
.jw-chat-bubble p { margin: 0 0 6px; }
.jw-chat-bubble p:last-child { margin-bottom: 0; }
.jw-chat-bubble ul, .jw-chat-bubble ol { margin: 4px 0; padding-left: 20px; }
.jw-chat-bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--jw-font-mono);
  font-size: 0.85em;
}
.jw-chat-bubble--user code { background: rgba(255, 255, 255, 0.2); }

@keyframes jw-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Empty State ---------- */
.jw-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--jw-text-muted);
}

/* ---------- Scrollbar ---------- */
.jw-scroll-thin::-webkit-scrollbar { width: 5px; }
.jw-scroll-thin::-webkit-scrollbar-track { background: transparent; }
.jw-scroll-thin::-webkit-scrollbar-thumb { background: var(--jw-gray-300); border-radius: 3px; }
.jw-scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--jw-gray-400); }

/* ---------- Toast ---------- */
.jw-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--jw-gray-900);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  max-width: 80vw;
  text-align: center;
}
.jw-toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 审阅风险环 ---------- */
.jw-risk-ring {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--jw-border-light);
}
.jw-risk-ring__svg { width: 72px; height: 72px; flex-shrink: 0; }
.jw-risk-ring__bg { fill: none; stroke: var(--jw-gray-200); stroke-width: 8; }
.jw-risk-ring__fill { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.6s; }
.jw-risk-ring__score {
  fill: var(--jw-text);
  font-size: 1.4rem;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}
.jw-risk-ring__meta { margin-left: 12px; }
.jw-risk-ring__label { font-size: 0.8rem; color: var(--jw-text-secondary); }
.jw-risk-ring__sub { font-size: 0.72rem; color: var(--jw-text-muted); margin-top: 2px; }
.jw-risk-ring__summary {
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--jw-text);
  line-height: 1.6;
  border-bottom: 1px solid var(--jw-border-light);
}

/* ---------- 风险项 ---------- */
.jw-risk-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--jw-gray-100);
  cursor: pointer;
  transition: background 0.15s;
}
.jw-risk-item:hover { background: var(--jw-gray-50); }
.jw-risk-item__severity { width: 6px; height: 6px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.jw-risk-item__severity--high { background: #ea4335; box-shadow: 0 0 0 3px rgba(234, 67, 53, 0.18); }
.jw-risk-item__severity--medium { background: #f9ab00; box-shadow: 0 0 0 3px rgba(249, 171, 0, 0.18); }
.jw-risk-item__severity--low { background: #38a169; box-shadow: 0 0 0 3px rgba(56, 161, 105, 0.18); }
.jw-risk-item__body { flex: 1; min-width: 0; }
.jw-risk-item__clause { font-size: 0.8rem; font-weight: 500; color: var(--jw-text); margin-bottom: 2px; }
.jw-risk-item__suggestion { font-size: 0.75rem; color: var(--jw-text-secondary); line-height: 1.5; }

/* ---------- 优化建议项 ---------- */
.jw-suggestion-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--jw-gray-100);
  font-size: 0.78rem;
  line-height: 1.5;
  transition: all 0.2s;
}
.jw-suggestion-item__original { color: var(--jw-text-muted); text-decoration: line-through; margin-bottom: 4px; }
.jw-suggestion-item__optimized { color: var(--jw-primary); font-weight: 500; margin-bottom: 4px; }
.jw-suggestion-item__reason { font-size: 0.72rem; color: var(--jw-text-muted); margin-bottom: 8px; }
.jw-suggestion-item__actions { display: flex; gap: 6px; }

/* ---------- 解读面板 / 格式预览 ---------- */
.jw-interpret-panel { padding: 12px; font-size: 0.85rem; line-height: 1.7; color: var(--jw-text); }
.jw-interpret-panel__label {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--jw-text-secondary);
  margin-bottom: 6px;
}
.jw-interpret-panel__content {
  padding: 10px 12px;
  background: var(--jw-gray-50);
  border-radius: 6px;
  font-size: 0.82rem;
}
.jw-format-preview {
  padding: 12px;
  border: 1px solid var(--jw-gray-200);
  border-radius: 6px;
  background: var(--jw-bg);
  white-space: pre-wrap;
  font-family: var(--jw-font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  max-height: 260px;
  overflow-y: auto;
  margin: 8px 0;
}
.jw-toolkit-result-action { padding: 0 12px 12px; display: flex; }
.jw-law-search__hint {
  font-size: 0.75rem;
  color: var(--jw-text-muted);
  margin-bottom: 8px;
}
.jw-toolkit-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  font-size: 0.85rem;
  color: var(--jw-text-secondary);
}
.jw-toolkit-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  font-size: 0.82rem;
  color: var(--jw-danger);
}

/* ---------- 编辑器高亮行（审阅联动） ---------- */
.jw-highlight-line {
  background: rgba(249, 171, 0, 0.22) !important;
}

/* ============================================================
   暗色模式 (data-theme="dark")
   ============================================================ */
[data-theme="dark"] {
  --jw-primary: #8ab4f8;
  --jw-primary-light: #1a2a3d;
  --jw-primary-dark: #aecbfa;
  --jw-bg: #1e1e1e;
  --jw-bg-secondary: #242424;
  --jw-text: #e8eaed;
  --jw-text-secondary: #9aa0a6;
  --jw-text-muted: #6b7280;
  --jw-border: #3c4043;
  --jw-border-light: #333;
  --jw-gray-50: #2a2a2a;
  --jw-gray-100: #2f2f2f;
  --jw-gray-200: #3c4043;
  --jw-gray-300: #484848;
  --jw-gray-400: #5a5a5a;
  --jw-gray-500: #6e6e6e;
  --jw-gray-600: #808080;
  --jw-gray-700: #999999;
  --jw-gray-800: #bbbbbb;
  --jw-gray-900: #e8eaed;
  --jw-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --jw-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

  --ws-bg: #171717;
  --ws-surface: #1e1e1e;
  --ws-surface-hover: #2a2a2a;
  --ws-border: #333;
  --ws-border-light: #2a2a2a;
  --ws-text: #e8eaed;
  --ws-text-secondary: #9aa0a6;
  --ws-text-muted: #6b7280;
  --ws-primary: #8ab4f8;
  --ws-primary-light: #1a2a3d;
  --ws-primary-hover: #aecbfa;
  --ws-success: #5cb85c;
  --ws-success-light: #1a2d1a;
  --ws-warning: #ffa726;
  --ws-warning-light: #2d1f0a;
}
