/* ═══════════════════════════════════════════
   Farmaci Manager — Global Styles
   Design: accessibile, leggibile, mobile-first
   ═══════════════════════════════════════════ */

:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --warning:      #d97706;
  --warning-bg:   #fef3c7;
  --gray-50:      #f9fafb;
  --gray-100:     #f3f4f6;
  --gray-200:     #e5e7eb;
  --gray-400:     #9ca3af;
  --gray-600:     #4b5563;
  --gray-800:     #1f2937;
  --radius:       12px;
  --radius-lg:    18px;
  --shadow:       0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg:    0 4px 20px rgba(0,0,0,0.12);
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ────────────────────────────────── */
.header {
  background: var(--primary);
  color: white;
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow);
}
.header h1 { font-size: 1.15rem; font-weight: 600; }
.header .subtitle { font-size: 0.8rem; opacity: 0.85; }
.header-icon { font-size: 1.5rem; }

/* ── Nav tabs ──────────────────────────────── */
.tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex: 1;
  min-width: 80px;
  padding: 0.75rem 0.5rem;
  border: none;
  background: none;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-400);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Cards ─────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}
.card-subtitle {
  font-size: 0.8rem;
  color: var(--gray-400);
}

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--primary);  color: white; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success);  color: white; }
.btn-danger   { background: var(--danger);   color: white; }
.btn-ghost    { background: var(--gray-100); color: var(--gray-800); }
.btn-ghost:hover { background: var(--gray-200); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; display: flex; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }

/* ── Forms ─────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--gray-800);
  background: white;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.9rem center; padding-right: 2.5rem; }

/* ── Badge / Pill ──────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: var(--gray-100); color: var(--gray-600); }

/* ── Stat grid ─────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--gray-800); }
.stat-label { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.2rem; }

/* ── Lista farmaci / terapie ───────────────── */
.item-list { list-style: none; }
.item-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--gray-100);
}
.item-row:last-child { border-bottom: none; }
.item-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.item-icon.blue   { background: #dbeafe; }
.item-icon.green  { background: var(--success-bg); }
.item-icon.orange { background: var(--warning-bg); }
.item-icon.red    { background: var(--danger-bg); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta  { font-size: 0.78rem; color: var(--gray-400); margin-top: 0.1rem; }
.item-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* ── Astuccio griglia ──────────────────────── */
.astuccio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.astuccio-slot {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: 2px solid transparent;
  padding: 4px;
  text-align: center;
}
.astuccio-slot.vuoto    { background: var(--gray-100); color: var(--gray-400); }
.astuccio-slot.da-fare  { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.astuccio-slot.caricato { background: var(--success-bg); color: var(--success); border-color: #86efac; }
.astuccio-slot:hover { transform: scale(1.05); }

/* ── Modal ─────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: flex-end;
  opacity: 0; visibility: hidden;
  transition: all 0.25s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.25s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-handle {
  width: 40px; height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  margin: 0 auto 1rem;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }

/* ── Toast ─────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 1rem; left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex; flex-direction: column; gap: 0.5rem;
  align-items: center;
  width: 90%;
}
.toast {
  background: var(--gray-800);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Orario pills ──────────────────────────── */
.orari-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.orario-pill {
  background: #dbeafe;
  color: #1e40af;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex; align-items: center; gap: 0.3rem;
}
.orario-pill .remove {
  cursor: pointer; color: #1e40af; font-size: 1rem; line-height: 1;
  background: none; border: none;
}

/* ── Camera / OCR area ─────────────────────── */
.ocr-area {
  background: var(--gray-800);
  border-radius: var(--radius);
  aspect-ratio: 4/2.5;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.75rem;
  color: white; cursor: pointer;
  position: relative; overflow: hidden;
}
.ocr-area video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ocr-area canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ocr-icon { font-size: 2.5rem; position: relative; z-index: 1; }
.ocr-text { font-size: 0.85rem; position: relative; z-index: 1; }
.ocr-viewfinder {
  position: absolute; z-index: 2;
  width: 55%; height: 35%;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
}

/* ── Profilo paziente ──────────────────────── */
.profilo-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem;
}
.profilo-option {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.profilo-option.selected { border-color: var(--primary); background: #eff6ff; }
.profilo-option .icon { font-size: 2rem; display: block; margin-bottom: 0.4rem; }
.profilo-option .label { font-size: 0.85rem; font-weight: 600; }
.profilo-option .desc  { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.2rem; }

/* ── Empty state ───────────────────────────── */
.empty-state {
  text-align: center; padding: 2rem 1rem;
  color: var(--gray-400);
}
.empty-state .icon { font-size: 3rem; display: block; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* ── Loader ────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ─────────────────────────────── */
.container { padding: 0.75rem 1rem; max-width: 600px; margin: 0 auto; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 0.75rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.text-muted { color: var(--gray-400); }
.text-sm { font-size: 0.85rem; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Responsive ────────────────────────────── */
@media (max-width: 400px) {
  .stat-value { font-size: 1.5rem; }
  .astuccio-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Selettore giorni settimana ────────────── */
.giorno-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.8rem;
  height: 2.2rem;
  border-radius: 50px;
  border: 2px solid #e2e8f0;
  background: white;
  color: #94a3b8;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 0 0.5rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.giorno-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
  box-shadow: 0 2px 6px rgba(37,99,235,0.4);
}
.giorno-btn:not(.active) {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #94a3b8;
}
