/* ===== CSS Custom Properties (Themes) ===== */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #f0f2f5;
  --bg-editor: #1e1e2e;
  --bg-editor-light: #2d2d3f;
  --bg-toolbar: #ffffff;
  --bg-statusbar: #f0f2f5;
  --bg-input: #ffffff;
  --bg-output: #1e1e2e;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-editor: #cdd6f4;
  --text-editor-line: #585b70;
  --border-color: #e2e8f0;
  --border-editor: #313244;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.1);
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.1);
  --error: #ef4444;
  --error-light: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252540;
  --bg-toolbar: #1a1a2e;
  --bg-statusbar: #1a1a2e;
  --bg-input: #1e1e2e;
  --bg-output: #1e1e2e;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #2d2d44;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: rgba(129, 140, 248, 0.15);
  --success-light: rgba(16, 185, 129, 0.15);
  --error-light: rgba(239, 68, 68, 0.15);
  --warning-light: rgba(245, 158, 11, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-danger:hover {
  background: var(--error-light);
  color: var(--error);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  transition: background var(--transition), border-color var(--transition);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.select-input {
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--transition);
  outline: none;
}

.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ===== Editor Container ===== */
.editor-container {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--border-color);
  transition: background var(--transition);
}

.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

.input-panel {
  border-right: 1px solid var(--border-color);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  transition: background var(--transition), border-color var(--transition);
}

.panel-title {
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.panel-info {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.editor-wrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.line-numbers {
  width: 38px;
  min-width: 38px;
  padding: 8px 6px;
  background: var(--bg-editor-light);
  color: var(--text-editor-line);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  line-height: 1.45;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--border-editor);
  flex-shrink: 0;
}

.editor-textarea {
  flex: 1;
  width: 100%;
  padding: 8px 12px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
  tab-size: 2;
  background: transparent;
  color: var(--text-editor);
  white-space: pre;
  overflow: auto;
  caret-color: var(--accent);
}

.editor-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.editor-textarea::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.editor-textarea::-webkit-scrollbar-track {
  background: transparent;
}

.editor-textarea::-webkit-scrollbar-thumb {
  background: var(--border-editor);
  border-radius: 4px;
}

.editor-textarea::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1px 8px;
  background: var(--bg-statusbar);
  border-top: 1px solid var(--border-color);
  font-size: 0.55rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  transition: background var(--transition), border-color var(--transition);
  gap: 6px;
  min-height: 18px;
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-right {
  margin-left: auto;
}

#statusFormat {
  font-size: 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

#statusValidation {
  font-size: 0.55rem;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  color: #ffffff;
  background: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

.toast.warning {
  background: var(--warning);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header {
    padding: 10px 16px;
  }

  .header-subtitle {
    display: none;
  }

  .toolbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .toolbar-group {
    gap: 4px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .editor-container {
    flex-direction: column;
  }

  .input-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .line-numbers {
    width: 30px;
    min-width: 30px;
  }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.editor-panel {
  animation: fadeIn 0.3s ease;
}

/* ===== Validation States ===== */
.editor-textarea.validation-error {
  background: var(--error-light);
}

.editor-textarea.validation-success {
  background: var(--success-light);
}