/* ---------- Design tokens ---------- */
:root {
  --bg: #f7f7f9;
  --bg-elevated: #ffffff;
  --bg-inset: #f1f1f5;
  --text: #16181d;
  --text-muted: #6b7280;
  --border: #e6e6ec;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 18, 30, 0.04);
  --shadow: 0 4px 16px rgba(16, 18, 30, 0.06);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Sidebar keeps a fixed dark tone regardless of light/dark theme. */
  --sidebar-bg: #232a41;
  --sidebar-border: #2f3752;
  --sidebar-text: #cbd2e6;
  --sidebar-text-muted: #7b849f;
  --sidebar-hover-bg: #2b3350;
  --sidebar-active-bg: rgba(124, 120, 240, 0.22);
  --sidebar-active-text: #ffffff;
  --sidebar-active-icon: #a5b0ff;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-inset: #1e2129;
  --text: #e8e9ed;
  --text-muted: #9497a3;
  --border: #2a2d37;
  --accent: #7c78f0;
  --accent-hover: #948ff5;
  --accent-soft: #22214a;
  --accent-contrast: #0f1115;
  --danger: #f87171;
  --danger-soft: #2a1616;
  --success: #4ade80;
  --success-soft: #12241a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.15s ease, color 0.15s ease;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.mono { font-family: var(--font-mono); font-size: 0.88rem; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
}

.brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-tag {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.privacy-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  display: none;
}

@media (min-width: 760px) {
  .privacy-note { display: inline; }
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted);
}

.switch-icon { width: 15px; height: 15px; flex-shrink: 0; }

.switch-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.18s ease;
}

[data-theme="dark"] .switch-knob { transform: translateX(18px); }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 57px;
  align-self: start;
  height: calc(100vh - 57px);
  overflow-y: auto;
}

.nav-heading {
  margin: 0 0 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-text-muted);
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }

@media (max-width: 860px) {
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
    padding: 12px;
    gap: 20px;
  }
  .nav-group { display: flex; flex-direction: row; align-items: center; gap: 6px; flex-shrink: 0; }
  .nav-heading { display: none; }
}

.tool-link {
  text-align: left;
  border: none;
  background: none;
  color: var(--sidebar-text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--sidebar-text-muted);
}

.tool-link:hover { background: var(--sidebar-hover-bg); }

.tool-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.tool-link.active .nav-icon { color: var(--sidebar-active-icon); }

/* ---------- Content ---------- */
.content {
  padding: 28px 24px 60px;
  min-width: 0;
}

.tool-panel { display: none; max-width: 780px; }
.tool-panel.active { display: block; animation: fade-in 0.15s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-desc {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 0.92rem;
}

.field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.field label, .inline-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

textarea, input[type="text"], input[type="number"], input[type="datetime-local"], .select {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: var(--font-sans);
  resize: vertical;
}

textarea:focus, input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea[readonly] { background: var(--bg-inset); }

.num-input { width: 80px; }

/* ---------- Toolbar / buttons ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.case-toolbar { margin-bottom: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg-inset); }

.btn-icon { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

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

.btn-copy {
  align-self: flex-end;
  margin-top: -4px;
}

.select {
  width: auto;
  cursor: pointer;
}

/* ---------- Output blocks ---------- */
.output-block {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 0;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.85rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
}
.chip b { color: var(--accent); font-family: var(--font-mono); }

.result-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-row span { color: var(--text-muted); flex-shrink: 0; }
.result-row code { font-family: var(--font-mono); word-break: break-all; text-align: right; }

.color-input-row { display: flex; gap: 8px; align-items: center; }
.color-input-row input[type="text"] { flex: 1; }
.color-input-row input[type="color"] {
  width: 42px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-elevated);
}

.swatch {
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--accent);
}

.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 4px 0 0;
}

.success {
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 4px 0 0;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}
