/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* DipendenzePlus Brand Palette */
  --brand-dark:    #0B2E2A;
  --brand-primary: #0D9488;
  --brand-hover:   #14B8A6;
  --brand-accent:  #22C55E;
  --brand-ice:     #E6FFFB;
  --brand-cyan:    #ECFDF5;

  /* Semantic tokens */
  --bg:       #F1F5F4;
  --bg2:      #FFFFFF;
  --bg3:      #F5F7F6;
  --border:   #D6E0DD;
  --accent:   #0D9488;
  --accent2:  #14B8A6;
  --success:  #16a34a;
  --warning:  #d97706;
  --danger:   #dc2626;
  --text:     #0D1F1D;
  --text2:    #3D5652;
  --text3:    #7E9A94;

  --sidebar-w: 230px;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(11,46,42,.07);
  --shadow-md: 0 8px 32px rgba(11,46,42,.12);
  --shadow-lg: 0 24px 64px rgba(11,46,42,.18);
}

html, body {
  height: 100%;
  font-family: 'Ubuntu', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--brand-dark);
  display: flex; flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.nav-menu { list-style: none; padding: 12px 0; flex: 1; }
.nav-section-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 1.4px;
  text-transform: uppercase; color: rgba(255,255,255,.28);
  padding: 18px 18px 5px;
}
.nav-menu li a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.62);
  text-decoration: none;
  border-right: 2px solid transparent;
  transition: all .14s;
  font-size: 13.5px; font-weight: 400;
}
.nav-menu li a svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-menu li a:hover {
  color: rgba(255,255,255,.92);
  background: rgba(255,255,255,.07);
}
.nav-menu li a.active {
  color: #fff;
  background: rgba(13,148,136,.32);
  border-right-color: var(--brand-primary);
  font-weight: 500;
}

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name  { display: block; font-size: 12.5px; font-weight: 500; color: rgba(255,255,255,.88); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { display: block; font-size: 11px; color: rgba(255,255,255,.4); }
.logout-btn { color: rgba(255,255,255,.38); transition: color .14s; }
.logout-btn:hover { color: #f87171; }
.logout-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 32px 0;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.5px; color: var(--brand-dark); }
.date-badge {
  font-size: 12px; font-weight: 500;
  color: var(--brand-primary);
  background: var(--brand-ice);
  padding: 4px 14px; border-radius: 20px;
}
.content-body { padding: 20px 32px 40px; flex: 1; }

/* ===== CARDS ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 11px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: .8px;
  margin-bottom: 16px;
}

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text3); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -1px; color: var(--brand-dark); }
.stat-sub { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text3); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg3); }
.td-actions { display: flex; gap: 6px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 8px;
  font-size: 13px; font-weight: 500; font-family: inherit;
  border: none; cursor: pointer; transition: all .14s;
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary  { background: var(--brand-primary); color: #fff; }
.btn-primary:hover  { background: var(--brand-hover); }
.btn-secondary { background: var(--bg2); color: var(--text2); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--brand-primary); color: var(--brand-primary); background: var(--brand-ice); }
.btn-danger  { background: rgba(220,38,38,.09); color: #b91c1c; border: 1.5px solid rgba(220,38,38,.2); }
.btn-danger:hover  { background: rgba(220,38,38,.18); }
.btn-success { background: rgba(22,163,74,.09); color: #15803d; border: 1.5px solid rgba(22,163,74,.2); }
.btn-success:hover { background: rgba(22,163,74,.18); }
.btn-sm   { padding: 5px 12px; font-size: 12px; }
.btn-icon { padding: 6px; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1/-1; }
label { font-size: 12px; font-weight: 500; color: var(--text2); }
input, select, textarea {
  background: var(--bg3); border: 1.5px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; font-family: inherit;
  transition: border-color .14s, box-shadow .14s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.12);
  background: #fff;
}
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg2); }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
fieldset { border: none; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-blue   { background: var(--brand-ice);            color: var(--brand-primary); }
.badge-green  { background: rgba(22,163,74,.12);          color: #15803d; }
.badge-yellow { background: rgba(217,119,6,.12);          color: #b45309; }
.badge-red    { background: rgba(220,38,38,.12);          color: #b91c1c; }
.badge-gray   { background: var(--bg3); border: 1px solid var(--border); color: var(--text3); }
.badge-indigo { background: var(--brand-cyan);            color: var(--brand-accent); }

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-input {
  width: 240px;
  background: var(--bg2); border: 1.5px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(13,148,136,.1); }

/* ===== PAGE TABS (segmented control) ===== */
.page-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 3px;
  width: fit-content; margin-bottom: 22px;
}
.page-tab {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 20px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  color: var(--text2); text-decoration: none;
  transition: all .14s; cursor: pointer;
  border: none; background: none;
}
.page-tab svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.page-tab:hover { color: var(--text); }
.page-tab.active { background: #fff; color: var(--brand-primary); box-shadow: 0 1px 4px rgba(11,46,42,.1); font-weight: 600; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,46,42,.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: 18px; width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 32px 80px rgba(11,46,42,.22), 0 0 0 0.5px rgba(11,46,42,.06);
}
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1080px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 24px 0;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--brand-dark); }
.modal-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg3); border: none;
  color: var(--text3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; transition: all .14s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body   { padding: 20px 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 0 24px 22px; }

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 500; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
  transition: opacity .4s;
}
.alert-success { background: rgba(22,163,74,.1);  border: 1px solid rgba(22,163,74,.25); color: #15803d; }
.alert-error   { background: rgba(220,38,38,.1);  border: 1px solid rgba(220,38,38,.25); color: #b91c1c; }

/* ===== LOGIN ===== */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, var(--brand-dark) 0%, #113F39 55%, #0B2E2A 100%);
}
.login-card {
  background: #fff; border-radius: 20px;
  padding: 42px 38px; width: 100%; max-width: 390px;
  box-shadow: 0 40px 80px rgba(0,0,0,.32);
}
.login-logo { display: flex; justify-content: center; margin-bottom: 30px; }
.login-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: var(--brand-dark); }
.login-card p  { color: var(--text3); margin-bottom: 24px; font-size: 13px; }

/* ===== DASHBOARD GRID ===== */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

.dash-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
@media (max-width: 1100px) { .dash-kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .dash-kpi-grid { grid-template-columns: 1fr; } }

.dash-kpi-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-top: 3px solid var(--border);
  border-radius: 12px; padding: 18px 20px;
  box-shadow: var(--shadow);
}
.dash-kpi-name  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); margin-bottom: 8px; }
.dash-kpi-num   { font-size: 32px; font-weight: 700; letter-spacing: -1.5px; line-height: 1; color: var(--brand-dark); }
.dash-kpi-sub   { font-size: 11px; color: var(--text3); margin-top: 5px; }

/* ===== UTILITIES ===== */
.text-muted { color: var(--text3); }
.text-sm { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.font-mono { font-family: 'Ubuntu Mono', 'Courier New', monospace; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text3); font-size: 13px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===== SCHEDA OSPITE: header + tab ===== */
.ospite-hero {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.ospite-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--brand-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.ospite-hero-name { font-size: 18px; font-weight: 700; color: var(--brand-dark); }
.ospite-hero-sub  { font-size: 12px; color: var(--text3); margin-top: 2px; }
.ospite-hero-actions { margin-left: auto; display: flex; gap: 8px; }

/* ===== INFO TABLE (visualizzazione dati "a scheda") ===== */
.info-table { width: 100%; border-collapse: collapse; }
.info-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.info-table tr:last-child td { border-bottom: none; }
.info-table .info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text3); width: 220px; }
.info-table .info-value { font-size: 13.5px; color: var(--text); font-weight: 500; }

/* ===== SECTION HEADER (dentro una scheda lunga) ===== */
.section-hdr {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
  color: var(--brand-primary);
  padding-bottom: 6px; margin: 22px 0 12px;
  border-bottom: 2px solid var(--brand-ice);
}
.section-hdr:first-child { margin-top: 0; }

/* ===== CHECKLIST GRID (reati, documenti acquisiti, FASAS, ecc.) ===== */
.checklist-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 16px;
}
.check-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text2);
  padding: 4px 0; cursor: pointer;
}
.check-item input[type=checkbox] { width: auto; flex-shrink: 0; accent-color: var(--brand-primary); }

/* ===== HISTORY LIST (storico versioni domicilio/residenza/sociodemo) ===== */
.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.history-item {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 12.5px; color: var(--text2);
}
.history-date { font-size: 10.5px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.history-toggle { font-size: 12px; color: var(--brand-primary); cursor: pointer; text-decoration: underline; background: none; border: none; padding: 0; font-family: inherit; }

/* ===== SUBSTANCE TABLE (anamnesi sostanze) ===== */
.substance-row td { vertical-align: middle; }
.substance-name { font-weight: 600; }
.substance-flag-primaria { color: var(--brand-primary); font-weight: 700; }

/* ===== ROLE BADGE ===== */
.role-admin           { background: rgba(220,38,38,.12); color: #b91c1c; }
.role-medico          { background: rgba(13,148,136,.12); color: #0f766e; }
.role-psicologo       { background: rgba(99,102,241,.12); color: #4338ca; }
.role-educatore       { background: rgba(217,119,6,.12); color: #b45309; }
.role-amministrazione { background: var(--bg3); border: 1px solid var(--border); color: var(--text3); }
