/* ═══════════════════════════════════════════════════════
   LAYOUT — viste, KPI, tabelle, modali, grid
   ═══════════════════════════════════════════════════════ */

/* APP SHELL */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--topbar-h);
  flex-wrap: wrap;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 8px rgba(28,49,68,.18);
}
.topbar-brand { font-size: 20px; font-weight: 800; letter-spacing: .01em; white-space: nowrap; }
.topbar-sub { color: rgba(255,255,255,.68); font-weight: 700; white-space: nowrap; }
.topbar-divider { width: 1px; height: 26px; background: rgba(255,255,255,.18); flex: 0 0 auto; }
.topbar-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; min-width: 0; max-width: 100%; flex: 0 0 auto; }
.topbar-tab {
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255,255,255,.66);
  padding: 8px 7px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.topbar-tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.topbar-tab.active {
  color: #fff;
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.18);
}
.topbar-right { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 100%; flex: 0 0 auto; }
.topbar .topbar-btn { padding: 8px 10px; font-size: 12px; }
.main-content { max-width: 1280px; margin: 0 auto; padding: 28px 24px 44px; }
.view-panel { display: none; }
.view-panel.active { display: block; }
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

/* BUTTONS */
.btn-primary,
.btn-ghost,
.act-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--blue-mid); transform: translateY(-1px); }
.btn-ghost,
.act-btn { background: var(--bg2); color: var(--text2); border-color: var(--border2); }
.btn-ghost:hover,
.act-btn:hover { color: var(--blue); border-color: var(--blue); }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* DASHBOARD */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--kpi-color, var(--blue));
}
.kpi-card .kpi-value { color: var(--kpi-color, var(--blue)); }
.kpi-sub-text { font-size: 11px; color: var(--text2); margin-top: 5px; font-weight: 700; }

/* CARDS + LISTS */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--blue-xpale);
}
.card-title { font-size: 14px; font-weight: 800; color: var(--text); }
.empty-state { padding: 24px; text-align: center; color: var(--text3); font-weight: 700; }
.appt-list { display: flex; flex-direction: column; }
.appt-row {
  display: grid;
  grid-template-columns: 5px 86px minmax(180px, 1fr) 160px auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.appt-row:last-child { border-bottom: none; }
.appt-row:hover { background: var(--blue-xpale); }
.appt-color-bar { align-self: stretch; border-radius: 4px; }
.appt-start { display: block; font-weight: 800; color: var(--text); }
.appt-dur { display: block; font-size: 11px; color: var(--text3); font-weight: 700; }
.appt-service { font-weight: 800; }
.appt-clients, .appt-op { color: var(--text2); font-weight: 700; font-size: 12px; }
.status-pill, .role-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border2);
  background: var(--blue-xpale);
  color: var(--text);
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.status-fatto { background: var(--green-pale); color: var(--green); border-color: #bfe3cd; }
.status-annullato, .status-noshow { background: var(--red-pale); color: var(--red); border-color: #efc2bc; }
.circuit-badge { margin-left: 6px; font-size: 11px; font-weight: 800; color: var(--text3); }

/* VIEWS */
.view { display: none; }
.view.active { display: block; }
.main { margin-top: 60px; padding: 32px; max-width: 1200px; margin-left: auto; margin-right: auto; margin-top: 60px; }

/* LOGIN */


/* KPI STRIP */
.kpi-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.kpi {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--kc, var(--kpi-color, var(--blue))); }
.kpi-label { font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--kpi-color, var(--blue)); line-height: 1; }
.kpi-sub   { font-size: 11px; color: var(--text2); margin-top: 5px; font-weight: 600; }

/* TOOLBAR */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar-search {
  flex: 1; min-width: 200px; background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 9px 14px; font-size: 14px;
  font-family: 'Nunito', sans-serif; color: var(--text); outline: none;
}
.toolbar-search:focus { border-color: var(--blue-mid); box-shadow: 0 0 0 3px rgba(28,49,68,.08); }
.filter-btn {
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 700;
  cursor: pointer; border: 1px solid var(--border2); background: var(--bg2);
  color: var(--text2); font-family: 'Nunito', sans-serif; transition: all .15s;
  white-space: nowrap;
}
.filter-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.filter-btn:hover:not(.active) { border-color: var(--blue); color: var(--blue); }

/* TABLE */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-head { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 160px; background: var(--blue-xpale); border-bottom: 1px solid var(--border); }
.th { padding: 11px 14px; font-size: 10px; font-weight: 800; color: var(--text3); text-transform: uppercase; letter-spacing: .08em; }
.table-row {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 160px;
  border-bottom: 1px solid var(--border); align-items: center;
  transition: background .12s; cursor: pointer;
}
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: var(--blue-xpale); }
.td { padding: 11px 14px; font-size: 13px; }
.client-name { font-weight: 700; color: var(--text); font-size: 14px; }
.client-sub { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* MODALI */
.mo {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.45);
}
.mo.open { display: flex; }
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border-radius: var(--radius); width: 520px; max-width: 96vw;
  max-height: min(90vh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { width: min(1080px, 96vw); }
.mhead {
  background: var(--blue);
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
}
.mtitle { font-size: 16px; font-weight: 800; color: #fff; }
.mclose {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.mclose:hover { color: #fff; }
.mbody {
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
}
.mfoot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg2);
  flex: 0 0 auto;
}
.modal-head {
  background: var(--blue); padding: 20px 24px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 800; color: #fff; }
.modal-close { background: none; border: none; color: rgba(255,255,255,.7); font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: #fff; }
.modal-body { padding: 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--bg2); position: sticky; bottom: 0; }

/* GRID HELPERS */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

#mo-esercizio .mbody > .g2 { grid-template-columns: minmax(300px, 1fr) minmax(360px, 1fr); }
@media (max-width: 820px) {
  #mo-esercizio .mbody > .g2 { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topbar { align-items: stretch; height: auto; min-height: var(--topbar-h); flex-wrap: wrap; padding: 12px 16px; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
}

@media (max-width: 720px) {
  .main-content { padding: 22px 14px 36px; }
  .view-header { flex-direction: column; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .appt-row { grid-template-columns: 5px 64px minmax(0, 1fr); }
  .appt-op, .appt-status { grid-column: 3; }
}

/* SECTION TITLE (old .sec-title) */
.sec-title {
  font-size: 10px; font-weight: 800; color: var(--blue); text-transform: uppercase;
  letter-spacing: .1em; margin: 20px 0 12px; padding-bottom: 8px;
  border-bottom: 2px solid var(--blue-pale);
}

/* MISURE BOX (old names) */
.mis-box {
  background: var(--blue-xpale); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 14px 16px; text-align: center;
}
.mis-val   { font-size: 24px; font-weight: 800; color: var(--blue); line-height: 1; }
.mis-unit  { font-size: 11px; color: var(--text3); font-weight: 600; margin-top: 2px; }
.mis-label { font-size: 10px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; margin-top: 6px; }

/* DATI GRID (old names) */
.dati-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.dati-item { padding: 10px 14px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.dati-item:nth-child(3n) { border-right: none; }
.dati-item:last-child { border-bottom: none; }
.dati-label { font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.dati-val   { font-size: 13px; font-weight: 700; color: var(--text); }
.dati-val.empty { color: var(--text3); font-style: italic; font-weight: 500; }

/* ESERCIZIO CARD (old names .eserc-*) */
.eserc-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.eserc-cat-hd { padding: 6px 14px; font-size: 10px; font-weight: 800; color: var(--blue); text-transform: uppercase; letter-spacing: .08em; background: var(--blue-xpale); border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.eserc-row { padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); transition: background .12s; display: flex; align-items: center; justify-content: space-between; }
.eserc-row:hover { background: var(--blue-xpale); }
.eserc-row.sel { background: var(--blue-pale); font-weight: 800; }
.eserc-head { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 11px 14px; background: var(--blue-xpale); border-bottom: 1px solid var(--border); cursor: pointer; }
.eserc-num  { width: 26px; height: 26px; background: var(--blue); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; flex-shrink: 0; }
.eserc-nome { font-size: 14px; font-weight: 800; color: var(--text); }
.eserc-cat  { font-size: 11px; color: var(--text3); font-weight: 600; margin-top: 2px; }
.eserc-prog { font-size: 10px; font-weight: 700; background: var(--gold-pale); color: #8a6210; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.eserc-body { padding: 14px; }
