/* 
  SEVIX - iOS-style Dual-Theme System
  Light Mode (Default Apple Clean Studio) & Dark Mode (Space Black / Titanium)
*/


:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* LIGHT THEME (Apple Clean Studio - Default) */
  --ios-bg-base: #F5F7FA;
  --ios-bg-surface: rgba(255, 255, 255, 0.82);
  --ios-bg-card: rgba(255, 255, 255, 0.78);
  --ios-bg-card-hover: rgba(255, 255, 255, 0.95);
  --ios-bg-secondary: rgba(0, 0, 0, 0.04);
  --ios-bg-tertiary: rgba(0, 0, 0, 0.07);
  
  --ios-text-primary: #1D1D1F;
  --ios-text-secondary: #6E6E73;
  --ios-text-tertiary: #86868B;
  --ios-text-subtle: #A1A1A6;

  --ios-border-subtle: rgba(0, 0, 0, 0.08);
  --ios-border-light: rgba(0, 0, 0, 0.12);
  --ios-border-highlight: rgba(0, 0, 0, 0.20);
  
  --ios-green: #34C759;
  --ios-green-glow: rgba(52, 199, 89, 0.25);
  --ios-blue: #0071E3;
  --ios-purple: #AF52DE;
  --ios-amber: #FF9500;
  --ios-red: #FF3B30;
  --ios-teal: #30B0C7;
  --ios-indigo: #5856D6;

  --brand: #2563EB;
  --brand-glow: rgba(37, 99, 235, 0.25);

  --ios-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --ios-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --ios-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
  --ios-shadow-card: 0 4px 20px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);

  --ios-glass-blur: blur(30px) saturate(180%);
  --viewport-bg-gradient: radial-gradient(circle at 50% 40%, #FFFFFF 0%, #EDF1F7 60%, #E2E8F0 100%);
  --plate-pei-color: 0x2A3240;
  --grid-main-color: 0x2563EB;
  --grid-sub-color: 0xCAD4E0;
}

/* DARK THEME (Titanium / Space Black) */
html.dark {
  --ios-bg-base: #07090E;
  --ios-bg-surface: rgba(18, 24, 38, 0.82);
  --ios-bg-card: rgba(26, 34, 50, 0.72);
  --ios-bg-card-hover: rgba(36, 46, 68, 0.85);
  --ios-bg-secondary: rgba(255, 255, 255, 0.06);
  --ios-bg-tertiary: rgba(255, 255, 255, 0.10);
  
  --ios-text-primary: #F5F5F7;
  --ios-text-secondary: #98989D;
  --ios-text-tertiary: #6E6E73;
  --ios-text-subtle: #48484A;

  --ios-border-subtle: rgba(255, 255, 255, 0.08);
  --ios-border-light: rgba(255, 255, 255, 0.15);
  --ios-border-highlight: rgba(255, 255, 255, 0.25);

  --ios-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --ios-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --ios-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --ios-shadow-card: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);

  --viewport-bg-gradient: radial-gradient(circle at 50% 40%, #161F33 0%, #0B0F19 65%, #06080D 100%);
  --plate-pei-color: 0x161C2A;
  --grid-main-color: 0x2563EB;
  --grid-sub-color: 0x2A374E;
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background-color: var(--ios-bg-base);
  color: var(--ios-text-primary);
  user-select: none;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Lock body scroll on desktop only */
@media (min-width: 769px) {
  body { overflow: hidden; }
}

/* Utility classes guaranteed even if Tailwind CDN is blocked */
.hidden {
  display: none !important;
}

.pointer-events-none {
  pointer-events: none !important;
}

.pointer-events-auto {
  pointer-events: auto !important;
}

/* Custom Smooth Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(120, 120, 128, 0.25);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 120, 128, 0.4);
}

/* Glassmorphism Classes */
.ios-glass-header {
  background: var(--ios-bg-base, #F5F7FA);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-bottom: 1px solid var(--ios-border-subtle);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.ios-glass-sidebar {
  background: var(--ios-bg-surface);
  backdrop-filter: var(--ios-glass-blur);
  -webkit-backdrop-filter: var(--ios-glass-blur);
  border-left: 1px solid var(--ios-border-subtle);
}

.ios-glass-panel {
  background: var(--ios-bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--ios-border-subtle);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--ios-shadow-card);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.ios-glass-panel:hover {
  border-color: var(--ios-border-light);
}

/* Dynamic Island (Crystal Clear Sharpness on iOS Retina) */
.ios-dynamic-island {
  background: var(--ios-bg-card);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border: 1px solid var(--ios-border-light);
  border-radius: 28px;
  box-shadow: var(--ios-shadow-md);
  color: var(--ios-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ios-dynamic-island:hover {
  box-shadow: var(--ios-shadow-lg);
}

/* Segmented Control (iOS Pure) */
.ios-segmented-control {
  background: var(--ios-bg-secondary);
  border: 1px solid var(--ios-border-subtle);
  border-radius: 12px;
  padding: 3px;
  display: flex;
  position: relative;
  gap: 2px;
  width: 100%;
  overflow: hidden;
}

.ios-segment-btn {
  flex: 1 1 0%;
  min-width: 0;
  text-align: center;
  padding: 7px 4px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 9px;
  color: var(--ios-text-secondary);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  border: none;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.ios-segment-btn:hover {
  color: var(--ios-text-primary);
}

.ios-segment-btn.active {
  background: #FFFFFF;
  color: #1D1D1F;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

html.dark .ios-segment-btn.active {
  background: rgba(255, 255, 255, 0.16);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* iOS Toggle Switch */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

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

.ios-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(120, 120, 128, 0.2);
  border: 1px solid var(--ios-border-subtle);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 9999px;
}

.ios-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

input:checked + .ios-slider {
  background-color: var(--ios-green);
  border-color: var(--ios-green);
  box-shadow: 0 0 10px var(--ios-green-glow);
}

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

/* iOS Stepper Button */
.ios-stepper {
  display: inline-flex;
  align-items: center;
  background: var(--ios-bg-secondary);
  border: 1px solid var(--ios-border-subtle);
  border-radius: 10px;
  padding: 2px;
}

.ios-stepper-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--ios-text-secondary);
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ios-stepper-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ios-text-primary);
}

html.dark .ios-stepper-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ios-stepper-btn:active {
  transform: scale(0.92);
}

/* iOS Range Slider */
input[type=range].ios-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--ios-bg-secondary);
  border-radius: 9999px;
  outline: none;
  border: 1px solid var(--ios-border-subtle);
}

input[type=range].ios-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s ease;
}

input[type=range].ios-range::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25), 0 0 0 3px rgba(37, 99, 235, 0.3);
}

input[type=range].ios-range::-webkit-slider-thumb:active {
  transform: scale(1.05);
}

/* Material Chips Grid */
.material-card {
  background: var(--ios-bg-card);
  border: 1px solid var(--ios-border-subtle);
  border-radius: 12px;
  padding: 7px 10px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.material-card:hover {
  background: var(--ios-bg-card-hover);
  border-color: var(--ios-border-light);
  transform: translateY(-1px);
}

.material-card.active {
  background: rgba(37, 99, 235, 0.08);
  border-color: var(--brand);
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.18);
}

html.dark .material-card.active {
  background: rgba(37, 99, 235, 0.15);
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.material-card.active .material-name {
  color: var(--brand);
  font-weight: 600;
}

/* Apple Buttons */
.ios-btn-primary {
  background: linear-gradient(180deg, #3B82F6 0%, #1D4ED8 100%);
  color: #FFFFFF;
  font-weight: 600;
  border-radius: 12px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.ios-btn-primary:hover {
  background: linear-gradient(180deg, #60A5FA 0%, #2563EB 100%);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
  transform: translateY(-1px);
}

.ios-btn-primary:active {
  transform: translateY(1px) scale(0.98);
}

.ios-btn-secondary {
  background: var(--ios-bg-secondary);
  color: var(--ios-text-primary);
  font-weight: 500;
  border-radius: 12px;
  padding: 7px 13px;
  border: 1px solid var(--ios-border-subtle);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.ios-btn-secondary:hover {
  background: var(--ios-bg-tertiary);
  border-color: var(--ios-border-light);
}

.ios-btn-secondary:active {
  transform: scale(0.97);
}

/* 3D Viewport Background */
.ios-viewport-bg {
  background: var(--viewport-bg-gradient);
  transition: background 0.4s ease;
}

/* Progress bar breakdown */
.cost-bar-container {
  display: flex;
  height: 8px;
  border-radius: 9999px;
  overflow: hidden;
  background: var(--ios-bg-secondary);
  gap: 2px;
}

.cost-bar-segment {
  height: 100%;
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 2px;
}

/* Modal animation */
.ios-modal-backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: fadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.ios-modal-card {
  background: var(--ios-bg-surface);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--ios-border-light);
  border-radius: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--ios-text-primary);
}

html.dark .ios-modal-card {
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7), inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Printable Quote View */
@media print {
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  body > *:not(#modal-quote) { display: none !important; }
  #modal-quote { position: static !important; display: block !important; background: #fff !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important; padding: 0 !important; animation: none !important; }
  #modal-quote .ios-modal-card { position: static !important; height: auto !important; max-height: none !important;
    overflow: visible !important; box-shadow: none !important; border: none !important; border-radius: 0 !important;
    background: #fff !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; animation: none !important; }
  #modal-quote .scroll-area { overflow: visible !important; height: auto !important; max-height: none !important; }
  #modal-quote-content { color: #000 !important; background: #fff !important; padding: 0 !important; }
  .no-print { display: none !important; }
  @page { margin: 14mm; }
}

/* Schermi molto stretti (≤350px): niente sforamenti nell'header */
@media (max-width: 350px) {
  #btn-mobile-open-history > span:not(#mobile-history-badge) { display: none; }
}
