*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0d0f;
  --surface: #121318;
  --surface2: #191b22;
  --border: #272a35;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --accent: #06b6d4;
  --success: #34c88a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #e8e2d6;
  --text-muted: #7a7060;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --glow-primary: rgba(99,102,241,0.18);
  --glow-accent: rgba(6,182,212,0.12);
}

:root.theme-light {
  --bg: #f5f0e8;
  --surface: #fffdf8;
  --surface2: #faf6ee;
  --border: #e8dfc8;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #0891b2;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #2a1f0e;
  --text-muted: #78634a;
  --glow-primary: rgba(79,70,229,0.12);
  --glow-accent: rgba(8,145,178,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--glow-primary) 30%, var(--glow-accent) 70%, transparent 100%);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  height: 20px;
  line-height: 20px;
  text-decoration: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  padding: 0 2px;
  border-radius: 6px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.brand-link:hover {
  color: var(--primary);
}
.header-sep {
  width: 1px;
  height: 15px;
  background: var(--border);
  margin: 0 12px;
  flex-shrink: 0;
}

.page-name {
  display: inline-flex;
  align-items: center;
  height: 20px;
  line-height: 20px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: -0.1px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }
.toolbar-group { display: flex; gap: 6px; }
.toolbar-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 7px; border: none;
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  box-shadow: 0 0 12px var(--glow-primary), 0 2px 4px rgba(0,0,0,.3);
  border: 1px solid var(--glow-primary);
}
.btn-primary:hover {
  filter: brightness(1.12);
  box-shadow: 0 0 18px var(--glow-primary), 0 2px 6px rgba(0,0,0,.3);
}
.btn-success  { background: rgba(52,200,138,.12); color: var(--success); border: 1px solid rgba(52,200,138,.25); }
.btn-success:hover { background: rgba(52,200,138,.22); box-shadow: 0 0 8px rgba(52,200,138,.2); }
.btn-warning  { background: rgba(245,158,11,.1); color: var(--warning); border: 1px solid rgba(245,158,11,.22); }
.btn-warning:hover { background: rgba(245,158,11,.2); box-shadow: 0 0 8px rgba(245,158,11,.2); }
.btn-ghost    { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--border); }
.btn-danger   { background: rgba(239,68,68,.12); color: var(--danger); border: 1px solid rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.22); }

:root.theme-light .btn-primary {
  color: #fff;
  box-shadow: 0 1px 8px var(--glow-primary);
}
:root.theme-light .btn-success {
  background: rgba(22,163,74,.1);
  color: #15803d;
  border-color: rgba(22,163,74,.3);
}
:root.theme-light .btn-success:hover { background: rgba(22,163,74,.2); }
:root.theme-light .btn-warning {
  background: rgba(217,119,6,.1);
  color: #b45309;
  border-color: rgba(217,119,6,.28);
}
:root.theme-light .btn-warning:hover { background: rgba(217,119,6,.2); }
:root.theme-light .btn-ghost {
  background: #fffdf8;
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
:root.theme-light .btn-ghost:hover { background: var(--surface2); color: var(--text); }

.settings-wrap { position: relative; }
.btn-settings {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-muted); cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background 0.15s, color 0.15s; white-space: nowrap; user-select: none;
}
.btn-settings:hover { color: var(--text); background: var(--border); }
.btn-settings.active { color: var(--primary); border-color: var(--primary); box-shadow: 0 0 8px var(--glow-primary); }
:root.theme-light .btn-settings {
  background: #fffdf8;
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
:root.theme-light .btn-settings:hover { background: var(--surface2); }

.settings-popover {
  display: none; position: absolute;
  top: calc(100% + 8px); right: 0; z-index: 200;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; min-width: 210px;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
}
.settings-popover.open { display: block; }
:root.theme-light .settings-popover {
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.settings-section-title {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px;
}

.theme-group {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.theme-opt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 7px 4px 6px;
  border-radius: 7px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.theme-opt:hover { background: var(--border); }
.theme-opt.sel { border-color: var(--primary); background: var(--glow-primary); }
.theme-swatch {
  width: 28px; height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.12);
}
.theme-swatch-dark  { background: linear-gradient(135deg, #0f1117 50%, #1a1d27 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #f4f5f7 50%, #ffffff 50%); }
.theme-opt-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.theme-opt.sel .theme-opt-label { color: var(--primary); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0; border-top: 1px solid var(--border);
}
.toggle-label { font-size: 13px; color: var(--text); }
.toggle-label small { display: block; font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: background 0.2s; }
.toggle input:checked + .toggle-track { background: linear-gradient(90deg, var(--primary), var(--accent)); }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; background: #fff; border-radius: 50%; transition: transform 0.2s; pointer-events: none; }
.toggle input:checked ~ .toggle-thumb { transform: translateX(16px); }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px; background: var(--surface2);
  border-bottom: 1px solid var(--border); flex-shrink: 0; min-height: 38px;
}
.panel-title {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; }
.panel-actions { display: flex; gap: 6px; align-items: center; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); cursor: pointer; font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon:active { transform: scale(0.93); }
:root.theme-light .btn-icon {
  background: #fffdf8;
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
:root.theme-light .btn-icon:hover { background: var(--surface2); color: var(--text); }

.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 24px; font-size: 11.5px; color: var(--text-muted);
  background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0;
  position: relative;
}
.status-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--glow-primary) 30%, var(--glow-accent) 70%, transparent 100%);
}
.status-left, .status-right { display: flex; gap: 16px; }
.status-item { display: flex; align-items: center; gap: 4px; }

#toast {
  position: fixed; bottom: 36px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1a1510; color: #e8dfc8;
  padding: 9px 20px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5), 0 0 16px var(--glow-primary);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s, transform 0.22s; white-space: nowrap;
  border: 1px solid var(--glow-primary); z-index: 999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
:root.theme-light #toast {
  background: #2a1f0e;
  color: #faf6ee;
  box-shadow: 0 6px 24px rgba(0,0,0,.2), 0 0 12px var(--glow-primary);
}

.history-wrap { position: relative; }
.history-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 300;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 320px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 0 16px var(--glow-primary);
  flex-direction: column;
}
.history-popover.open { display: flex; animation: ctxFadeIn 0.12s ease; }
@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.history-list-wrap {
  overflow-y: auto;
  max-height: 1060px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120,135,165,.2) transparent;
}
.history-list-wrap::-webkit-scrollbar { width: 5px; }
.history-list-wrap::-webkit-scrollbar-thumb { background: rgba(120,135,165,.2); border-radius: 3px; }
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.history-header-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
}
.history-clear-btn {
  font-size: 11px; color: var(--text-muted); cursor: pointer;
  padding: 2px 6px; border-radius: 4px;
  transition: background 0.12s, color 0.12s;
  border: none; background: transparent;
  user-select: none;
}
.history-clear-btn:hover { background: rgba(239,68,68,.12); color: var(--danger); }
.history-empty {
  padding: 20px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--glow-primary); }
.history-item-body { flex: 1; min-width: 0; }
.history-item-preview {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text);
  height: calc(11.5px * 1.65 * 2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}
.history-item-meta {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
:root.theme-light .history-popover {
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
:root.theme-light .history-item:hover { background: var(--glow-primary); }
:root.theme-light .history-item { border-bottom-color: rgba(0,0,0,.04); }

.main { flex: 1; display: flex; overflow: hidden; }
.panel { display: flex; flex-direction: column; overflow: hidden; min-width: 80px; }

.ctx-menu {
  position: fixed;
  z-index: 1000;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 140px;
  box-shadow: 0 8px 28px rgba(0,0,0,.4);
  display: none;
  animation: ctxFadeIn 0.1s ease;
}
.ctx-menu.open { display: block; }
.ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 11px; border-radius: 5px;
  cursor: pointer; font-size: 13px; color: var(--text);
  transition: background 0.1s; user-select: none;
}
.ctx-item:hover { background: var(--border); }
.ctx-item svg { flex-shrink: 0; opacity: 0.75; }
.ctx-sep {
  height: 1px; background: var(--border);
  margin: 3px 0;
}
.ctx-item-danger { color: var(--danger); }
.ctx-item-danger:hover { background: rgba(224,92,92,.12); }
.ctx-item-danger svg { opacity: 0.85; }
:root.theme-light .ctx-menu {
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
}

body.resizing { cursor: col-resize; user-select: none; }
