:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b5bfd;
  --primary-hover: #2d4ae0;
  --primary-soft: rgba(59, 91, 253, 0.1);
  --green: #0d9488;
  --red: #dc2626;
  --warn: #d97706;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
}

[data-theme="tech"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #283548;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-soft: rgba(56, 189, 248, 0.14);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

[data-theme="aurora"] {
  --bg: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 50%, #ecfeff 100%);
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(248, 250, 252, 0.9);
  --text: #1e1b4b;
  --muted: #6366f1;
  --border: rgba(129, 140, 248, 0.25);
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: rgba(124, 58, 237, 0.12);
}

[data-theme="guofeng"] {
  --bg: #f6f1e7;
  --surface: #fcfaf5;
  --surface-2: #f2eadc;
  --text: #2c251d;
  --muted: #786b59;
  --border: #dfd3be;
  --primary: #a6342a;
  --primary-hover: #8a281f;
  --primary-soft: rgba(166, 52, 42, 0.1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}

.brand-badge {
  background: var(--primary);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.top-nav {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

.nav-pill {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.nav-pill.active, .nav-pill:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.app-shell {
  display: flex;
  height: calc(100vh - 58px);
}

.sidebar {
  width: 84px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-item {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 6px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

.side-item.active, .side-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.side-icon { font-size: 18px; line-height: 1.2; }

.workspace {
  flex: 1;
  padding: 16px 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  gap: 12px;
}

.tab-panel.active { display: flex; }

.toolbar-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.flex-grow { flex: 1; min-width: 240px; }

.split-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.doc-card { flex: 1; }

.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
}

.card-title { font-weight: 600; font-size: 14px; }

.card-actions { display: flex; align-items: center; gap: 8px; }

.editor-area, .output-area {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.75;
  background: transparent;
  color: var(--text);
  overflow-y: auto;
}

.output-area { white-space: pre-wrap; word-break: break-word; }
.output-area.placeholder, .placeholder { color: var(--muted); }

.card-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  background: var(--surface-2);
}

.hint-warn { color: var(--warn); }
.char-counter, .status-text { color: var(--muted); white-space: nowrap; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: 0.15s ease;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 9px; font-size: 12px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }

.select-control, .select-compact, .input-control {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

.input-control { width: 100%; }
.input-control:focus, .select-control:focus { border-color: var(--primary); }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.on { background: #22c55e; }
.status-dot.off { background: #f59e0b; }

.count-chip {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
}

.trial-badge {
  background: rgba(13, 148, 136, 0.12);
  color: var(--green);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.contact-modal-body { text-align: center; }
.contact-urgent {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}
.contact-wx-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}
.contact-qr-wrap img {
  width: 170px;
  height: 170px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: cover;
}

/* Diff highlighting */
.diff-del {
  background: rgba(220, 38, 38, 0.14);
  color: var(--red);
  text-decoration: line-through;
  padding: 0 2px;
  border-radius: 3px;
}

.diff-ins {
  background: rgba(13, 148, 136, 0.15);
  color: var(--green);
  padding: 0 2px;
  border-radius: 3px;
}

.diff-para { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px dashed var(--border); }

/* Doc preview */
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-dark { background: var(--text); }

.doc-preview {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  line-height: 1.8;
  font-size: 14.5px;
}
.doc-line { margin-bottom: 10px; }
.doc-line.rewritten { color: var(--green); }
.doc-line.kept { color: var(--red); font-weight: 600; }
.empty-doc { color: var(--muted); text-align: center; margin-top: 60px; }

/* Detect view */
.detect-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.metric-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.metric-val { font-size: 18px; font-weight: 700; color: var(--primary); }
.metric-lbl { font-size: 11px; color: var(--muted); }

.sent-item {
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 8px;
  border-left: 3px solid var(--border);
  background: var(--surface-2);
}
.sent-item.high { border-left-color: var(--red); background: rgba(220, 38, 38, 0.06); }
.sent-item.medium { border-left-color: var(--warn); background: rgba(217, 119, 6, 0.06); }
.sent-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.llm-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--primary-soft);
  font-size: 13px;
  line-height: 1.6;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-lg { max-width: 680px; }
.modal-header, .modal-footer {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close { border: none; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px; max-height: 68vh; overflow-y: auto; }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.form-note { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 8px 0 0; }
.faq-body p { font-size: 13.5px; line-height: 1.7; margin: 0 0 12px; }

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
}
.history-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.history-snippet { font-size: 13px; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 900px) {
  .top-nav { display: none; }
  .app-shell { flex-direction: column; height: auto; min-height: calc(100vh - 58px); }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .split-grid { grid-template-columns: 1fr; }
  .editor-area, .output-area { min-height: 240px; }
}
