:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --surface: #ffffff;
  --background: #f8fafc;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --warning-bg: #fef2f2;
  --warning-border: #fca5a5;
  --warning-text: #b91c1c;
  --success-bg: #f0fdf4;
  --success-text: #15803d;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--background);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 60px;
}

header {
  background: #0d2a4a;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  flex-wrap: wrap;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: #0284c7;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: white;
  font-size: 1.1rem;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: #93c5fd;
}

.header-badge {
  background: rgba(255, 255, 255, 0.12);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.container {
  max-width: 1440px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Control Panel */
.controls-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.controls-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-item label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

select, input[type="text"] {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  background-color: white;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

select:focus, input[type="text"]:focus {
  border-color: var(--primary);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.checkbox-item input {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

.actions-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(2, 132, 199, 0.4);
}

.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

/* Comparison Viewports */
.view-switchers {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.segmented-control {
  display: inline-flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
}

.segmented-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.segmented-btn.active {
  background: white;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: stretch;
}

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

.preview-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 480px;
}

.card-header {
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.badge-orig {
  background: #e0e7ff;
  color: #3730a3;
}

.badge-mat {
  background: #dcfce7;
  color: #166534;
}

.viewport-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #ffffff 0% 50%) 50% / 20px 20px;
  position: relative;
  overflow: auto;
}

.canvas-container {
  max-width: 100%;
  max-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  max-width: 100%;
  max-height: 500px;
  height: auto;
  width: auto;
  object-fit: contain;
  box-shadow: var(--shadow-md);
  background: transparent;
  border-radius: 4px;
}

/* Dropzone */
.dropzone {
  width: 100%;
  height: 100%;
  min-height: 380px;
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 2rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 1.75rem;
}

.dropzone-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.dropzone-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Split Slider View */
.split-view-container {
  display: none;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  position: relative;
  min-height: 500px;
  user-select: none;
}

.split-view-container.active {
  display: flex;
  flex-direction: column;
}

.split-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #ffffff 0% 50%) 50% / 20px 20px;
  overflow: hidden;
  min-height: 480px;
}

.split-img-box {
  position: relative;
  max-width: 100%;
  max-height: 500px;
}

.split-canvas-orig {
  display: block;
  max-width: 100%;
  max-height: 500px;
}

.split-canvas-converted-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 50%;
  overflow: hidden;
  border-right: 3px solid #ffffff;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

.split-canvas-converted {
  display: block;
  max-width: none;
  height: 100%;
}

.split-slider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  background: white;
  border: 3px solid var(--primary);
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: ew-resize;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--primary);
  z-index: 10;
}

/* Progress indicator */
.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 20;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Color Usage Section */
.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Warnings */
.alert-box {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  padding: 12px 16px;
  border-radius: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9rem;
}

.alert-icon {
  font-size: 1.2rem;
}

/* Color Table / Grid */
.color-chips-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.color-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: transform 0.15s, border-color 0.15s;
}

.color-card:hover {
  transform: translateY(-2px);
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.color-card.warning-card {
  border-color: var(--warning-border);
  background: #fff5f5;
}

.swatch-box {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.color-info {
  flex: 1;
  min-width: 0;
}

.color-code-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.color-code {
  font-weight: 700;
  font-size: 0.95rem;
}

.tag-basic {
  font-size: 0.65rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
  padding: 1px 5px;
  border-radius: 4px;
}

.tag-supp {
  font-size: 0.65rem;
  font-weight: 700;
  background: #fed7aa;
  color: #9a3412;
  padding: 1px 5px;
  border-radius: 4px;
}

.color-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.color-share {
  text-align: right;
}

.share-percent {
  font-size: 1.1rem;
  font-weight: 800;
}

.share-percent.danger {
  color: var(--warning-text);
}

/* Palette catalog drawer */
.catalog-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.catalog-header {
  padding: 1rem 1.5rem;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.catalog-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.catalog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

.catalog-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.catalog-item-chip {
  height: 50px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.catalog-item-meta {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.catalog-item-code {
  font-weight: 700;
  color: var(--text-main);
}

.catalog-item-sub {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* Footer */
footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}
