:root {
  --bg: #f0f2f7;
  --sidebar-bg: #1a1d27;
  --sidebar-border: rgba(255,255,255,0.06);
  --sidebar-text: #9ba3b5;
  --sidebar-text-active: #ffffff;
  --sidebar-item-active-bg: rgba(255,255,255,0.10);
  --sidebar-item-hover-bg: rgba(255,255,255,0.06);
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e9f0;
  --line-2: #d1d8e4;
  --accent: #6366f1;
  --accent-hover: #4f52d8;
  --accent-subtle: rgba(99,102,241,0.10);
  --success: #059669;
  --success-subtle: rgba(5,150,105,0.10);
  --danger: #dc2626;
  --danger-subtle: rgba(220,38,38,0.10);
  --download-bg: #1e293b;
  --download-hover: #0f172a;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 16px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--sidebar-text-active);
  letter-spacing: -0.2px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: 7px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--sidebar-item-hover-bg);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-item-active-bg);
  color: var(--sidebar-text-active);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  opacity: 1;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--sidebar-border);
}

.health-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 7px;
  background: rgba(255,255,255,0.04);
}

.health-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
  transition: background 0.3s;
}

.health-badge.ok .health-dot { background: #34d399; }
.health-badge.warn .health-dot { background: #f87171; }

.health-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-text);
  letter-spacing: 0.3px;
}

/* ── Content Area ───────────────────────────────────── */
.content-area {
  flex: 1;
  margin-left: 220px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Tab Panels ─────────────────────────────────────── */
.tab-panel {
  display: none;
  flex: 1;
  padding: 36px 40px 48px;
  flex-direction: column;
}

.tab-panel.active {
  display: flex;
}

/* ── Content Header ─────────────────────────────────── */
.content-header {
  margin-bottom: 28px;
}

.content-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.3px;
  margin-bottom: 5px;
}

.content-header p {
  color: var(--muted);
  font-size: 14px;
}

/* ── Tool Layout ────────────────────────────────────── */
.tool-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  flex: 1;
}

/* ── Card ───────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.controls-card {
  padding: 0;
}

.card-section {
  padding: 18px 20px;
  border-top: 1px solid var(--line);
}

.card-section:first-child {
  border-top: none;
}

/* ── Field Label ────────────────────────────────────── */
.field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Drop Zone ──────────────────────────────────────── */
.drop-zone {
  position: relative;
  min-height: 140px;
  border: 1.5px dashed var(--line-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #fafbfd;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.drop-zone.has-file {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  text-align: center;
  padding: 16px;
}

.drop-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin-bottom: 4px;
  transition: background 0.2s, color 0.2s;
}

.drop-zone:hover .drop-icon,
.drop-zone.dragging .drop-icon,
.drop-zone.has-file .drop-icon {
  background: var(--accent-subtle);
  color: var(--accent);
}

.drop-primary {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.drop-hint {
  font-size: 12px;
  color: var(--muted);
}

/* ── Text Input / Select ────────────────────────────── */
.text-input,
select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.text-input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ── Advanced Block ─────────────────────────────────── */
.advanced-block {
  border-top: 1px solid var(--line);
}

.advanced-block summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.advanced-block summary::-webkit-details-marker { display: none; }

.advanced-block summary:hover { color: var(--ink); }

.chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.advanced-block[open] summary { color: var(--ink); }
.advanced-block[open] .chevron { transform: rotate(180deg); }

.advanced-body {
  padding: 0 20px 18px;
}

/* ── Status Bar ─────────────────────────────────────── */
.status-bar {
  min-height: 18px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.status-bar:empty { margin-bottom: 0; min-height: 0; }
.status-bar.error { color: var(--danger); }
.status-bar.success { color: var(--success); }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  border-radius: 8px;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(99,102,241,0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 3px 10px rgba(99,102,241,0.35);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-download {
  background: var(--download-bg);
  color: #fff;
  margin-top: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.btn-download:hover {
  background: var(--download-hover);
}

.btn-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.hidden { display: none !important; }

/* ── Preview Pair ───────────────────────────────────── */
.preview-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.preview-card {
  padding: 16px;
}

.preview-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.preview-frame {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.preview-frame img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.preview-frame img.visible { display: block; }

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  opacity: 0.5;
  pointer-events: none;
}

.preview-frame img.visible ~ .preview-placeholder { display: none; }

/* ── SVG Result ─────────────────────────────────────── */
.svg-result-card {
  padding: 16px;
}

.svg-frame {
  width: 100%;
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-frame object {
  width: 100%;
  height: 480px;
  display: block;
  background: transparent;
}

#svgEmpty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  opacity: 0.45;
  pointer-events: none;
}

#svgEmpty.hidden { display: none !important; }

/* ── Checkerboard ───────────────────────────────────── */
.checkerboard {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, rgba(0,0,0,0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.05) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

/* ── Spinner animation ──────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinning {
  animation: spin 0.8s linear infinite;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 1024px) {
  .tool-layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

@media (max-width: 800px) {
  .sidebar {
    width: 64px;
    padding: 16px 8px;
  }

  .brand-name,
  .nav-item span:last-child,
  .health-label { display: none; }

  .brand { padding-bottom: 16px; justify-content: center; }
  .brand-icon { margin: 0; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-icon { opacity: 1; }

  .content-area { margin-left: 64px; }

  .tab-panel { padding: 24px 20px 40px; }

  .tool-layout {
    grid-template-columns: 1fr;
  }

  .preview-pair {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .tab-panel { padding: 20px 14px 32px; }
}
