:root {
  color-scheme: dark light;
  --accent-primary: #6366f1;
  --accent-secondary: #818cf8;
  --accent-light: #c7d2fe;
  --accent-ink: #4f46e5;
  --text-primary: #e0e0f0;
  --text-secondary: #8888a0;
  --text-muted: #6a6a90;
  --card-bg: #fff;
  --card-shadow: 0 8px 32px rgba(0,0,0,.12);
  --card-radius: 18px;
  --card-dark-bg: rgba(99,102,241,.08);
  --card-dark-border: rgba(99,102,241,.15);
  --card-dark-bg-hover: rgba(99,102,241,.16);
  --html-bg: #0f0f1a;
  --bg-gradient: linear-gradient(165deg,#0f0f1a 0%,#1a1a2e 40%,#16213e 100%);
  --topbar-bg: rgba(15,15,26,.85);
  --topbar-border: rgba(99,102,241,.12);
  --input-bg: rgba(255,255,255,.04);
  --input-border: rgba(255,255,255,.08);
  --title-gradient: linear-gradient(135deg,#c7d2fe 0%,#818cf8 50%,#6366f1 100%);
}
[data-theme="light"] {
  color-scheme: light;
  --accent-primary: #4f46e5;
  --accent-secondary: #4f46e5;
  --accent-light: #4338ca;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a72;
  --text-muted: #8a8aa0;
  --card-bg: #fff;
  --card-shadow: 0 6px 22px rgba(31,35,80,.08);
  --card-dark-bg: rgba(99,102,241,.06);
  --card-dark-border: rgba(99,102,241,.22);
  --card-dark-bg-hover: rgba(99,102,241,.12);
  --html-bg: #f5f7fb;
  --bg-gradient: linear-gradient(165deg,#f5f7fb 0%,#eef0f8 40%,#e8edf6 100%);
  --topbar-bg: rgba(245,247,251,.85);
  --topbar-border: rgba(99,102,241,.22);
  --input-bg: rgba(31,35,80,.04);
  --input-border: rgba(99,102,241,.22);
  --title-gradient: linear-gradient(135deg,#4f46e5 0%,#4338ca 50%,#312e81 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--topbar-border);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text-primary); text-decoration: none; }
.theme-toggle {
  width: 36px; height: 36px;
  border: 1px solid var(--card-dark-border);
  background: var(--card-dark-bg);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-primary);
}
.theme-toggle svg { width: 16px; height: 16px; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.micro-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.2em; color: var(--accent-secondary);
  text-transform: uppercase; margin-bottom: 18px;
  display: block;
}
.gradient-title {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 800; line-height: 1.1;
  letter-spacing: -0.025em;
  background: var(--title-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 14px;
}
.lead {
  font-size: 15px; color: var(--text-secondary);
  line-height: 1.55; margin-bottom: 28px;
  max-width: 760px;
}

.editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 800px) {
  .editor { grid-template-columns: 1fr; }
}

.panel {
  background: var(--card-dark-bg);
  border: 1px solid var(--card-dark-border);
  border-radius: 14px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-dark-border);
  background: var(--card-dark-bg);
}
.panel-title {
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent-secondary);
}
.char-count {
  font-size: 11px; font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
}
.char-count.over { color: #ef4444; }

.ta {
  width: 100%; min-height: 280px;
  padding: 16px;
  background: var(--input-bg);
  border: none; outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px; line-height: 1.55;
  resize: vertical;
}
.ta-mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.ta::placeholder { color: var(--text-muted); }

.actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.btn-primary {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: #fff; font-weight: 600; font-size: 14px;
  padding: 12px 22px;
  border: none; border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 6px 24px rgba(99,102,241,.35);
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 28px rgba(99,102,241,.45); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px; padding: 12px 16px;
  border: 1px solid var(--card-dark-border);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}
.btn-ghost:hover { color: var(--accent-light); border-color: var(--accent-primary); }

.preview-panel { margin-bottom: 24px; }
.preview {
  padding: 18px 20px;
  background: var(--input-bg);
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 80px;
  color: var(--text-primary);
}
.preview b, .preview strong { font-weight: 700; }
.preview i, .preview em { font-style: italic; }
.preview u { text-decoration: underline; }
.preview s { text-decoration: line-through; opacity: 0.7; }
.preview code {
  background: var(--card-dark-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent-light);
}
.preview pre {
  background: var(--card-dark-bg);
  border: 1px solid var(--card-dark-border);
  padding: 12px 14px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  margin: 8px 0;
}
.preview pre code { background: transparent; padding: 0; color: var(--text-primary); }
.preview a { color: var(--accent-primary); text-decoration: underline; }
.preview blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 4px 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: normal;
}
.preview tg-spoiler {
  background: var(--text-muted);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 0 4px;
  cursor: pointer;
  transition: color 200ms ease;
}
.preview tg-spoiler:hover { color: var(--text-primary); }

.cheatsheet {
  background: var(--card-dark-bg);
  border: 1px solid var(--card-dark-border);
  border-radius: 14px;
  overflow: hidden;
}
.cheatsheet summary {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-light);
  cursor: pointer;
  list-style: none;
}
.cheatsheet summary::-webkit-details-marker { display: none; }
.cheatsheet summary::before { content: '+ '; color: var(--accent-primary); font-weight: 700; }
.cheatsheet[open] summary::before { content: '− '; }
.cheatsheet-body { padding: 0 18px 18px; font-size: 13.5px; color: var(--text-secondary); }
.cheatsheet table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.cheatsheet th, .cheatsheet td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--card-dark-border);
  vertical-align: top;
}
.cheatsheet th { color: var(--accent-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.cheatsheet code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--input-bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.cheatsheet-note { margin-top: 12px; color: var(--text-muted); font-size: 12px; }

.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: #22c55e;
  color: #fff;
  border-radius: 10px;
  font-weight: 600; font-size: 14px;
  z-index: 100;
  animation: slideUp 0.2s;
}
@keyframes slideUp {
  from { transform: translate(-50%, 16px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* PII mask specific */
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; min-height: 32px; }
.stat-pill { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; font-family: var(--font-mono); background: rgba(99, 102, 241, 0.12); color: var(--accent-primary); border: 1px solid rgba(99, 102, 241, 0.3); }
.stat-empty { color: var(--text-muted); font-size: 14px; }
.stat-КАРТА, .stat-ДАТА { background: rgba(245, 158, 11, 0.12); color: #f59e0b; border-color: rgba(245, 158, 11, 0.3); }
.stat-СНИЛС, .stat-ПАСПОРТ, .stat-ФИО { background: rgba(236, 72, 153, 0.12); color: #ec4899; border-color: rgba(236, 72, 153, 0.3); }
.stat-EMAIL { background: rgba(6, 182, 212, 0.12); color: #06b6d4; border-color: rgba(6, 182, 212, 0.3); }
.stat-ИНН, .stat-ИНН_ОРГ { background: rgba(16, 185, 129, 0.12); color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.safety-note { margin: 20px 0; padding: 14px 18px; background: rgba(245, 158, 11, 0.08); border-left: 3px solid #f59e0b; border-radius: 8px; color: var(--text-secondary); font-size: 14px; line-height: 1.6; }
.safety-note strong { color: var(--text-primary); }

/* Highlight panel */
.highlight-box { font-family: var(--font-mono); font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; padding: 16px; background: var(--card-bg); border-radius: 12px; max-height: 400px; overflow: auto; color: var(--text-primary); }
.highlight-box .hl { padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.hl-КАРТА, .hl-ДАТА { background: rgba(245, 158, 11, 0.25); color: #f59e0b; }
.hl-СНИЛС, .hl-ПАСПОРТ, .hl-ФИО { background: rgba(236, 72, 153, 0.25); color: #ec4899; }
.hl-EMAIL { background: rgba(6, 182, 212, 0.25); color: #06b6d4; }
.hl-ИНН, .hl-ИННОРГ, .hl-РС { background: rgba(16, 185, 129, 0.25); color: #10b981; }
.hl-ТЕЛ, .hl-IP { background: rgba(99, 102, 241, 0.25); color: var(--accent-primary); }
.hl-АДРЕС, .hl-ГОСНОМЕР { background: rgba(168, 85, 247, 0.25); color: #a855f7; }

.stat-РС, .stat-ИННОРГ { background: rgba(16, 185, 129, 0.12); color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.stat-ТЕЛ, .stat-IP { background: rgba(99, 102, 241, 0.12); color: var(--accent-primary); border-color: rgba(99, 102, 241, 0.3); }
.stat-АДРЕС, .stat-ГОСНОМЕР { background: rgba(168, 85, 247, 0.12); color: #a855f7; border-color: rgba(168, 85, 247, 0.3); }

/* Aggressive toggle */
.toggle { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px; background: var(--card-bg); border: 1px solid var(--panel-border); cursor: pointer; font-size: 13px; color: var(--text-secondary); user-select: none; }
.toggle input { cursor: pointer; }
.toggle:hover { color: var(--text-primary); border-color: var(--accent-primary); }

/* Restore section */
.section-divider { display: flex; align-items: center; margin: 40px 0 20px; gap: 16px; }
.section-divider::before, .section-divider::after { content: ""; flex: 1; height: 1px; background: var(--panel-border); }
.section-divider span { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.restore-lead { color: var(--text-secondary); margin: 0 0 16px; font-size: 14px; line-height: 1.6; }
.restore-info { margin: 12px 0 8px; padding: 10px 14px; background: rgba(99, 102, 241, 0.08); border-left: 3px solid var(--accent-primary); border-radius: 6px; font-size: 13px; color: var(--text-secondary); }
.restore-info.muted { background: var(--panel-bg); border-left-color: var(--panel-border); }

/* Dropzone overlay */
.dropzone { position: fixed; inset: 0; background: rgba(99, 102, 241, 0.85); display: none; align-items: center; justify-content: center; z-index: 1000; pointer-events: none; }
.dropzone.show { display: flex; }
.dropzone-inner { color: white; text-align: center; padding: 40px; border: 3px dashed white; border-radius: 24px; }
.dropzone-inner p { font-size: 24px; font-weight: 700; margin: 16px 0 0; }

/* New PII types pills */
.stat-ОГРН, .stat-ОГРНИП, .stat-БИК { background: rgba(16, 185, 129, 0.12); color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.hl-ОГРН, .hl-ОГРНИП, .hl-БИК { background: rgba(16, 185, 129, 0.25); color: #10b981; }
