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

:root {
  --blue:    #1e40af;
  --blue-lt: #dbeafe;
  --green:   #15803d;
  --green-lt:#dcfce7;
  --red:     #dc2626;
  --orange:  #d97706;
  --gray-50: #f8fafc;
  --gray-100:#f1f5f9;
  --gray-200:#e2e8f0;
  --gray-400:#94a3b8;
  --gray-600:#475569;
  --gray-700:#334155;
  --gray-900:#0f172a;
  --white:   #ffffff;
  --shadow:  0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius:  12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--blue);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.header-inner {
  max-width: 700px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.header-sub { font-size: .8rem; opacity: .75; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  max-width: 700px;
  margin: 0 auto;
  background: var(--white);
  border-bottom: 2px solid var(--gray-200);
  position: sticky;
  top: 49px;
  z-index: 90;
}
.tab {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--blue); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Tab Content ──────────────────────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Inputs Card ──────────────────────────────────────────────────────────── */
.inputs-card {
  max-width: 700px;
  margin: 16px auto 0;
  padding: 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.inputs-card h2 {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-400);
  margin-bottom: 12px;
}
.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.input-grid label { display: flex; flex-direction: column; gap: 4px; }
.input-grid label > span:first-child {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-600);
}
.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 2px 10px 2px 0;
  transition: border-color .15s;
}
.input-row:focus-within { border-color: var(--blue); background: #fff; }
.input-row input {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
  width: 100%;
  padding: 8px 0 8px 10px;
  outline: none;
  -moz-appearance: textfield;
}
.input-row input::-webkit-outer-spin-button,
.input-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.input-row .unit { font-size: .8rem; color: var(--gray-400); white-space: nowrap; }
.input-hint {
  font-size: .75rem;
  color: var(--green);
  font-weight: 600;
  min-height: 1rem;
}

/* ── Results ──────────────────────────────────────────────────────────────── */
.results-section {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 0 16px;
}
.section-title {
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 14px 16px 6px;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}
.section-title.intubacao { color: #7c3aed; }
.section-title.farmacos  { color: var(--red); }
.section-title.acessos   { color: var(--orange); }
.section-title.perfusoes { color: var(--gray-600); }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 0 8px;
}

/* ── Card flip ────────────────────────────────────────────────────────────── */
.card-flip {
  perspective: 800px;
}

.result-card {
  background: var(--white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.4,0,.2,1), box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.result-card.flipped { transform: rotateY(180deg); }

.card-front {
  display: flex;
  flex-direction: column;
  gap: 4px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  background: var(--blue);
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateY(180deg);
  text-align: center;
  pointer-events: none;
}
.back-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .7;
}
.back-formula {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.4;
  white-space: pre-line;
}
.back-timer {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,.25);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow: hidden;
}
.back-timer-bar {
  height: 100%;
  background: rgba(255,255,255,.7);
  width: 100%;
  transform-origin: left;
  animation: timerShrink 5s linear forwards;
}
@keyframes timerShrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

.result-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.drug-name {
  font-size: .85rem;
  font-weight: 700;
  color: var(--gray-700);
  line-height: 1.3;
  flex: 1 1 100%;
}
.dose-ref {
  font-size: .7rem;
  background: var(--gray-100);
  color: var(--gray-600);
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}
.drug-max {
  font-size: .7rem;
  background: #fef3c7;
  color: #92400e;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
}

.result-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 2px;
}
.value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
  letter-spacing: -.03em;
}
.value.no-formula { color: var(--gray-400); font-size: 1.2rem; }
.result-value .unit {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-400);
}

.drug-note {
  font-size: .72rem;
  color: var(--gray-600);
  line-height: 1.4;
  margin-top: 4px;
  border-top: 1px solid var(--gray-100);
  padding-top: 6px;
}

.perf-card { opacity: .7; }
.perf-card .result-value { display: none; }

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  max-width: 700px;
  margin: 8px auto 24px;
  padding: 12px 16px;
  text-align: center;
  font-size: .72rem;
  color: var(--gray-400);
  border-top: 1px solid var(--gray-200);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .results-grid { grid-template-columns: 1fr 1fr; }
  .value { font-size: 1.4rem; }
}
@media (min-width: 600px) {
  .results-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
