:root {
  color-scheme: light;
  --ink: #102c35;
  --muted: #5b7078;
  --deep: #0b3b4a;
  --teal: #087f83;
  --teal-soft: #dff4f2;
  --blue-soft: #eaf4f8;
  --line: #d7e3e6;
  --paper: #ffffff;
  --canvas: #f2f7f8;
  --orange: #ef8b32;
  --green: #25866b;
  --green-soft: #e1f4ec;
  --amber: #c77b13;
  --amber-soft: #fff2d7;
  --coral: #c95345;
  --coral-soft: #fde8e4;
  --red: #9c2f36;
  --red-soft: #fae3e6;
  --shadow: 0 20px 50px rgba(14, 57, 70, 0.09);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 0%, rgba(8, 127, 131, 0.12), transparent 32rem),
    linear-gradient(180deg, #f8fbfc 0, var(--canvas) 34rem);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }

.topbar {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: max(14px, env(safe-area-inset-top)) 0 14px;
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--deep); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 15px; box-shadow: 0 8px 20px rgba(11, 59, 74, 0.18); overflow: hidden; }
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.08rem; letter-spacing: -0.025em; line-height: 1.15; }
.brand strong i { color: var(--teal); font-style: normal; }
.brand small { margin-top: 3px; color: var(--muted); font-size: .64rem; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.connection-badge { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 650; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(37, 134, 107, .12); }
.connection-badge.offline .connection-dot { background: var(--orange); box-shadow: 0 0 0 4px rgba(239, 139, 50, .14); }
.install-button, .secondary-button { border: 1px solid var(--line); background: rgba(255,255,255,.88); color: var(--deep); border-radius: 12px; padding: 10px 16px; font-weight: 750; }
.install-button:hover, .secondary-button:hover { border-color: #a9c5cc; background: #fff; }

main { padding: 44px 0 28px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 28px; }
.intro > div:first-child { max-width: 720px; }
.eyebrow { margin: 0 0 8px; color: var(--teal); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1.03; letter-spacing: -.052em; color: var(--deep); }
.intro > div:first-child > p:last-child { max-width: 650px; margin: 0; color: var(--muted); font-size: 1.05rem; }
.formula-chip { flex: 0 0 auto; min-width: 250px; padding: 15px 18px; border: 1px solid rgba(8, 127, 131, .16); border-radius: 16px; background: rgba(223, 244, 242, .7); }
.formula-chip span, .formula-chip strong { display: block; }
.formula-chip span { color: var(--teal); font-size: .74rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.formula-chip strong { margin-top: 3px; color: var(--deep); font-size: .96rem; }

.install-help { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin: -6px 0 22px; padding: 15px 18px; border: 1px solid #bcdfe0; border-radius: 15px; background: #ecf9f8; color: var(--deep); }
.install-help p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.install-help button { border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; line-height: 1; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: 22px; align-items: stretch; }
.calculator-card, .result-card, .reference-card, .safety-grid > article, .safety-grid > details { border: 1px solid rgba(168, 195, 201, .64); background: rgba(255,255,255,.95); box-shadow: var(--shadow); }
.calculator-card, .result-card { min-height: 520px; border-radius: 24px; padding: 28px; }
.section-heading { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 25px; }
.section-heading.compact { margin-bottom: 20px; }
.step-number { display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 11px; color: #fff; background: var(--deep); font-weight: 850; }
.section-heading h2 { margin: 0; color: var(--deep); font-size: 1.14rem; letter-spacing: -.015em; }
.section-heading p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

.field-grid { display: grid; gap: 18px; }
.field { display: block; }
.field > span:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; color: var(--ink); font-size: .9rem; font-weight: 770; }
.field em { color: var(--muted); font-size: .7rem; font-style: normal; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.input-wrap { display: flex; align-items: center; overflow: hidden; min-height: 52px; border: 1.5px solid #c9dadd; border-radius: 14px; background: #fbfdfd; transition: border-color .16s, box-shadow .16s; }
.input-wrap:focus-within { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(8,127,131,.1); background: #fff; }
.input-wrap input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; padding: 12px 14px; color: var(--deep); font-size: 1.05rem; font-weight: 740; }
.input-wrap input::placeholder { color: #9aacb1; font-weight: 500; }
.input-wrap b { align-self: stretch; display: flex; align-items: center; padding: 0 14px; border-left: 1px solid var(--line); color: var(--muted); background: #f2f7f8; font-size: .82rem; white-space: nowrap; }
.field > small { display: block; margin: 6px 2px 0; color: var(--muted); font-size: .76rem; }
.field > .field-error { min-height: 0; margin-top: 2px; color: var(--red); font-weight: 700; }
.field.invalid .input-wrap { border-color: var(--red); box-shadow: 0 0 0 3px rgba(156,47,54,.08); }
.field-optional { padding-top: 5px; border-top: 1px dashed var(--line); }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; flex: 1; min-height: 50px; border: 0; border-radius: 14px; background: var(--deep); color: #fff; font-weight: 800; box-shadow: 0 10px 20px rgba(11,59,74,.18); }
.primary-button:hover { background: #0e4c5e; }
.primary-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.result-card { background: linear-gradient(155deg, rgba(255,255,255,.98), rgba(237,247,248,.98)); }
.empty-state { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 74px; height: 74px; margin-bottom: 15px; border-radius: 22px; background: var(--blue-soft); color: var(--teal); }
.empty-icon svg { width: 42px; fill: none; stroke: currentColor; stroke-width: 2.7; stroke-linecap: round; }
.empty-state strong { color: var(--deep); font-size: 1.08rem; }
.empty-state p { max-width: 290px; margin: 5px 0 0; font-size: .9rem; }
.result-content { animation: reveal .3s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.result-hero { padding: 22px; border-radius: 19px; background: var(--deep); color: #fff; box-shadow: 0 14px 30px rgba(11,59,74,.2); }
.result-hero > p:first-child { margin-bottom: 2px; color: #c4e1e6; font-size: .82rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.result-value-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.result-value-row > strong { font-size: clamp(3rem, 7vw, 4.8rem); line-height: 1; letter-spacing: -.06em; }
.result-badge { max-width: 210px; border-radius: 999px; padding: 8px 12px; background: rgba(255,255,255,.13); font-size: .78rem; font-weight: 800; line-height: 1.25; text-align: center; }
.result-summary { margin: 14px 0 0; color: #d8ecef; font-size: .9rem; }

.scale { margin: 24px 2px 20px; }
.scale-track { position: relative; display: grid; grid-template-columns: 40fr 14.4fr 19.8fr 26fr; height: 9px; border-radius: 999px; }
.scale-segment:first-child { border-radius: 999px 0 0 999px; }
.scale-segment:last-of-type { border-radius: 0 999px 999px 0; }
.scale-segment.conserved { background: var(--green); }
.scale-segment.borderline { background: #e2a63d; }
.scale-segment.resistant { background: var(--coral); }
.scale-segment.marked { background: var(--red); }
.scale-marker { position: absolute; top: 50%; left: 0; width: 17px; height: 17px; border: 3px solid #fff; border-radius: 50%; background: var(--deep); box-shadow: 0 2px 8px rgba(16,44,53,.3); transform: translate(-50%, -50%); transition: left .35s ease; }
.scale-labels { display: flex; justify-content: space-between; margin-top: 7px; color: var(--muted); font-size: .68rem; font-weight: 750; }

.result-details { margin: 0; border: 1px solid var(--line); border-radius: 16px; background: #fff; overflow: hidden; }
.result-details > div { display: grid; grid-template-columns: 145px 1fr; gap: 12px; padding: 12px 14px; }
.result-details > div + div { border-top: 1px solid var(--line); }
.result-details dt { color: var(--muted); font-size: .78rem; font-weight: 700; }
.result-details dd { margin: 0; color: var(--ink); font-size: .84rem; font-weight: 760; text-align: right; }
.clinical-note { display: flex; gap: 10px; margin-top: 16px; padding: 13px 14px; border-radius: 14px; background: rgba(255,242,215,.72); color: #6f4a13; }
.clinical-note svg { flex: 0 0 auto; width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.clinical-note p { margin: 0; font-size: .78rem; }

.reference-card { margin-top: 22px; border-radius: 24px; padding: 26px 28px; }
.reference-header { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 18px; }
.reference-header h2 { margin: 0; color: var(--deep); font-size: 1.32rem; letter-spacing: -.025em; }
.reference-header > span { padding: 6px 11px; border-radius: 999px; color: var(--teal); background: var(--teal-soft); font-size: .74rem; font-weight: 800; text-transform: uppercase; }
.reference-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.reference-item { position: relative; min-height: 132px; display: flex; flex-direction: column; padding: 17px; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fbfdfd; }
.reference-item::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: currentColor; }
.reference-item.conserved { color: var(--green); }
.reference-item.borderline { color: var(--amber); }
.reference-item.resistant { color: var(--coral); }
.reference-item.marked { color: var(--red); }
.reference-item strong { font-size: 1.42rem; letter-spacing: -.03em; }
.reference-item span { margin-top: 3px; color: var(--ink); font-size: .85rem; font-weight: 760; line-height: 1.3; }
.reference-item small { margin-top: auto; color: var(--muted); font-size: .7rem; }
.reference-footnote { margin: 16px 0 0; color: var(--muted); font-size: .8rem; }

.safety-grid { display: grid; grid-template-columns: 1.4fr .6fr; gap: 14px; margin-top: 14px; }
.safety-grid > article, .safety-grid > details { border-radius: 18px; padding: 18px 20px; box-shadow: none; }
.safety-grid > article { display: flex; gap: 13px; }
.safety-icon { display: grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-weight: 900; }
.safety-grid h2 { margin: 0 0 4px; color: var(--deep); font-size: .95rem; }
.safety-grid p { margin: 0; color: var(--muted); font-size: .8rem; }
.safety-grid summary { color: var(--deep); font-weight: 800; cursor: pointer; }
.sources { display: grid; gap: 8px; margin-top: 12px; }
.sources a { color: var(--teal); font-size: .78rem; font-weight: 650; text-underline-offset: 3px; }

footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 28px 0 max(28px, env(safe-area-inset-bottom)); color: var(--muted); font-size: .78rem; }
footer p { margin: 0; }
footer a { color: var(--teal); font-weight: 750; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .calculator-card, .result-card { min-height: auto; }
  .reference-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .app-shell { width: min(100% - 22px, 1180px); }
  .topbar { min-height: 72px; }
  .connection-badge { display: none; }
  main { padding-top: 24px; }
  .intro { align-items: stretch; flex-direction: column; gap: 17px; }
  .intro > div:first-child > p:last-child { font-size: .96rem; }
  .formula-chip { min-width: 0; }
  .calculator-card, .result-card, .reference-card { padding: 20px 17px; border-radius: 20px; }
  .form-actions { flex-direction: column; }
  .secondary-button { min-height: 46px; }
  .result-value-row { align-items: flex-start; flex-direction: column; gap: 12px; }
  .result-details > div { grid-template-columns: 1fr; gap: 3px; }
  .result-details dd { text-align: left; }
  .reference-grid, .safety-grid { grid-template-columns: 1fr; }
  .reference-item { min-height: 118px; }
  footer { align-items: flex-start; flex-direction: column; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e9f3f5;
    --muted: #aec2c7;
    --deep: #a9edf0;
    --teal: #65d2d0;
    --teal-soft: #163f43;
    --blue-soft: #173944;
    --line: #35535a;
    --paper: #122d34;
    --canvas: #0a2026;
    --shadow: 0 20px 50px rgba(0, 0, 0, .18);
  }
  body { background: radial-gradient(circle at 90% 0%, rgba(8,127,131,.18), transparent 30rem), linear-gradient(180deg,#0c252c 0,var(--canvas) 34rem); }
  .brand { color: var(--ink); }
  .calculator-card, .result-card, .reference-card, .safety-grid > article, .safety-grid > details { background: rgba(16, 43, 50, .96); border-color: #35535a; }
  .result-card { background: linear-gradient(155deg, rgba(16,43,50,.98), rgba(11,36,43,.98)); }
  .primary-button, .step-number { background: #0f5363; color: #fff; }
  .input-wrap, .input-wrap:focus-within, .result-details, .reference-item { background: #0d272e; }
  .input-wrap b { background: #14343c; }
  .result-hero { background: #0f5363; }
  .install-button, .secondary-button { background: #12323a; color: var(--ink); }
  .install-help { background: #12393e; border-color: #2b6063; }
  .clinical-note { background: rgba(94,66,22,.5); color: #ffe1a6; }
}
