*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-bg: #eff6ff;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #111827;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --cat-label: #9ca3af;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #dc2626;
  --output-bg: #f9fafb;
  --transition: 0.14s ease;
  --header-h: 58px;
}

.dark {
  --accent: #60a5fa;
  --accent-dark: #93c5fd;
  --accent-bg: #1e3a5f;
  --bg: #111827;
  --surface: #1f2937;
  --border: #374151;
  --border-light: #2d3748;
  --text: #f9fafb;
  --text-secondary: #e5e7eb;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --cat-label: #6b7280;
  --error-bg: #3b1212;
  --error-border: #7f1d1d;
  --error-text: #f87171;
  --output-bg: #1a2332;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ─── HEADER ─── */
.header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 11px; }

.app-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.app-title-group { display: flex; flex-direction: column; gap: 1px; }
.app-title { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; line-height: 1.2; }
.app-subtitle { font-size: 11.5px; color: var(--text-muted); font-weight: 400; line-height: 1.2; }

.header-right { display: flex; align-items: center; gap: 12px; }
.format-count { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.dark-toggle {
  width: 32px; height: 32px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
}
.dark-toggle:hover { background: var(--bg); color: var(--text); }
.dark-toggle .icon-moon { display: none; }
.dark-toggle .icon-sun { display: block; }
.dark .dark-toggle .icon-moon { display: block; }
.dark .dark-toggle .icon-sun { display: none; }

/* ─── BODY ─── */
.body { display: flex; flex: 1; overflow: hidden; }

/* ─── SIDEBAR ─── */
.sidebar {
  width: 182px; min-width: 182px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}

.sidebar-inner {
  flex: 1; overflow-y: auto;
  padding: 12px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-inner::-webkit-scrollbar { width: 4px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.category-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--cat-label);
  padding: 14px 16px 4px;
}
.category-label:first-child { padding-top: 4px; }

.sidebar-item {
  display: flex; align-items: center; width: 100%;
  padding: 6px 16px 6px 14px;
  border: none; background: transparent;
  font-family: inherit; font-size: 13px; font-weight: 400;
  color: var(--text-secondary); cursor: pointer; text-align: left;
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  line-height: 1.4;
}
.sidebar-item:hover { background: var(--bg); color: var(--text); }
.sidebar-item.selected {
  border-left-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent-dark);
  font-weight: 600;
}

/* ─── MAIN ─── */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; padding: 14px 20px 0; min-width: 0;
}

/* ─── MODE BAR ─── */
.mode-bar { display: flex; align-items: center; margin-bottom: 12px; flex-shrink: 0; }

.mode-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 3px; gap: 2px;
}

.mode-btn {
  padding: 5px 18px; border: none; border-radius: 6px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; background: transparent; color: var(--text-muted);
  transition: all var(--transition); line-height: 1.4;
}
.mode-btn:hover:not(.active) { color: var(--text); background: rgba(128,128,128,0.1); }
.mode-btn.active {
  background: var(--surface); color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ─── IO ROW ─── */
.io-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 14px; flex: 1; overflow: hidden; min-height: 0;
}

.io-panel {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); overflow: hidden; min-height: 0;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-panel:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.output-panel { background: var(--output-bg); }

.io-top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--border-light); flex-shrink: 0;
}
.io-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em; color: var(--text-muted); }
.io-top-actions { display: flex; align-items: center; gap: 5px; }

.text-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); font-family: inherit; font-size: 12px;
  font-weight: 500; color: var(--text-secondary); cursor: pointer;
  transition: all var(--transition); white-space: nowrap;
}
.text-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.text-btn.copied { border-color: #16a34a; color: #16a34a; background: #f0fdf4; }
.dark .text-btn.copied { background: #052e16; }

.textarea-wrap { flex: 1; min-height: 0; overflow: hidden; }

textarea {
  width: 100%; height: 100%; padding: 12px 14px;
  border: none; outline: none;
  font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
  font-size: 12.5px; line-height: 1.75; color: var(--text);
  background: transparent; resize: none; display: block;
  overflow-y: auto;
}

textarea::placeholder { color: var(--text-faint); font-style: italic; font-family: 'Inter', sans-serif; }
#outputText { color: var(--text-secondary); }
#outputText::placeholder { color: var(--text-faint); font-style: italic; font-family: 'Inter', sans-serif; }

.io-bottom-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; border-top: 1px solid var(--border-light);
  flex-shrink: 0; min-height: 30px; gap: 8px;
}
.io-bottom-bar span { font-size: 11.5px; color: var(--text-faint); }
.output-bottom { justify-content: space-between; }

.error-inline { color: var(--error-text) !important; font-size: 11.5px; font-weight: 500; }
.error-state textarea { color: var(--error-text) !important; }

/* ─── INFO BAR ─── */
.info-bar {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 13px; margin-top: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 18px; flex-shrink: 0;
}
.info-icon { color: var(--accent); flex-shrink: 0; margin-top: 2px; }
.info-text { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.info-text strong { color: var(--text); font-weight: 600; }

/* ─── RESPONSIVE ─── */
@media (max-width: 700px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .body { flex-direction: column; }

  .sidebar {
    width: 100%; min-width: 0; border-right: none;
    border-bottom: 1px solid var(--border); height: auto;
  }
  .sidebar-inner {
    display: flex; flex-direction: row; flex-wrap: nowrap;
    overflow-x: auto; overflow-y: hidden;
    padding: 8px 10px; gap: 4px;
    scrollbar-width: none;
  }
  .sidebar-inner::-webkit-scrollbar { display: none; }
  .category-label { display: none; }
  .sidebar-item {
    border-left: none; border-radius: 20px; padding: 5px 13px;
    border: 1px solid var(--border); white-space: nowrap; flex-shrink: 0;
    font-size: 12.5px;
  }
  .sidebar-item.selected {
    background: var(--accent-bg); border-color: var(--accent);
    color: var(--accent-dark);
  }

  .main { padding: 12px 12px 0; overflow: visible; }
  .io-row { grid-template-columns: 1fr; }
  .io-panel { min-height: 200px; }
  .app-subtitle { display: none; }
  .format-count { display: none; }
}