/* ===== DESIGN TOKENS ===== */
:root {
  /* Primary */
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a5f;

  /* Neutrals */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Accents */
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --red-50: #fef2f2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --amber-50: #fffbeb;
  --amber-500: #f59e0b;
  --purple-50: #faf5ff;
  --purple-500: #a855f7;
  --purple-600: #9333ea;

  /* Surfaces */
  --surface-bg: #ffffff;
  --surface-section: var(--gray-50);
  --surface-card: #ffffff;
  --surface-elevated: #ffffff;

  /* Borders */
  --border-light: var(--gray-200);
  --border-default: var(--gray-300);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-normal: 250ms var(--ease-out);
  --transition-slow: 350ms var(--ease-out);
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--gray-800);
  background: var(--surface-bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4 {
  color: var(--gray-900);
  line-height: 1.25;
  font-weight: 700;
}

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

@media (min-width: 768px) {
  h1 { font-size: 2.5rem; }
  h2 { font-size: 1.75rem; }
}

/* ===== LAYOUT ===== */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

@media (min-width: 768px) {
  .container { padding: 0 32px; }
}

/* ===== HEADER / NAVBAR ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  height: 64px;
  display: flex;
  align-items: center;
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--gray-900);
  font-weight: 700;
  font-size: 1.25rem;
}

.navbar-brand svg {
  width: 32px;
  height: 32px;
  color: var(--blue-600);
}

.navbar-brand span {
  color: var(--blue-600);
}

.navbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--gray-500);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-500);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== HERO SECTION ===== */
.hero {
  background: linear-gradient(135deg, var(--blue-50) 0%, #f0f0ff 50%, var(--gray-50) 100%);
  padding: 48px 0 56px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.06) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.hero h1 {
  margin-bottom: 12px;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--gray-600);
  max-width: 560px;
  margin: 0 auto 24px;
}

.hero-badges {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-600);
  box-shadow: var(--shadow-sm);
}

.badge svg {
  width: 14px;
  height: 14px;
}

.badge--blue { color: var(--blue-700); background: var(--blue-50); border-color: var(--blue-200); }
.badge--green { color: var(--green-700); background: var(--green-50); border-color: var(--green-100); }

/* ===== MAIN CONTENT ===== */
.main-content {
  padding: 40px 0 80px;
  background: var(--surface-section);
  min-height: 60vh;
}

.app-grid {
  display: grid;
  gap: 28px;
  grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
  .app-grid {
    grid-template-columns: 400px 1fr;
  }
}

/* ===== CARDS ===== */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-100);
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h2 svg {
  width: 20px;
  height: 20px;
  color: var(--blue-600);
}

.card-body {
  padding: 24px;
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  background: var(--gray-50);
  position: relative;
}

.upload-zone:hover {
  border-color: var(--blue-400);
  background: var(--blue-50);
}

.upload-zone.drag-over {
  border-color: var(--blue-500);
  background: var(--blue-50);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.upload-zone.has-file {
  border-style: solid;
  border-color: var(--green-500);
  background: var(--green-50);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: var(--gray-400);
  transition: color var(--transition-normal);
}

.upload-zone:hover .upload-icon {
  color: var(--blue-500);
}

.upload-zone.has-file .upload-icon {
  color: var(--green-600);
}

.upload-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.upload-subtitle {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 16px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--blue-600);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.upload-btn:hover {
  background: var(--blue-700);
}

.upload-file-input {
  display: none;
}

.file-info-bar {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--surface-card);
  border: 1px solid var(--green-100);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.file-info-bar.visible {
  display: flex;
}

.file-info-bar svg {
  width: 18px;
  height: 18px;
  color: var(--green-600);
  flex-shrink: 0;
}

.file-info-name {
  font-weight: 600;
  color: var(--gray-800);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info-size {
  color: var(--gray-500);
  font-size: 0.8rem;
  white-space: nowrap;
}

.file-remove-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: color var(--transition-fast);
  display: flex;
}

.file-remove-btn:hover {
  color: var(--red-500);
}

.file-remove-btn svg {
  width: 16px;
  height: 16px;
  color: inherit;
}

/* ===== FORM CONTROLS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-select,
.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--surface-card);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-select:focus,
.form-input:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== ANALYZE BUTTON ===== */
.btn-analyze {
  width: 100%;
  padding: 14px;
  background: var(--blue-600);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  position: relative;
  overflow: hidden;
}

.btn-analyze:hover:not(:disabled) {
  background: var(--blue-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-analyze:active:not(:disabled) {
  transform: translateY(0);
}

.btn-analyze:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

.btn-analyze svg {
  width: 20px;
  height: 20px;
}

.btn-analyze .spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== SLICER TOGGLE ===== */
.slicer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--blue-50);
  border: 1px solid var(--blue-200);
  border-radius: var(--radius-md);
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--blue-800);
}

.slicer-toggle label {
  cursor: pointer;
  font-weight: 500;
  flex: 1;
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--gray-300);
  border-radius: 11px;
  transition: background var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--blue-600);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ===== 3D PREVIEW ===== */
.preview-container {
  width: 100%;
  height: 300px;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.preview-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  border-radius: var(--radius-lg);
}

.preview-controls {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  color: var(--gray-500);
  pointer-events: none;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--gray-400);
  gap: 8px;
}

.preview-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.preview-placeholder span {
  font-size: 0.85rem;
}

/* ===== RESULTS ===== */
.results-section {
  display: none;
}

.results-section.visible {
  display: block;
  animation: fadeInUp 0.4s var(--ease-out);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  padding: 16px;
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  text-align: center;
  transition: box-shadow var(--transition-normal);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg {
  width: 18px;
  height: 18px;
}

.stat-icon--blue { background: var(--blue-50); color: var(--blue-600); }
.stat-icon--green { background: var(--green-50); color: var(--green-600); }
.stat-icon--purple { background: var(--purple-50); color: var(--purple-600); }
.stat-icon--amber { background: var(--amber-50); color: var(--amber-500); }

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Dimensions Table */
.dimensions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.dimensions-table th {
  text-align: left;
  padding: 8px 12px;
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-600);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-light);
}

.dimensions-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.dimensions-table tr:last-child td {
  border-bottom: none;
}

.dimensions-table .value {
  font-weight: 600;
  color: var(--gray-900);
  font-variant-numeric: tabular-nums;
}

/* CloudSlicer Results */
.cloudslicer-results {
  display: none;
}

.cloudslicer-results.visible {
  display: block;
  animation: fadeInUp 0.4s var(--ease-out);
}

.cs-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}

.cs-result-row:last-child {
  border-bottom: none;
}

.cs-result-label {
  color: var(--gray-600);
  font-weight: 500;
}

.cs-result-value {
  color: var(--gray-900);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Progress Bar for CloudSlicer */
.cs-progress {
  display: none;
  padding: 20px;
  text-align: center;
}

.cs-progress.visible {
  display: block;
}

.cs-progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  margin: 12px 0;
}

.cs-progress-bar-fill {
  height: 100%;
  background: var(--blue-600);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); width: 40%; }
  50% { transform: translateX(50%); width: 40%; }
  100% { transform: translateX(200%); width: 40%; }
}

.cs-progress-bar-fill.determinate {
  animation: none;
}

.cs-progress-text {
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 500;
}

.cs-progress-step {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 6px;
}

/* Error State */
.error-message {
  display: none;
  padding: 14px;
  background: var(--red-50);
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: var(--red-600);
  font-size: 0.875rem;
  margin-top: 12px;
}

.error-message.visible {
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeInUp 0.3s var(--ease-out);
}

.error-message svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ===== FOOTER ===== */
.footer {
  padding: 24px 0;
  border-top: 1px solid var(--border-light);
  background: var(--surface-bg);
  text-align: center;
  color: var(--gray-500);
  font-size: 0.8rem;
}

.footer a {
  color: var(--blue-600);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ===== UTILITY ===== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 767px) {
  .hero { padding: 32px 0 40px; }
  .main-content { padding: 24px 0 60px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.2rem; }
}
