/* ═══════════════════════════════════════════════════════════════
   Universal Text Decoder — Design System
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables / Theme ─────────────────────────────────── */
:root {
  /* Light theme (default) */
  --bg-primary: #f8f9fb;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f5f6f8;
  --bg-hover: #e8eaed;
  --bg-hero: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  --text-primary: #1a1d23;
  --text-secondary: #5f6368;
  --text-tertiary: #80868b;
  --text-inverse: #ffffff;

  --border-color: #e0e3e8;
  --border-light: #eef0f3;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-text: #4338ca;

  --success: #22c55e;
  --success-bg: #f0fdf4;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --warning: #f59e0b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  --sidebar-width: 280px;
  --nav-height: 60px;
  --transition: 0.2s ease;
}

/* Dark theme */
[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #22252f;
  --bg-sidebar: #151821;
  --bg-card: #1e2130;
  --bg-input: #252836;
  --bg-hover: #2a2d3a;
  --bg-hero: linear-gradient(135deg, #312e81 0%, #4c1d95 100%);

  --text-primary: #e8eaed;
  --text-secondary: #9ca3af;
  --text-tertiary: #6b7280;

  --border-color: #2d3040;
  --border-light: #252836;

  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: #1e1b4b;
  --accent-text: #a5b4fc;

  --success-bg: #052e16;
  --error-bg: #2d0f0f;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

p { color: var(--text-secondary); }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--accent-hover); }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

/* ── Layout Shell ──────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--nav-height);
}

/* ── Top Nav ───────────────────────────────────────────────── */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  cursor: pointer;
}

.nav-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 0.85rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}
.nav-link:hover, .nav-link.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.mobile-menu-btn {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  align-items: center;
  justify-content: center;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  height: calc(100vh - var(--nav-height));
  position: fixed;
  top: var(--nav-height);
  left: 0;
  overflow-y: auto;
  padding: 16px 0;
  z-index: 90;
  transition: transform var(--transition);
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.sidebar-category {
  margin-bottom: 4px;
}

.sidebar-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  cursor: pointer;
  user-select: none;
}
.sidebar-category-header:hover {
  color: var(--text-secondary);
}
.sidebar-category-header .chevron {
  font-size: 0.65rem;
  transition: transform var(--transition);
}
.sidebar-category.collapsed .chevron {
  transform: rotate(-90deg);
}
.sidebar-category.collapsed .sidebar-items {
  display: none;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px 7px 28px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.sidebar-item.active {
  background: var(--accent-light);
  color: var(--accent-text);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  max-width: 100%;
  min-height: calc(100vh - var(--nav-height));
}

/* ── Hero ───────────────────────────────────────────────────── */
.hero {
  background: var(--bg-hero);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  margin-bottom: 40px;
  color: white;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 500px;
  height: 500px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}
.hero h1 {
  color: white;
  font-size: 2.2rem;
  margin-bottom: 10px;
  position: relative;
}
.hero p {
  color: rgba(255,255,255,0.85);
  font-size: 1.05rem;
  max-width: 600px;
  margin-bottom: 28px;
  position: relative;
}

/* ── Auto-Detect Box ───────────────────────────────────────── */
.auto-detect-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-md);
  position: relative;
}

.auto-detect-box textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 14px;
  transition: border-color var(--transition);
}
.auto-detect-box textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.auto-detect-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-success {
  background: var(--success);
  color: white;
}

/* ── Category Grid ─────────────────────────────────────────── */
.categories-section {
  margin-bottom: 40px;
}

.section-title {
  font-size: 1.3rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.category-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.category-card .card-icon {
  width: 42px;
  height: 42px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 14px;
}
.category-card h3 {
  font-size: 1rem;
  margin-bottom: 6px;
}
.category-card p {
  font-size: 0.82rem;
  color: var(--text-tertiary);
}
.category-card .card-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 10px;
}

/* ── Tool Page ─────────────────────────────────────────────── */
.tool-page {
  max-width: 900px;
}

.tool-header {
  margin-bottom: 24px;
}
.tool-header .breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}
.tool-header .breadcrumb a {
  color: var(--text-tertiary);
}
.tool-header .breadcrumb a:hover {
  color: var(--accent);
}
.tool-header h1 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}
.tool-header p {
  font-size: 0.95rem;
}

.tool-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tool-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
}

.tool-section label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.tool-section textarea {
  width: 100%;
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  resize: vertical;
  transition: border-color var(--transition);
  line-height: 1.5;
}
.tool-section textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.tool-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.output-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.tool-section .status-msg {
  margin-top: 8px;
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.status-msg.success {
  background: var(--success-bg);
  color: var(--success);
}
.status-msg.error {
  background: var(--error-bg);
  color: var(--error);
}

/* ── Tools Grid (listing page) ─────────────────────────────── */
.tools-search {
  margin-bottom: 24px;
}

.tools-search input {
  width: 100%;
  max-width: 500px;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
}
.tools-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.tools-category-section {
  margin-bottom: 32px;
}
.tools-category-section h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.tool-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.tool-list-item:hover {
  background: var(--bg-hover);
}
.tool-list-item .tool-info h4 {
  font-size: 0.9rem;
  font-weight: 500;
}
.tool-list-item .tool-info p {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}
.tool-list-item .arrow {
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

/* ── Content Pages (API, Docs, About) ──────────────────────── */
.content-page {
  max-width: 800px;
}

.content-page h1 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}
.content-page > p {
  margin-bottom: 28px;
  font-size: 1rem;
}

.content-section {
  margin-bottom: 32px;
}
.content-section h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}
.content-section h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.code-block {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  overflow-x: auto;
  margin: 12px 0;
  line-height: 1.6;
  white-space: pre;
  color: var(--text-primary);
}

.endpoint-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 14px;
}
.endpoint-card .method {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-right: 8px;
}
.endpoint-card .method.post {
  background: #dbeafe;
  color: #1d4ed8;
}
[data-theme="dark"] .endpoint-card .method.post {
  background: #1e3a5f;
  color: #93c5fd;
}
.endpoint-card .method.get {
  background: #dcfce7;
  color: #16a34a;
}
[data-theme="dark"] .endpoint-card .method.get {
  background: #14532d;
  color: #86efac;
}
.endpoint-card .path {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
}
.endpoint-card p {
  margin-top: 6px;
  font-size: 0.85rem;
}

/* ── Feature List ──────────────────────────────────────────── */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.feature-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.feature-item .icon {
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Toast Notification ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .main-content {
    padding: 24px;
  }
}

@media (max-width: 768px) {
  .nav-links { display: none; }
  .mobile-menu-btn { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }

  .hero {
    padding: 32px 24px;
  }
  .hero h1 { font-size: 1.6rem; }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .auto-detect-actions {
    flex-direction: column;
  }
  .auto-detect-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .tool-actions {
    flex-direction: column;
  }
  .tool-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .hero { padding: 24px 16px; }
  .hero h1 { font-size: 1.4rem; }
  .tool-section { padding: 14px; }
}

/* ── Sidebar overlay for mobile ────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 85;
}
.sidebar-overlay.show {
  display: block;
}

/* ── Checkbox toggle (for real-time decode) ────────────────── */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.toggle-group input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ── Scrollbar (global) ────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}
