/* ==========================================================================
   MacroCalc — Modern Dark Mode Design System & iOS PWA Styles
   ========================================================================== */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Color Palette (Deep Slate & Zinc with Emerald Accents) */
  --bg-app: #080c14;
  --bg-card: #0f172a;
  --bg-card-inner: #162033;
  --bg-input: #0b1120;
  
  --border-subtle: #1e293b;
  --border-focus: #10b981;
  --border-card: #334155;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  /* Brand & Macro Colors */
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  
  --kcal-color: #f59e0b;
  --kcal-bg: rgba(245, 158, 11, 0.12);
  --kcal-border: rgba(245, 158, 11, 0.25);

  --fat-color: #eab308;
  --fat-bg: rgba(234, 179, 8, 0.12);
  --fat-border: rgba(234, 179, 8, 0.25);

  --carbs-color: #38bdf8;
  --carbs-bg: rgba(56, 189, 248, 0.12);
  --carbs-border: rgba(56, 189, 248, 0.25);

  --protein-color: #34d399;
  --protein-bg: rgba(52, 211, 153, 0.12);
  --protein-border: rgba(52, 211, 153, 0.25);

  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-card: 0 16px 36px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* Base Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* PWA Mobile Wrapper with iOS Safe Areas */
.app-wrapper {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: max(1.2rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 0%, #162038 0%, #080c14 65%);
}

/* App Header */
.app-header {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding: 0.25rem 0.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--primary-glow);
  color: #ffffff;
  flex-shrink: 0;
}

.logo-icon {
  width: 24px;
  height: 24px;
}

.app-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  line-height: 1.15;
}

.app-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.pwa-badge {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.12);
  color: var(--primary);
  border: 1px solid rgba(16, 185, 129, 0.28);
}

/* Main Card */
.calculator-card {
  width: 100%;
  max-width: 480px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Form Groups */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.highlight-group {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08) 0%, rgba(16, 185, 129, 0.02) 100%);
  border: 1px solid rgba(16, 185, 129, 0.22);
  border-radius: var(--radius-md);
  padding: 0.9rem;
}

.input-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.highlight-group .input-label {
  color: #34d399;
}

.label-icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.label-icon-wrapper svg {
  width: 16px;
  height: 16px;
}

.weight-icon { color: #34d399; }
.kcal-icon { color: var(--kcal-color); }
.fat-icon { color: var(--fat-color); }
.carbs-icon { color: var(--carbs-color); }
.protein-icon { color: var(--protein-color); }

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

.form-control {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 1.15rem;
  font-weight: 600;
  padding: 0.75rem 3.5rem 0.75rem 0.95rem;
  outline: none;
  transition: var(--transition);
  user-select: text;
}

.main-input {
  font-size: 1.35rem;
  padding-right: 4.8rem;
  border-color: rgba(16, 185, 129, 0.35);
}

.form-control::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

.form-control:focus {
  border-color: var(--border-focus);
  background-color: #0d1527;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-suffix {
  position: absolute;
  right: 0.95rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  pointer-events: none;
}

.error-hint {
  display: none;
  font-size: 0.78rem;
  color: var(--danger);
  margin-top: 0.25rem;
}

.error-hint.visible {
  display: block;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 0.25rem 0;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}

.divider span {
  padding: 0 0.8rem;
}

/* 2x2 Macros Input Grid */
.macros-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

/* Form Action Buttons */
.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  touch-action: manipulation;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  flex: 2;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

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

.btn-secondary {
  flex: 1;
  background: var(--bg-card-inner);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: #1e293b;
  color: var(--text-main);
  border-color: #475569;
}

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

/* ==========================================================================
   Result Section (Slide & Fade-in Animation)
   ========================================================================== */
.result-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border-subtle);
  opacity: 1;
  max-height: 800px;
  transform: translateY(0);
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), 
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              max-height 0.4s ease;
  overflow: hidden;
}

.result-section.hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  border-top: none;
  transform: translateY(12px);
  pointer-events: none;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.result-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.result-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.result-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

/* Copy All Button */
.btn-copy-all {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-full);
  padding: 0.45rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}

.btn-copy-all:hover {
  background: rgba(16, 185, 129, 0.22);
  border-color: #34d399;
  color: #ffffff;
}

.btn-copy-all:active {
  transform: scale(0.96);
}

.btn-copy-all.copied {
  background: #10b981;
  color: #ffffff;
  border-color: #10b981;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.5);
}

/* Results Grid */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.result-card {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: var(--transition);
}

.result-card:hover {
  border-color: #334155;
  transform: translateY(-1px);
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.result-tag {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tag-kcal { color: var(--kcal-color); }
.tag-fat { color: var(--fat-color); }
.tag-carbs { color: var(--carbs-color); }
.protein-card .tag-protein { color: var(--protein-color); }

/* Compact Single Copy Button */
.btn-copy-single {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: var(--transition);
}

.btn-copy-single .btn-icon {
  width: 12px;
  height: 12px;
}

.btn-copy-single:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-copy-single:active {
  transform: scale(0.94);
}

.btn-copy-single.copied {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: #10b981;
}

.result-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  user-select: text;
}

.result-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.result-unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* Macro Ratio Distribution Bar */
.macro-distribution {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.distribution-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.distribution-bar {
  display: flex;
  width: 100%;
  height: 8px;
  background-color: #1e293b;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.bar-segment {
  height: 100%;
  transition: width 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.seg-fat { background-color: var(--fat-color); }
.seg-carbs { background-color: var(--carbs-color); }
.seg-protein { background-color: var(--protein-color); }

/* iOS PWA Install Hint */
.ios-install-hint {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.35;
}

.hint-icon {
  width: 18px;
  height: 18px;
  color: #38bdf8;
  flex-shrink: 0;
}

.ios-install-hint strong {
  color: var(--text-muted);
}

/* Toast Notification */
.toast-notification {
  position: fixed;
  bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 1rem));
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: #0f172a;
  border: 1px solid #10b981;
  color: #ffffff;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-full);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6), 0 0 16px rgba(16, 185, 129, 0.3);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-notification.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(16px);
}

.toast-icon {
  width: 16px;
  height: 16px;
  color: #10b981;
}

/* Utility Hidden */
.hidden {
  display: none !important;
}

/* Responsive Breakpoints */
@media (max-width: 380px) {
  .calculator-card {
    padding: 1.1rem;
  }
  .macros-grid, .result-grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }
  .app-title {
    font-size: 1.3rem;
  }
}

@media (min-width: 640px) {
  .app-wrapper {
    justify-content: center;
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
}
