/* ================================================================
   InsuCalc – Style Sheet
   Palette: Orange (#FF6B2B, #FF9A56) + Cyan (#00C5D7, #00E5F5)
   Design: Medical glassmorphism, dark-base, mobile-first
   ================================================================ */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  --orange-primary:  #FF6B2B;
  --orange-light:    #FF9A56;
  --orange-glow:     rgba(255, 107, 43, 0.35);
  --orange-soft:     rgba(255, 107, 43, 0.12);

  --cyan-primary:    #00C5D7;
  --cyan-light:      #00E5F5;
  --cyan-glow:       rgba(0, 197, 215, 0.30);
  --cyan-soft:       rgba(0, 197, 215, 0.10);

  --bg-base:         #0A0E1A;
  --bg-card:         rgba(14, 20, 38, 0.80);
  --bg-input:        rgba(255, 255, 255, 0.05);
  --bg-hover:        rgba(255, 255, 255, 0.08);
  --bg-table-row:    rgba(255, 255, 255, 0.03);
  --bg-table-hover:  rgba(0, 197, 215, 0.08);

  --text-primary:    #F0F4FF;
  --text-secondary:  #8B9ABF;
  --text-muted:      #5A6882;

  --border-default:  rgba(255, 255, 255, 0.08);
  --border-focus:    var(--cyan-primary);
  --border-table:    rgba(255, 255, 255, 0.06);

  --radius-card:     24px;
  --radius-input:    14px;
  --radius-btn:      14px;
  --radius-badge:    100px;

  --shadow-card:     0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px var(--border-default);
  --shadow-btn:      0 8px 32px var(--orange-glow);
  --shadow-glow-c:   0 0 40px var(--cyan-glow);

  --transition:      all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  --font:            'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 40px;
  overflow-x: hidden;
  position: relative;
}

/* ── Animated Background Blobs ──────────────────────────────────── */
.bg-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
  animation: blobFloat 8s ease-in-out infinite alternate;
}

.blob-1 {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(255,107,43,0.18) 0%, transparent 70%);
  top: -80px;
  right: -80px;
  animation-delay: 0s;
}

.blob-2 {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(0,197,215,0.15) 0%, transparent 70%);
  bottom: -60px;
  left: -60px;
  animation-delay: -3s;
}

.blob-3 {
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255,154,86,0.10) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  animation-delay: -6s;
}

@keyframes blobFloat {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(20px, 30px) scale(1.05); }
}

.blob-3 {
  animation-name: blobFloatCenter;
}
@keyframes blobFloatCenter {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(calc(-50% + 15px), calc(-50% + 20px)) scale(1.08); }
}

/* ── App Wrapper ────────────────────────────────────────────────── */
.app-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Header ─────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 6px;
}

.header-icon {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--orange-primary), var(--cyan-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 24px var(--orange-glow), 0 0 0 1px rgba(255,255,255,0.1) inset;
}

.header-text h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--orange-light), var(--cyan-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.header-subtitle {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Main Card ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-default);
  overflow: hidden;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Insulin Badge ───────────────────────────────────────────────── */
.insulin-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cyan-primary);
  background: var(--cyan-soft);
  border: 1px solid rgba(0,197,215,0.20);
  border-radius: var(--radius-badge);
  padding: 6px 14px;
  letter-spacing: 0.03em;
  margin-bottom: 24px;
  align-self: flex-start;
  text-transform: uppercase;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan-light);
  box-shadow: 0 0 6px var(--cyan-primary);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ── Input Section ───────────────────────────────────────────────── */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.input-label svg {
  color: var(--orange-primary);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

#glucose-input {
  width: 100%;
  padding: 18px 60px 18px 20px;
  font-family: var(--font);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-input);
  outline: none;
  transition: var(--transition);
  -moz-appearance: textfield;
  letter-spacing: -0.02em;
}

#glucose-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 1.2rem;
}

#glucose-input::-webkit-outer-spin-button,
#glucose-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#glucose-input:focus {
  border-color: var(--cyan-primary);
  background: rgba(0, 197, 215, 0.06);
  box-shadow: 0 0 0 3px var(--cyan-glow);
}

#glucose-input.input-error {
  border-color: #FF4565;
  box-shadow: 0 0 0 3px rgba(255, 69, 101, 0.20);
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.input-unit {
  position: absolute;
  right: 18px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

/* ── Calculate Button ────────────────────────────────────────────── */
.btn-calculate {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 17px 24px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--orange-primary) 0%, #FF8C00 50%, var(--orange-light) 100%);
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-btn);
  transition: var(--transition);
  letter-spacing: 0.01em;
}

.btn-calculate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 60%);
  pointer-events: none;
}

.btn-calculate:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px var(--orange-glow), 0 4px 12px rgba(0,0,0,0.3);
}

.btn-calculate:active {
  transform: translateY(0);
  box-shadow: var(--shadow-btn);
}

.btn-calculate:focus-visible {
  outline: 3px solid var(--orange-light);
  outline-offset: 3px;
}

.btn-icon {
  flex-shrink: 0;
}

/* ── Result Section ──────────────────────────────────────────────── */
.result-section {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeSlideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 4px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-divider::before,
.result-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-default);
}

/* Warning card */
.result-warning {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: rgba(255, 69, 101, 0.10);
  border: 1px solid rgba(255, 69, 101, 0.25);
  border-radius: 16px;
  animation: fadeSlideUp 0.4s ease;
}

.warning-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.warning-text strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: #FF6B82;
  margin-bottom: 4px;
}

.warning-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Normal result */
.result-normal {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: 18px;
  padding: 18px 20px;
}

.result-glucose-display,
.result-dose-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.glucose-label,
.dose-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.glucose-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--orange-light);
  line-height: 1;
  letter-spacing: -0.03em;
}

.glucose-unit,
.dose-unit {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.result-arrow {
  font-size: 1.4rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.dose-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--cyan-light);
  line-height: 1;
  letter-spacing: -0.03em;
}

/* Syringe visual */
.syringe-visual {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.syringe-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan-primary), var(--cyan-light));
  box-shadow: 0 0 14px var(--cyan-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0); }
  to   { opacity: 1; transform: scale(1); }
}

/* Range bar */
.range-bar-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.range-bar {
  height: 8px;
  border-radius: 100px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  position: relative;
  overflow: hidden;
}

.range-indicator {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 100px;
  background: linear-gradient(90deg, var(--cyan-primary), var(--orange-primary));
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 8px;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Result tip */
.result-tip {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
  padding: 12px 16px;
  background: var(--bg-input);
  border-radius: 12px;
  border: 1px solid var(--border-default);
}

/* ── Table Toggle Button ─────────────────────────────────────────── */
.btn-table-toggle {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 13px 18px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: 14px;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.01em;
}

.btn-table-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.12);
}

.btn-table-toggle .chevron {
  margin-left: auto;
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.btn-table-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

/* ── Reference Table ─────────────────────────────────────────────── */
.reference-table {
  margin-top: 12px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-table);
  animation: fadeSlideUp 0.3s ease;
}

.reference-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.reference-table thead th {
  padding: 12px 16px;
  background: rgba(0, 197, 215, 0.08);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cyan-primary);
  text-align: left;
  border-bottom: 1px solid var(--border-table);
}

.reference-table tbody tr {
  background: var(--bg-table-row);
  border-bottom: 1px solid var(--border-table);
  transition: background 0.2s;
}

.reference-table tbody tr:last-child {
  border-bottom: none;
}

.reference-table tbody tr:hover {
  background: var(--bg-table-hover);
}

.reference-table tbody tr.highlighted {
  background: rgba(0, 197, 215, 0.14);
  border-left: 3px solid var(--cyan-primary);
}

.reference-table tbody td {
  padding: 12px 16px;
  color: var(--text-primary);
  font-weight: 500;
}

.reference-table tbody td:last-child {
  font-weight: 700;
  color: var(--cyan-light);
}

/* ── Disclaimer Footer ───────────────────────────────────────────── */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: left;
  padding: 0 4px;
}

.disclaimer svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--text-muted);
}

/* ── Utility ─────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Responsive tweaks ── */
@media (max-width: 360px) {
  .card {
    padding: 22px 18px;
  }

  .header-text h1 {
    font-size: 1.5rem;
  }

  #glucose-input {
    font-size: 1.35rem;
    padding: 15px 58px 15px 18px;
  }

  .glucose-value,
  .dose-value {
    font-size: 1.65rem;
  }

  .result-row {
    padding: 14px 16px;
  }
}

@media (min-width: 480px) {
  .syringe-dot {
    width: 36px;
    height: 36px;
  }
}
