/* ============================================================
   Medication Safety Digital Twin — Stylesheet
   Palette KSM: Viola #7B5EA7 | Teal #4ECDC4 | Lavanda #E8D5F5
   ============================================================ */

:root {
  --viola:      #7B5EA7;
  --viola-dark: #5a4280;
  --viola-light:#9b7ec7;
  --teal:       #4ECDC4;
  --teal-dark:  #35b5ac;
  --lavanda:    #E8D5F5;
  --lavanda-mid:#d0b0ef;
  --bianco:     #FFFFFF;
  --grigio-bg:  #F8F7FB;
  --grigio-card:#FFFFFF;
  --testo:      #2D2D2D;
  --testo-light:#666677;
  --bordo:      #E2E0EA;
  --ok:         #27AE60;
  --attenzione: #F39C12;
  --pericolo:   #E74C3C;
  --critico:    #8B0000;
  --shadow:     0 2px 12px rgba(123,94,167,0.10);
  --shadow-lg:  0 8px 32px rgba(123,94,167,0.18);
  --radius:     12px;
  --radius-sm:  8px;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--grigio-bg);
  color: var(--testo);
  font-size: 15px;
  line-height: 1.6;
}

/* ---- HEADER ---- */
.header {
  background: linear-gradient(135deg, var(--viola) 0%, var(--teal) 100%);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-logo { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.header-logo img { height: 56px; }
.header-logo-text { color: white; }
.header-logo-text .brand { font-size: 15px; font-weight: 700; letter-spacing: 0.5px; }
.header-logo-text .tagline { font-size: 10px; opacity: 0.85; }
.header-nav { display: flex; align-items: center; gap: 8px; }
.header-nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.header-nav a:hover, .header-nav a.active { background: rgba(255,255,255,0.2); color: white; }

/* ---- SIDEBAR ---- */
.layout { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid var(--bordo);
  padding: 1.5rem 0;
  flex-shrink: 0;
}
.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--testo-light);
  padding: 0 1.2rem;
  margin-bottom: 4px;
}
.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 1.2rem;
  text-decoration: none;
  color: var(--testo);
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: var(--transition);
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--lavanda); color: var(--viola); }
.sidebar a.active { background: var(--lavanda); color: var(--viola); border-left-color: var(--viola); }
.sidebar a .icon { width: 18px; text-align: center; font-size: 16px; }

/* ---- MAIN CONTENT ---- */
.main { flex: 1; padding: 2rem; max-width: 1200px; }

/* ---- INTERACTION BADGE ---- */
.interaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 24px;
  font-weight: 700;
  font-size: 14px;
  background: var(--grigio-bg);
  border: 2px solid var(--bordo);
}
.interaction-badge.sev-0 { background: #eafaf1; border-color: var(--ok); color: var(--ok); }
.interaction-badge.sev-1 { background: #eafaf1; border-color: var(--ok); color: var(--ok); }
.interaction-badge.sev-2 { background: #fef9e7; border-color: var(--attenzione); color: #b7770d; }
.interaction-badge.sev-3 { background: #fdf2f2; border-color: var(--pericolo); color: var(--pericolo); }
.interaction-badge.sev-4 { background: #f5e0e0; border-color: var(--critico); color: var(--critico); }

/* ---- CARDS ---- */
.card {
  background: var(--grigio-card);
  border: 1px solid var(--bordo);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--bordo);
}
.card-title { font-size: 16px; font-weight: 700; color: var(--viola); }

/* ---- DRUG LIST ---- */
.drug-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--bordo);
}
.drug-item:last-child { border-bottom: none; }
.drug-name { font-weight: 600; font-size: 15px; }
.drug-dose { font-size: 13px; color: var(--testo-light); }
.drug-times { display: flex; gap: 6px; flex-wrap: wrap; }
.drug-time-chip {
  background: var(--lavanda);
  color: var(--viola);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* ---- BLISTER ---- */
.blister-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 28px);
  gap: 5px;
  margin: 1rem 0;
}
.blister-pill {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--viola-light);
  background: var(--lavanda);
  cursor: pointer;
  transition: var(--transition);
}
.blister-pill.taken { background: var(--viola); border-color: var(--viola-dark); }
.blister-pill.empty { background: #eee; border-color: #ddd; cursor: default; }
.blister-progress {
  height: 8px;
  background: var(--lavanda);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.blister-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--viola), var(--teal));
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ---- INTERAZIONE CARD ---- */
.interaction-item {
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  border-left: 4px solid var(--bordo);
}
.interaction-item.sev-1 { background: #eafaf1; border-left-color: var(--ok); }
.interaction-item.sev-2 { background: #fef9e7; border-left-color: var(--attenzione); }
.interaction-item.sev-3 { background: #fdf2f2; border-left-color: var(--pericolo); }
.interaction-item.sev-4 { background: #f5e0e0; border-left-color: var(--critico); }
.interaction-drugs { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.interaction-desc { font-size: 13px; color: var(--testo-light); }
.interaction-badge-small {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
}
.interaction-badge-small.sev-1 { background: var(--ok); color: white; }
.interaction-badge-small.sev-2 { background: var(--attenzione); color: white; }
.interaction-badge-small.sev-3 { background: var(--pericolo); color: white; }
.interaction-badge-small.sev-4 { background: var(--critico); color: white; }

/* ---- FORM ---- */
.form-group { margin-bottom: 1.2rem; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--testo); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--bordo);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: white;
  transition: var(--transition);
  outline: none;
  color: var(--testo);
}
.form-control:focus { border-color: var(--viola); box-shadow: 0 0 0 3px rgba(123,94,167,0.12); }
.form-control::placeholder { color: #bbb; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
}
.btn-primary { background: var(--viola); color: white; }
.btn-primary:hover { background: var(--viola-dark); box-shadow: var(--shadow); }
.btn-teal { background: var(--teal); color: white; }
.btn-teal:hover { background: var(--teal-dark); }
.btn-outline { background: white; color: var(--viola); border: 2px solid var(--viola); }
.btn-outline:hover { background: var(--lavanda); }
.btn-danger { background: var(--pericolo); color: white; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 32px; font-size: 16px; border-radius: 32px; }
.btn-full { width: 100%; justify-content: center; }

/* ---- OCR UPLOAD ---- */
.ocr-drop {
  border: 2.5px dashed var(--viola-light);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--lavanda);
}
.ocr-drop:hover, .ocr-drop.dragover {
  border-color: var(--viola);
  background: #dfc9f5;
}
.ocr-drop-icon { font-size: 48px; margin-bottom: 12px; }
.ocr-drop-text { color: var(--viola); font-weight: 600; }
.ocr-drop-sub { color: var(--testo-light); font-size: 13px; margin-top: 4px; }

/* ---- OCR RESULTS ---- */
.ocr-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1.5px solid var(--bordo);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: white;
}
.ocr-result-item.found { border-color: var(--teal); }
.ocr-result-item.not-found { border-color: var(--attenzione); background: #fef9e7; }
.ocr-confidence {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--lavanda);
  color: var(--viola);
}

/* ---- DASHBOARD STATS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: white;
  border: 1px solid var(--bordo);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-number { font-size: 32px; font-weight: 800; color: var(--viola); }
.stat-label { font-size: 12px; color: var(--testo-light); margin-top: 4px; }

/* ---- TIMESTAMP BADGE ---- */
.ots-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--testo-light);
  background: #f0f0f0;
  padding: 3px 8px;
  border-radius: 10px;
}
.ots-badge::before { content: '⛓'; font-size: 10px; }

/* ---- ALERT ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: #eafaf1; color: #1a7a40; border: 1px solid #a9dfbf; }
.alert-warning { background: #fef9e7; color: #8a6000; border: 1px solid #f9e4a0; }
.alert-danger  { background: #fdf2f2; color: #a93226; border: 1px solid #f5b7b1; }
.alert-info    { background: #eaf3fb; color: #1a5276; border: 1px solid #a9cce3; }

/* ---- AUTOCOMPLETE ---- */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1.5px solid var(--viola-light);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--bordo);
  transition: var(--transition);
}
.autocomplete-item:hover, .autocomplete-item.selected {
  background: var(--lavanda);
  color: var(--viola);
}
.autocomplete-item .drug-generic { font-size: 12px; color: var(--testo-light); }

/* ---- PRICING CARDS ---- */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin: 2rem 0;
}
.pricing-card {
  background: white;
  border: 2px solid var(--bordo);
  border-radius: var(--radius);
  padding: 1.8rem 1.5rem;
  text-align: center;
  transition: var(--transition);
}
.pricing-card:hover, .pricing-card.featured {
  border-color: var(--viola);
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}
.pricing-card.featured { background: linear-gradient(160deg, var(--lavanda), white); }
.pricing-name { font-size: 16px; font-weight: 700; color: var(--viola); margin-bottom: 8px; }
.pricing-price { font-size: 36px; font-weight: 800; color: var(--testo); }
.pricing-price span { font-size: 16px; font-weight: 400; color: var(--testo-light); }
.pricing-features { list-style: none; text-align: left; margin: 1.2rem 0; }
.pricing-features li { padding: 5px 0; font-size: 13px; }
.pricing-features li::before { content: '✓  '; color: var(--teal); font-weight: 700; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .header-logo-text .tagline { display: none; }
}

/* ---- LOGIN PAGE ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--viola) 0%, var(--teal) 100%);
  padding: 2rem;
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo img { height: 52px; }
.login-title { font-size: 22px; font-weight: 800; color: var(--viola); margin: 10px 0 4px; }
.login-sub { font-size: 13px; color: var(--testo-light); }

/* ---- UTILITY ---- */
.text-viola { color: var(--viola); }
.text-teal  { color: var(--teal); }
.text-muted { color: var(--testo-light); }
.fw-bold    { font-weight: 700; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.d-none { display: none; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--lavanda);
  border-top-color: var(--viola);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 1rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
