:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-light: #ccfbf1;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-line: #fecaca;
  --amber: #d97706;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}

body { padding-bottom: 140px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--teal);
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(13, 148, 136, .25);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.logo-img { width: 40px; height: 40px; border-radius: 10px; display: block; flex: none; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.app-header h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.tagline { margin: 0; font-size: 12px; opacity: .85; font-weight: 500; }
.reset-btn {
  background: rgba(255, 255, 255, .18);
  border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
}
.reset-btn:active { background: rgba(255, 255, 255, .3); }

/* Layout */
.app-main { padding: 16px; max-width: 720px; margin: 0 auto; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px; font-size: 16px; font-weight: 700;
}
.step-num {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--teal-light); color: var(--teal-dark);
  font-size: 14px; font-weight: 800; flex: none;
}
.redflag-card .step-num { background: var(--red-bg); color: var(--red); }
.hint { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }

/* Patient */
.patient-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field:first-child { grid-column: 1 / -1; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.age-row { display: flex; gap: 8px; }
input, select {
  font: inherit; padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--teal); }
#ageValue { flex: 1; }
#ageUnit { width: 110px; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 11px; border: 1.5px solid var(--line);
  background: #fff; border-radius: 12px; font-weight: 700;
  color: var(--muted); cursor: pointer;
}
.seg button.active { background: var(--teal); border-color: var(--teal); color: #fff; }

/* Search */
.search {
  margin-bottom: 14px;
  background: var(--bg); border-color: transparent;
}

/* Symptom groups */
.sym-group { margin-bottom: 16px; }
.sym-group:last-child { margin-bottom: 0; }
.sym-group h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fff;
  font-size: 14px; font-weight: 500; color: var(--ink);
  cursor: pointer; user-select: none;
  transition: transform .05s ease;
}
.chip .ico { font-size: 15px; }
.chip:active { transform: scale(.96); }
.chip.on {
  background: var(--teal); border-color: var(--teal); color: #fff;
}
.redflag-chips .chip.on {
  background: var(--red); border-color: var(--red); color: #fff;
}
.redflag-chips .chip { border-color: var(--red-line); }

/* Alert banner */
.alert-banner {
  position: fixed; left: 12px; right: 12px;
  bottom: 96px; z-index: 40;
  background: var(--red); color: #fff;
  border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 8px 30px rgba(220, 38, 38, .4);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: translateY(12px); opacity: 0; } }
.alert-banner { cursor: pointer; padding-right: 40px; }
.alert-banner h4 { margin: 0 0 6px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.alert-banner ul { margin: 6px 0 0; padding-left: 20px; font-size: 13.5px; }
.alert-banner.hidden { display: none; }
.alert-close {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.22); color: #fff;
  font-size: 15px; cursor: pointer; display: grid; place-items: center;
}
.alert-close:active { background: rgba(255,255,255,.4); }
.alert-hint { margin: 8px 0 0; font-size: 11px; opacity: .8; text-align: right; }

/* Results panel (bottom sheet) */
.results-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  background: #fff; border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 30px rgba(15, 23, 42, .15);
  max-height: 80vh; display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.results-handle {
  width: 100%; border: none; background: transparent;
  padding: 16px 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 700; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.results-handle::before {
  content: ""; position: absolute; top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 2px; background: var(--line);
}
.results-handle { position: relative; }
.chev { transition: transform .25s ease; color: var(--muted); }
.results-panel.collapsed .chev { transform: rotate(-180deg); }
.results-body {
  overflow-y: auto; padding: 8px 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.results-panel.collapsed .results-body { display: none; }

/* Diagnosis cards */
.dx {
  border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-top: 12px;
}
.dx.top { border-color: var(--teal); background: #f0fdfa; }
.dx-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.dx-name { font-weight: 700; font-size: 15.5px; }
.dx-score { font-weight: 800; font-size: 15px; color: var(--teal-dark); white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--bg); margin: 10px 0 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), #2dd4bf); border-radius: 4px; }
.dx-note { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.dx-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px;
  background: var(--bg); color: var(--muted);
}
.tag.match { background: var(--teal-light); color: var(--teal-dark); }
.tag.season { background: #fef3c7; color: #b45309; }
.tag.age { background: #e0e7ff; color: #4338ca; }
.tag.rf { background: var(--red-bg); color: var(--red); }

/* Section headers within results */
.section-head {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 18px 0 4px; padding-top: 4px;
}
.section-head:first-child { margin-top: 6px; }
.section-head.danger { color: var(--red); }

/* Barra compatta sezione gravi (collassata) */
.serious-toggle {
  width: 100%; margin: 12px 0 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border: 1.5px dashed var(--red-line);
  background: var(--red-bg); border-radius: 12px;
  font: inherit; font-size: 13.5px; color: var(--ink); cursor: pointer;
  text-align: left;
}
.serious-toggle:active { background: #fde2e2; }
.serious-toggle .st-left { display: flex; align-items: center; gap: 8px; }
.serious-toggle .st-crit {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--red);
  padding: 2px 7px; border-radius: 6px;
}
.serious-toggle .st-hint { font-size: 11.5px; color: var(--red); white-space: nowrap; font-weight: 600; }
.serious-toggle.inline {
  display: inline-flex; width: auto; margin: 0 0 0 8px; padding: 2px 8px;
  border-style: solid; font-size: 11px; font-weight: 700; vertical-align: middle;
}

/* Serious condition cards */
.dx.serious { border-left: 4px solid var(--amber); }
.dx.serious.sev-critica { border-left-color: var(--red); }
.dx.serious.escalated {
  border: 1px solid var(--red); border-left: 4px solid var(--red);
  background: var(--red-bg); box-shadow: 0 0 0 3px rgba(220,38,38,.08);
}
.dx.serious .dx-score { color: var(--muted); font-size: 13px; }

.sev {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .4px;
  padding: 2px 7px; border-radius: 6px; margin-right: 8px; vertical-align: middle;
}
.sev.crit { background: var(--red); color: #fff; }
.sev.high { background: #fef3c7; color: #b45309; }

.disc-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 6px; }
.disc-list { display: flex; flex-direction: column; gap: 6px; }
.disc-item {
  display: flex; align-items: flex-start; gap: 8px; text-align: left;
  width: 100%; padding: 9px 11px; border: 1.5px solid var(--line);
  border-radius: 10px; background: #fff; font: inherit; font-size: 13px;
  color: var(--ink); cursor: pointer; line-height: 1.35;
}
.disc-item .tick {
  flex: none; width: 18px; height: 18px; border-radius: 5px;
  border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff; margin-top: 1px;
}
.disc-item.on { border-color: var(--red); background: var(--red-bg); font-weight: 600; }
.disc-item.on .tick { background: var(--red); border-color: var(--red); }

.dx-action {
  font-size: 12.5px; font-weight: 600; color: var(--teal-dark);
  background: var(--teal-light); border-radius: 8px; padding: 7px 10px; margin: 10px 0 0;
}
.dx.serious.escalated .dx-action { color: var(--red); background: #fee2e2; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }
.empty.small { padding: 12px 10px; font-size: 13px; }
.no-result {
  background: var(--bg); border-radius: 12px; padding: 14px 16px;
  font-size: 13px; color: var(--muted); line-height: 1.5; margin: 4px 0 0;
}
.no-result strong { color: var(--ink); }
/* evidenzia la card red flag quando il match della ricerca è lì */
.redflag-card.search-hit { box-shadow: 0 0 0 2px var(--red), var(--shadow); }

/* Disclaimer */
.disclaimer {
  font-size: 11.5px; color: var(--muted); line-height: 1.5;
  padding: 18px 18px 24px; max-width: 720px; margin: 0 auto;
  text-align: center;
}
.disclaimer p { margin: 0; }
.disclaimer strong { color: var(--ink); }
.disclaimer .credit {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: #94a3b8; letter-spacing: .2px;
}

@media (min-width: 640px) {
  .results-panel { left: auto; right: 16px; bottom: 16px; width: 380px; border-radius: 18px; }
  .alert-banner { left: auto; right: 16px; width: 380px; }
}
