:root{
  --bg:#05060a;
  --card:#0b0d16;
  --card2:#101320;
  --border:#252a3e;
  --accent:#ffb347;
  --text:#f5f5ff;
  --muted:#a0a4c0;
  --bad:#ff4d6b;
  --ok:#4fd37a;
  --input:#090b12;
}

*{box-sizing:border-box}

body{
  margin:0;
  padding:18px 12px 36px;
  font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  background:radial-gradient(circle at top,#131629 0,#05060a 48%,#020308 100%);
  color:var(--text);
}

.shell{
  max-width:1180px;
  margin:0 auto;
}

.top{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
  margin-bottom:14px;
}

.back{
  text-decoration:none;
  border:1px solid var(--border);
  border-radius:999px;
  padding:8px 13px;
  color:var(--muted);
  background:rgba(0,0,0,.25);
  font-size:.85rem;
  white-space:nowrap;
}

h1{
  margin:0;
  font-size:clamp(1.7rem,3.5vw,2.5rem);
  letter-spacing:.02em;
}

.sub{
  margin:6px 0 0;
  color:var(--muted);
  font-size:.92rem;
  line-height:1.35;
}

.warning{
  border:1px solid rgba(255,179,71,.45);
  background:rgba(255,179,71,.09);
  color:#ffd9a1;
  border-radius:14px;
  padding:11px 13px;
  margin:14px 0;
  font-size:.86rem;
  line-height:1.4;
}

.tabs{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin:14px 0;
}

.tab{
  border:1px solid var(--border);
  border-radius:999px;
  background:#111421;
  color:var(--muted);
  padding:9px 13px;
  cursor:pointer;
  font-weight:750;
}

.tab.active{
  background:var(--accent);
  color:#211408;
  border-color:rgba(255,179,71,.9);
}

.panel{
  display:none;
}

.panel.active{
  display:block;
}

.grid{
  display:grid;
  grid-template-columns:1.1fr .9fr;
  gap:14px;
}

@media(max-width:900px){
  .grid{grid-template-columns:1fr}
  .top{flex-direction:column}
}

.card{
  background:linear-gradient(135deg,rgba(255,179,71,.08),transparent 55%),var(--card);
  border:1px solid var(--border);
  border-radius:18px;
  padding:16px;
  box-shadow:0 18px 40px rgba(0,0,0,.65);
}

.result-card{
  position:sticky;
  top:12px;
  align-self:start;
}

@media(max-width:900px){
  .result-card{position:static}
}

h2{
  margin:0 0 12px;
  color:var(--accent);
  font-size:.95rem;
  text-transform:uppercase;
  letter-spacing:.12em;
}

h3{
  margin:12px 0 6px;
  font-size:.95rem;
  color:#ffd9a1;
}

label{
  display:block;
  font-size:.78rem;
  color:var(--muted);
  margin:10px 0 5px;
}

input,
select{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  background:var(--input);
  color:var(--text);
  padding:10px 11px;
  font-size:1rem;
  outline:none;
}

input:focus,
select:focus{
  border-color:rgba(255,179,71,.75);
}

.row{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}

.row3{
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
  gap:10px;
}

@media(max-width:620px){
  .row,.row3{grid-template-columns:1fr}
}

.actions{
  display:flex;
  gap:9px;
  flex-wrap:wrap;
  margin-top:14px;
}

button{
  border:1px solid rgba(255,179,71,.8);
  border-radius:999px;
  background:#ffb347;
  color:#221509;
  padding:10px 16px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.09em;
  cursor:pointer;
}

button.secondary{
  background:#121523;
  color:var(--text);
  border-color:var(--border);
  box-shadow:none;
}

.result{
  background:var(--card2);
  border:1px solid var(--border);
  border-radius:15px;
  padding:14px;
  color:var(--muted);
  line-height:1.45;
}

.big{
  font-size:2rem;
  font-weight:900;
  color:var(--accent);
  line-height:1.1;
  margin:3px 0 10px;
}

.muted{
  color:var(--muted);
  font-size:.86rem;
  line-height:1.45;
}

.bad{
  color:var(--bad);
  font-weight:800;
}

.ok{
  color:var(--ok);
  font-weight:800;
}

.outputs{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(145px,1fr));
  gap:9px;
  margin-top:10px;
}

.outbox{
  border:1px solid var(--border);
  border-radius:13px;
  padding:10px;
  background:rgba(0,0,0,.2);
}

.outbox .v{
  font-size:1.25rem;
  color:var(--accent);
  font-weight:850;
}

.outbox .k{
  font-size:.74rem;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
}

.pillrow{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top:10px;
}

.pill{
  border:1px solid var(--border);
  border-radius:999px;
  padding:5px 9px;
  color:var(--muted);
  font-size:.76rem;
  background:rgba(0,0,0,.25);
}

.toolbar{
  display:grid;
  grid-template-columns:1fr 260px;
  gap:10px;
  margin-bottom:14px;
}

@media(max-width:700px){
  .toolbar{grid-template-columns:1fr}
}

.drug-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
  gap:12px;
}

.drug-card{
  background:linear-gradient(135deg,rgba(255,179,71,.07),transparent 55%),var(--card);
  border:1px solid var(--border);
  border-radius:17px;
  padding:14px;
  box-shadow:0 14px 32px rgba(0,0,0,.55);
}

.drug-card h3{
  margin:0 0 4px;
  color:var(--text);
  font-size:1.05rem;
}

.drug-category{
  color:var(--accent);
  font-size:.72rem;
  letter-spacing:.12em;
  text-transform:uppercase;
  margin-bottom:8px;
}

.drug-section{
  margin-top:9px;
  border-top:1px solid rgba(255,255,255,.06);
  padding-top:8px;
}

.drug-section b{
  color:#ffd9a1;
}

.drug-section ul{
  margin:6px 0 0 18px;
  padding:0;
  color:var(--muted);
  font-size:.84rem;
  line-height:1.4;
}

.drug-actions{
  margin-top:12px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.small-btn{
  padding:7px 10px;
  font-size:.72rem;
}

.mini{
  font-size:.76rem;
  color:var(--muted);
  line-height:1.35;
}

/* Header con logo */
.brand{
  display:flex;
  align-items:center;
  gap:16px;
}

.logo-wrap{
  width:86px;
  min-width:86px;
  filter:drop-shadow(0 0 16px rgba(255,179,71,.35));
}

.logo-wrap svg{
  width:100%;
  height:auto;
  display:block;
}

@media(max-width:620px){
  .brand{
    align-items:flex-start;
  }

  .logo-wrap{
    width:68px;
    min-width:68px;
  }
}

/* Migliorie consultazione farmaci */
.drug-grid{
  grid-template-columns:repeat(auto-fit,minmax(320px,1fr));
}

.drug-card{
  position:relative;
  overflow:hidden;
}

.drug-card::before{
  content:"";
  position:absolute;
  inset:-45%;
  background:radial-gradient(circle at top right,rgba(255,179,71,.12),transparent 60%);
  opacity:.75;
  pointer-events:none;
}

.drug-card > *{
  position:relative;
  z-index:1;
}

.drug-card:hover{
  border-color:rgba(255,179,71,.55);
  transform:translateY(-1px);
}

.drug-card h3{
  font-size:1.12rem;
  letter-spacing:.01em;
}

.drug-category{
  display:inline-flex;
  width:auto;
  border:1px solid rgba(255,179,71,.35);
  border-radius:999px;
  padding:4px 9px;
  background:rgba(255,179,71,.08);
}

.drug-section{
  background:rgba(0,0,0,.16);
  border:1px solid rgba(255,255,255,.05);
  border-radius:12px;
  padding:9px 10px;
  margin-top:9px;
}

.drug-section:first-of-type{
  border-top:1px solid rgba(255,255,255,.05);
}

.drug-actions{
  justify-content:flex-end;
}

.small-btn{
  border-color:rgba(255,179,71,.75);
}

.count-card{
  grid-column:1/-1;
  color:var(--muted);
  padding:11px 14px;
}

.count-card b{
  color:var(--accent);
}

.drug-details{
  margin-top:10px;
  border:1px solid rgba(255,255,255,.06);
  border-radius:13px;
  background:rgba(0,0,0,.18);
  overflow:hidden;
}

.drug-details summary{
  cursor:pointer;
  list-style:none;
  padding:10px 12px;
  color:#ffd9a1;
  font-weight:800;
  font-size:.86rem;
}

.drug-details summary::-webkit-details-marker{
  display:none;
}

.drug-details summary::after{
  content:"+";
  float:right;
  color:var(--accent);
  font-weight:900;
}

.drug-details[open] summary::after{
  content:"−";
}

.drug-details .drug-section{
  margin:0;
  border-left:0;
  border-right:0;
  border-bottom:0;
  border-radius:0;
  background:rgba(0,0,0,.12);
}

.drug-tools{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin:-4px 0 14px;
  padding:10px;
  border:1px solid rgba(255,255,255,.06);
  border-radius:14px;
  background:rgba(0,0,0,.18);
}

.drug-tools .small-btn{
  margin:0;
}

.table-wrap{
  width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  border:1px solid rgba(255,255,255,.06);
  border-radius:12px;
  background:rgba(0,0,0,.18);
}

.mini-table{
  width:100%;
  min-width:820px;
  border-collapse:separate;
  border-spacing:0;
  font-size:.82rem;
}

.mini-table th,
.mini-table td{
  border-bottom:1px solid rgba(255,255,255,.07);
  padding:9px 10px;
  vertical-align:top;
  text-align:left;
}

.mini-table th{
  position:sticky;
  top:0;
  background:#111421;
  color:var(--accent);
  z-index:1;
  white-space:nowrap;
}

.mini-table td{
  color:var(--muted);
  line-height:1.35;
}

.heparin-table th:nth-child(1),
.heparin-table td:nth-child(1),
.heparin-table th:nth-child(2),
.heparin-table td:nth-child(2),
.heparin-table th:nth-child(3),
.heparin-table td:nth-child(3){
  white-space:nowrap;
  width:110px;
}

.heparin-table th:nth-child(4),
.heparin-table td:nth-child(4){
  min-width:280px;
  color:var(--text);
}

.heparin-table th:nth-child(5),
.heparin-table td:nth-child(5){
  min-width:160px;
}

@media(max-width:700px){
  .mini-table{
    min-width:900px;
    font-size:.78rem;
  }

  .mini-table th,
  .mini-table td{
    padding:8px;
  }
}
/* NOAC checkbox grid */
.check-grid{
  display:grid;
  grid-template-columns:1fr;
  gap:8px;
  margin:8px 0 10px;
}

.check-grid label{
  display:flex;
  align-items:center;
  gap:9px;
  margin:0;
  padding:8px 10px;
  border:1px solid rgba(255,255,255,.06);
  border-radius:12px;
  background:rgba(0,0,0,.16);
  color:var(--muted);
  font-size:.82rem;
  line-height:1.25;
  cursor:pointer;
}

.check-grid input[type="checkbox"]{
  width:16px;
  min-width:16px;
  height:16px;
  margin:0;
  padding:0;
  accent-color:var(--accent);
}

.check-grid label:hover{
  border-color:rgba(255,179,71,.45);
  color:var(--text);
}

/* NOAC help tooltip */
.help-label{
  display:flex;
  align-items:center;
  gap:7px;
  position:relative;
  width:max-content;
  max-width:100%;
}

.help-dot{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:18px;
  height:18px;
  min-width:18px;
  border-radius:50%;
  background:var(--accent);
  color:#fff;
  font-weight:900;
  font-size:.78rem;
  line-height:1;
  cursor:help;
  position:relative;
  box-shadow:0 0 10px rgba(255,179,71,.35);
}

.help-pop{
  display:block;
  position:absolute;
  left:50%;
  top:26px;
  transform:translateX(-50%) translateY(-4px);
  width:min(520px, calc(100vw - 36px));
  max-height:430px;
  overflow:auto;
  z-index:9999;
  opacity:0;
  visibility:hidden;
  pointer-events:none;
  padding:13px 14px;
  border:1px solid rgba(255,179,71,.55);
  border-radius:14px;
  background:#101320;
  color:var(--text);
  font-size:.78rem;
  font-weight:500;
  line-height:1.42;
  box-shadow:0 18px 46px rgba(0,0,0,.78), 0 0 18px rgba(255,179,71,.18);
  transition:opacity .12s ease, transform .12s ease, visibility .12s ease;
}

.help-dot:hover .help-pop,
.help-dot:focus-within .help-pop{
  opacity:1;
  visibility:visible;
  pointer-events:auto;
  transform:translateX(-50%) translateY(0);
}

.help-pop b{
  color:#ffd9a1;
}

.help-pop::-webkit-scrollbar{
  width:8px;
}

.help-pop::-webkit-scrollbar-thumb{
  background:rgba(255,179,71,.45);
  border-radius:999px;
}

@media(max-width:700px){
  .help-pop{
    left:0;
    transform:translateX(-12px) translateY(-4px);
  }

  .help-dot:hover .help-pop,
  .help-dot:focus-within .help-pop{
    transform:translateX(-12px) translateY(0);
  }
}

/* Protocolli: textarea e file input */
textarea{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  background:var(--input);
  color:var(--text);
  padding:10px 11px;
  font-size:1rem;
  line-height:1.35;
  outline:none;
  resize:vertical;
  min-height:92px;
  font-family:inherit;
}

textarea:focus{
  border-color:rgba(255,179,71,.75);
}

input[type="file"]{
  background:var(--input);
  color:var(--muted);
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px;
  cursor:pointer;
}

input[type="file"]::file-selector-button{
  border:1px solid rgba(255,179,71,.75);
  border-radius:999px;
  background:#ffb347;
  color:#221509;
  padding:8px 12px;
  margin-right:10px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.06em;
  cursor:pointer;
}

input[type="file"]::file-selector-button:hover{
  filter:brightness(1.05);
}

/* Protocolli: bottoni compatti coerenti */
#protoUploadBtn,
#protoResetFormBtn,
input[type="file"]::file-selector-button{
  font-family:inherit;
  font-size:.72rem;
  padding:7px 10px;
  letter-spacing:.09em;
}

#protoFiles{
  font-size:.86rem;
}
/* Protocolli: normalizzazione definitiva bottoni */
#protocols button,
#protocols .small-btn,
#protocols .back.small-btn,
#protocols input[type="file"]::file-selector-button{
  font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;
  font-size:.72rem !important;
  font-weight:800 !important;
  line-height:1.2 !important;
  text-transform:uppercase !important;
  letter-spacing:.09em !important;
  padding:7px 10px !important;
}

#protocols input[type="file"]{
  font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;
  font-size:.86rem !important;
  line-height:1.2 !important;
}
