:root {
  /* Apple-inspired Color Palette */
  --system-blue: #007aff;
  --system-green: #34c759;
  --system-orange: #ff9500;
  --system-red: #ff3b30;
  --system-gray: #8e8e93;
  --system-background: #f5f5f7;
  --system-surface: rgba(255, 255, 255, 0.72);
  --system-surface-elevated: rgba(255, 255, 255, 0.85);
  --system-separator: rgba(0, 0, 0, 0.08);
  --system-text: #1d1d1f;
  --system-text-secondary: #86868b;
  --system-text-tertiary: #a1a1a6;
  
  /* Layout & Depth */
  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-medium: 0 8px 18px rgba(0, 0, 0, 0.08);
  --blur: 15px;
  
  /* Animations */
  --transition-fluid: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@media (prefers-color-scheme: dark) {
  :root {
    --system-background: #000000;
    --system-surface: rgba(44, 44, 46, 0.8);
    --system-surface-elevated: rgba(58, 58, 60, 0.9);
    --system-separator: rgba(255, 255, 255, 0.15);
    --system-text: #f5f5f7;
    --system-text-secondary: #a1a1a6;
    --system-text-tertiary: #6e6e73;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--system-background);
  color: var(--system-text);
  line-height: 1.47059;
  font-weight: 400;
  letter-spacing: -0.022em;
  overflow-x: hidden;
}

/* Glassmorphism Containers */
.glass {
  background: var(--system-surface);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--system-separator);
}

.glass-elevated {
  background: var(--system-surface-elevated);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--system-separator);
  box-shadow: var(--shadow-medium);
}

/* Navigation */
.app-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--system-separator);
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.011em;
}

/* Main Layout */
.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 60px 16px 40px;
}

.hero-section {
  text-align: left;
  margin-bottom: 24px;
}

.hero-section h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-bottom: 4px;
}

.hero-section p {
  font-size: 15px;
  color: var(--system-text-secondary);
  font-weight: 400;
}

.main-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

/* Sidebar / Input Panel */
.panel-input {
  grid-column: span 5;
}

.panel-results {
  grid-column: span 7;
}

@media (max-width: 900px) {
  .panel-input, .panel-results {
    grid-column: span 12;
  }
}

/* Actions */
.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* Cards */
.card {
  border-radius: var(--radius-lg);
  padding: 16px;
}

.card-title {
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: 0.007em;
}

/* Form Elements */
.input-group {
  margin-bottom: 12px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--system-text-secondary);
}

.field-pack {
  position: relative;
  display: flex;
  align-items: center;
}

input, select {
  width: 100%;
  height: 34px;
  background: var(--system-background);
  border: 1px solid var(--system-separator);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 14px;
  color: var(--system-text);
  transition: var(--transition-fluid);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--system-blue);
  background: var(--system-surface-elevated);
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.field-prefix {
  position: absolute;
  left: 12px;
  color: var(--system-text-tertiary);
  font-size: 17px;
  pointer-events: none;
}

.field-pack.has-prefix input {
  padding-left: 44px;
}

/* Custom Select Styling */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238e8e93' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

/* Switches */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  min-height: 34px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--system-separator);
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

input:checked + .slider {
  background-color: var(--system-blue);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Dynamic Lists (Process & Components) */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--system-background);
  border-radius: var(--radius-md);
  border: 1px solid var(--system-separator);
  transition: var(--transition-fluid);
}

.list-item:hover {
  background: var(--system-surface-elevated);
  transform: translateY(-2px);
}

.list-item__copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item__copy strong {
  font-size: 15px;
  font-weight: 600;
}

.list-item__copy span {
  font-size: 13px;
  color: var(--system-text-secondary);
}

.list-item__actions {
  display: flex;
  gap: 8px;
}

.list-action {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  background: var(--system-separator);
  color: var(--system-blue);
  cursor: pointer;
  transition: var(--transition-fluid);
}

.list-action.is-selected {
  background: var(--system-blue);
  color: white;
}

.list-action.is-danger {
  color: var(--system-red);
}

.list-action.is-danger:hover {
  background: rgba(255, 59, 48, 0.1);
}

/* Delta Badge */
.delta-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.delta-badge.is-positive {
  background: rgba(52, 199, 89, 0.1);
  color: var(--system-green);
}

.delta-badge.is-negative {
  background: rgba(255, 59, 48, 0.1);
  color: var(--system-red);
}

/* Active Extras (Mini Cards) */
.extra-row {
  margin-top: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--system-background);
  border: 1px solid var(--system-separator);
  transition: var(--transition-fluid);
}

.extra-row:hover {
  background: var(--system-surface-elevated);
}

.extra-row__top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  align-items: center;
}

.extra-row__title {
  display: flex;
  flex-direction: column;
}

.extra-row__title strong {
  font-size: 14px;
  font-weight: 600;
}

.extra-row__title span {
  font-size: 12px;
  color: var(--system-text-secondary);
}

.extra-row__controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.extra-row__controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.extra-row__delete {
  font-size: 13px;
  font-weight: 500;
  color: var(--system-red);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition-fluid);
}

.extra-row__delete:hover {
  background: rgba(255, 59, 48, 0.1);
}

/* Stepper & Inline Elements */
.qty-stepper {
  display: flex;
  align-items: center;
  background: var(--system-separator);
  border-radius: 8px;
  padding: 2px;
  width: fit-content;
}

.qty-stepper button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--system-blue);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition-fluid);
}

.qty-stepper button:hover {
  background: var(--system-surface-elevated);
}

.qty-stepper span {
  min-width: 32px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--system-text);
}

.extra-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Mode Tabs Fix Visibility */
.mode-tabs {
  background: var(--system-separator);
  border-radius: 10px;
  padding: 2px;
  display: flex;
  margin-bottom: 16px;
  position: relative;
  border: 1px solid var(--system-separator);
}

.mode-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--system-text-secondary);
  cursor: pointer;
  z-index: 1;
  transition: var(--transition-fluid);
  border-radius: 8px;
}

.mode-tab.is-active {
  color: var(--system-text);
  font-weight: 600;
}

.mode-indicator {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  background: #ffffff; /* Use solid white for light mode visibility */
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  border-radius: 8px;
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
  z-index: 0;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .mode-indicator {
    background: #636366; /* Higher contrast in dark mode */
  }
}

/* Buttons */
.btn {
  height: 34px;
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fluid);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--system-blue);
  color: white;
}

.btn-primary:hover {
  background: #0071e3;
}

.btn-secondary {
  background: var(--system-separator);
  color: var(--system-blue);
}

.btn-secondary:hover {
  background: rgba(0, 122, 255, 0.1);
}

.btn:active {
  transform: scale(0.98);
}

/* Results Section */
.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.metric-card {
  padding: 12px;
  border-radius: var(--radius-md);
  text-align: center;
}

.metric-label {
  font-size: 11px;
  color: var(--system-text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.metric-blue { background: rgba(0, 122, 255, 0.08); color: var(--system-blue); }
.metric-green { background: rgba(52, 199, 89, 0.08); color: var(--system-green); }
.metric-orange { background: rgba(255, 149, 0, 0.08); color: var(--system-orange); }

/* Details Table */
.details-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--system-separator);
}

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

.detail-label {
  color: var(--system-text-secondary);
  font-size: 15px;
}

.detail-value {
  font-weight: 600;
  font-size: 15px;
}

.detail-row.is-total .detail-value {
  color: var(--system-green);
  font-size: 19px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.modal-header {
  padding: 24px 30px;
  border-bottom: 1px solid var(--system-separator);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 30px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 20px 30px;
  border-top: 1px solid var(--system-separator);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Utilities */
.is-hidden { display: none !important; }

/* Responsive Adjustments */
@media (max-width: 900px) {
  .hero-section h1 { font-size: 24px; }
  .panel-input, .panel-results { grid-column: span 12; }
  .app-container { padding-top: 50px; }
  .main-grid { gap: 12px; }
  .results-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .card { padding: 12px; }
  .metric-value { font-size: 18px; }
  .nav-title { font-size: 15px; }
}

@media print {
  .app-nav, .panel-actions, .panel-foot, .modal, #syncIndicator, .hero-section p {
    display: none !important;
  }
  .app-container { padding: 0; }
  .card { border: 1px solid #ddd; box-shadow: none; border-radius: 0; }
}

