/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-surface2: #f1f3f5;
  --color-border: #dee2e6;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-primary: #0d6efd;
  --color-primary-hover: #0a58ca;
  --color-primary-text: #ffffff;
  --color-ghost-hover: #e9ecef;
  --color-green: #198754;
  --color-red: #dc3545;
  --color-drag: rgba(13, 110, 253, 0.08);
  --color-drag-border: #0d6efd;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,.12);
  --font-mono: 'Fira Code', 'Cascadia Code', 'Consolas', 'Monaco', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 0.15s ease;
}

[data-theme="dark"] {
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-surface2: #21262d;
  --color-border: #30363d;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-primary: #388bfd;
  --color-primary-hover: #58a6ff;
  --color-primary-text: #ffffff;
  --color-ghost-hover: #21262d;
  --color-green: #3fb950;
  --color-red: #f85149;
  --color-drag: rgba(56, 139, 253, 0.1);
  --color-drag-border: #388bfd;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 2px 8px rgba(0,0,0,.4);
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--color-primary); }
ul { list-style: none; }

/* ─── Header ────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.app-title { font-size: 1.2rem; font-weight: 700; }
.app-subtitle { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 1px; }
.header-right { display: flex; gap: 0.5rem; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--color-ghost-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--color-ghost-hover); }

.btn-sm { padding: 0.25rem 0.65rem; font-size: 0.8rem; }
.btn-lg { padding: 0.6rem 2rem; font-size: 1rem; font-weight: 600; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
  align-self: flex-start;
  position: sticky;
  top: 1rem;
}
.options-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}
.options-list { display: flex; flex-direction: column; gap: 0.45rem; }
.options-list li { display: flex; flex-direction: column; }
.options-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.2rem 0;
  border-radius: var(--radius);
}
.options-list label:hover { color: var(--color-primary); }
.options-list input[type="checkbox"] { accent-color: var(--color-primary); width: 14px; height: 14px; flex-shrink: 0; }
.indent-label {
  padding-left: 1.5rem !important;
  font-size: 0.78rem !important;
  color: var(--color-text-muted);
}
.indent-label input[type="number"] {
  width: 3.5rem;
  padding: 0.1rem 0.3rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface2);
  color: var(--color-text);
  font-size: 0.78rem;
}
.option-group { display: flex; flex-direction: column; gap: 0.2rem; }

/* ─── Editor area ────────────────────────────────────────────────────────── */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

/* ─── Drop zone ──────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}
.drop-zone.drag-over {
  border-color: var(--color-drag-border);
  background: var(--color-drag);
}
.drop-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  padding: 0.35rem;
  pointer-events: none;
}

/* ─── Panes ──────────────────────────────────────────────────────────────── */
.panes {
  display: flex;
  gap: 0;
  height: 340px;
}
.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pane-divider {
  width: 1px;
  background: var(--color-border);
  margin: 0.75rem 0;
}
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.pane-input .pane-header { border-radius: var(--radius-lg) 0 0 0; }
.pane-output .pane-header { border-radius: 0 var(--radius-lg) 0 0; }
.pane-actions { display: flex; gap: 0.35rem; }

.code-area {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 0.75rem;
  outline: none;
  overflow-y: auto;
}
.code-area[readonly] { background: var(--color-surface2); }

/* ─── Stats bar ──────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}
.stats-bar.hidden { display: none; }
.stat-item { display: flex; flex-direction: column; }
.stat-label { font-size: 0.7rem; color: var(--color-text-muted); }
.stat-value { font-weight: 600; }
.stat-arrow { color: var(--color-text-muted); font-size: 1rem; }
.stat-savings { font-weight: 700; font-size: 1rem; margin-left: auto; }

/* ─── Action bar ─────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  justify-content: center;
}

/* ─── Preview ────────────────────────────────────────────────────────────── */
.preview-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.preview-section h2 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}
.preview-panes {
  display: flex;
  gap: 1rem;
}
.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.preview-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
}
.preview-box {
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 0.75rem;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .app-main { flex-direction: column; padding: 0.75rem; }
  .sidebar { width: 100%; position: static; }
  .panes { flex-direction: column; height: auto; }
  .pane-divider { width: 100%; height: 1px; margin: 0; }
  .code-area { height: 200px; }
  .pane-input .pane-header { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .pane-output .pane-header { border-radius: 0 0 0 0; }
  .preview-panes { flex-direction: column; }
}
