:root {
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.08);
  --line-strong: rgba(15, 23, 42, 0.12);
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
  --shadow-strong: 0 30px 80px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(99, 102, 241, 0.12), transparent 34%),
    radial-gradient(circle at bottom right, rgba(56, 189, 248, 0.10), transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 55%, #eef2ff 100%);
}

button, input, select { font: inherit; }

.app-shell { position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; }
.canvas-host { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.canvas-host canvas { display: block; width: 100% !important; height: 100% !important; }

.top-ui {
  display: block;
  position: absolute;
  top: 24px;
  left: 24px;
  right: auto;
  width: min(360px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px);
  z-index: 10;
  pointer-events: none;
}

.panel {
  display: block;
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.filters-panel {
  width: 100%;
  max-height: inherit;
  padding: 14px;
  overflow: auto;
}

.filter-toggle-button {
  display: flex;
  width: 100%;
  height: 44px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.filter-toggle-icon {
  transition: transform 180ms ease;
}

.filters-body { margin-top: 12px; }
.filters-panel.is-collapsed .filters-body { display: none; }
.filters-panel:not(.is-collapsed) .filter-toggle-icon { transform: rotate(180deg); }

.filters-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch;
}

.filter-label { display: flex; flex-direction: column; gap: 6px; }
.filter-label span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }

.shape-filter,
.dimension-filter,
.tags-filter { grid-column: auto; }
.color-filter { min-width: 0; }

.hue-range {
  position: relative;
  height: 44px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
  overflow: hidden;
}

.hue-track,
.hue-selection {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 16px;
  transform: translateY(-50%);
  pointer-events: none;
}

.hue-track {
  background: linear-gradient(90deg, #ef4444 0%, #f97316 8%, #facc15 17%, #84cc16 26%, #22c55e 35%, #14b8a6 44%, #06b6d4 53%, #3b82f6 62%, #6366f1 71%, #a855f7 80%, #ec4899 89%, #ef4444 100%);
  opacity: 1;
}

.hue-selection {
  right: auto;
  background: transparent;
  box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.18), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.hue-thumb {
  position: absolute;
  inset: 0 8px;
  width: calc(100% - 16px);
  height: 44px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
}

.hue-thumb::-webkit-slider-thumb {
  width: 14px;
  height: 30px;
  border: 2px solid white;
  background: #0f172a;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.32);
  cursor: ew-resize;
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
}

.hue-thumb::-moz-range-thumb {
  width: 14px;
  height: 30px;
  border: 2px solid white;
  border-radius: 0;
  background: #0f172a;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.32);
  cursor: ew-resize;
  pointer-events: auto;
}

.hue-thumb::-moz-range-track { background: transparent; border: 0; }

.hue-readout {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.hue-readout span { letter-spacing: 0; text-transform: none; }

.chip-filter-list,
.dimension-toggle {
  min-height: 44px;
  max-height: 116px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  overflow: auto;
  padding: 7px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
}

.dimension-toggle { flex-wrap: nowrap; }

.filter-chip,
.dimension-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(248, 250, 252, 0.95);
  color: #334155;
  cursor: pointer;
  font-size: 13px;
}

.filter-chip:has(input:checked),
.dimension-toggle label:has(input:checked) {
  border-color: #0f172a;
  background: #0f172a;
  color: white;
}

.filter-chip input,
.dimension-toggle input { margin: 0; accent-color: #0f172a; }
.filter-chip span,
.dimension-toggle span { color: inherit; font-size: inherit; letter-spacing: 0; text-transform: none; }
.muted-chip { opacity: 0.55; }
.tag-filter-empty { padding: 0 6px; color: var(--muted); font-size: 13px; }

.input, .select, .reset-button {
  height: 44px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
  padding: 0 12px;
  outline: none;
  color: var(--text);
}

.input:focus, .select:focus { border-color: rgba(71, 85, 105, 0.45); }

.reset-button {
  background: #0f172a;
  color: white;
  padding: 0 16px;
  cursor: pointer;
}

.reset-button:hover { background: #1e293b; }

.filters-meta {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted);
}

.filters-meta a {
  color: #334155;
  font-weight: 700;
  text-decoration: none;
}

.filters-meta a:hover { color: #2563eb; }

.bottom-status {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 10;
  padding: 11px 16px;
  font-size: 14px;
  color: #475569;
  white-space: nowrap;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  padding: 18px 22px;
}

.empty-state-title { font-size: 16px; font-weight: 600; }
.empty-state-text { margin-top: 4px; font-size: 14px; color: var(--muted); }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(12px);
}

.modal {
  width: min(1180px, 100%);
  height: min(88vh, 780px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-strong);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.modal-title {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 650;
}

.modal-subtitle {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.close-button,
.primary-action,
.secondary-action {
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: white;
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
}

.close-button:hover,
.secondary-action:hover { background: #f8fafc; }

.primary-action {
  border-color: #0f172a;
  background: #0f172a;
  color: white;
  font-weight: 700;
}

.primary-action:hover { background: #1e293b; }
.primary-action:disabled { opacity: 0.55; cursor: wait; }
.full-width-action { width: 100%; }

.modal-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.meta-column {
  overflow: auto;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.meta-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.meta-list { display: grid; gap: 12px; margin-top: 16px; }

.meta-edit-form { display: grid; gap: 12px; }

.meta-edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.edit-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.edit-field-wide { grid-column: 1 / -1; }

.edit-field span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #94a3b8;
}

.edit-field input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line-strong);
  background: white;
  padding: 0 10px;
  color: var(--text);
  outline: none;
}

.edit-field input:focus { border-color: rgba(37, 99, 235, 0.65); }
.edit-field input[type="color"] { padding: 4px; }

.meta-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.edit-status {
  border: 1px solid var(--line-strong);
  background: rgba(15, 23, 42, 0.04);
  padding: 10px 12px;
  color: #334155;
  font-size: 14px;
}

.edit-status.success {
  border-color: rgba(21, 128, 61, 0.35);
  color: #15803d;
  background: rgba(21, 128, 61, 0.06);
}

.edit-status.error {
  border-color: rgba(185, 28, 28, 0.35);
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.06);
}

.meta-card {
  border: 1px solid var(--line);
  background: white;
  padding: 14px;
}

.meta-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #94a3b8;
  margin-bottom: 8px;
}

.meta-value {
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
}

.meta-swatch-row { display: flex; align-items: center; gap: 10px; }
.meta-swatch { width: 18px; height: 18px; border: 1px solid var(--line-strong); flex: 0 0 auto; }

.sketch-frame { width: 100%; height: 100%; border: 0; background: white; }

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .filters-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .modal-body { grid-template-columns: 1fr; }
  .meta-column { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .top-ui {
    top: 16px;
    left: 16px;
    right: auto;
    width: min(340px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
  }
  .filters-panel { padding: 10px; }
  .filters-grid { grid-template-columns: 1fr; }
  .shape-filter, .dimension-filter, .tags-filter { grid-column: auto; }
  .dimension-toggle { flex-wrap: wrap; }
  .color-filter { min-width: 0; }
  .filters-meta { font-size: 13px; }
  .modal-title { font-size: 22px; }
  .overlay { padding: 16px; }
  .meta-edit-grid { grid-template-columns: 1fr; }
  .meta-actions { flex-direction: column; }
  .bottom-status {
    font-size: 13px;
    max-width: calc(100% - 32px);
    text-align: center;
    white-space: normal;
  }
}
