/* RotaManager - foglio di stile unico */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2230;
  --muted: #6b7280;
  --line: #e2e5eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --err: #b91c1c;
  --err-soft: #fee2e2;
  --night: #312e81;
  --radius: 10px;
  --sidebar: 232px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.boot { padding: 3rem; color: var(--muted); }

/* ---------- layout ---------- */
#root { display: flex; min-height: 100vh; }

aside.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: #171a24;
  color: #c9cedb;
  padding: 1.1rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { font-size: 1.15rem; font-weight: 700; color: #fff; padding: 0 1.1rem 1rem; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; font-size: .74rem; color: #8b93a7; letter-spacing: 0; }
.nav-group { padding: .9rem 1.1rem .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6d7488; }
nav a {
  display: block; padding: .48rem 1.1rem; color: #c9cedb;
  text-decoration: none; border-left: 3px solid transparent; font-size: .9rem;
}
nav a:hover { background: #21242f; color: #fff; }
nav a.active { background: #21242f; color: #fff; border-left-color: var(--accent); font-weight: 600; }

main { flex: 1; padding: 1.6rem 1.9rem 4rem; max-width: 1500px; min-width: 0; }

header.page { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
header.page h1 { font-size: 1.35rem; margin: 0 0 .15rem; }
header.page p { margin: 0; color: var(--muted); font-size: .88rem; max-width: 70ch; }
header.page .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- pannelli ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem;
}
.panel > h2 { font-size: .98rem; margin: 0 0 .8rem; display: flex; align-items: center; gap: .5rem; }
.panel > h2 .actions { margin-left: auto; display: flex; gap: .4rem; }
.panel-note { color: var(--muted); font-size: .84rem; margin: -.4rem 0 .8rem; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1.1rem; }
.grid2 > .panel { margin-bottom: 0; }

/* ---------- tabelle ---------- */
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: left; padding: .48rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); font-style: italic; padding: .8rem .2rem; }

/* ---------- controlli ---------- */
button {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 7px; padding: .35rem .7rem; cursor: pointer;
}
button:hover { border-color: #c3c8d4; background: #f8f9fb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #4338ca; }
button.danger { color: var(--err); border-color: #f0c9c9; }
button.danger:hover { background: var(--err-soft); }
button.mini { padding: .12rem .42rem; font-size: .78rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; padding: .34rem .5rem; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 62px; resize: vertical; }

.field { margin-bottom: .7rem; }
.field > label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .18rem; font-weight: 600; }
.field .hint { font-size: .74rem; color: var(--muted); margin-top: .15rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.checklist {
  max-height: 148px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 7px; padding: .35rem .5rem;
}
.checklist label { display: flex; align-items: center; gap: .4rem; font-size: .86rem; padding: .1rem 0; }
.checklist input { width: auto; }
.inline-check { display: flex; align-items: center; gap: .45rem; }
.inline-check input { width: auto; }

/* ---------- badge e barre ---------- */
.badge {
  display: inline-block; padding: .08rem .45rem; border-radius: 6px;
  font-size: .74rem; font-weight: 600; background: var(--accent-soft); color: var(--accent);
  margin: 0 .25rem .15rem 0; white-space: nowrap;
}
.badge.grey { background: #eef0f4; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.night { background: #e0e7ff; color: var(--night); }

.bar { background: #eef0f4; border-radius: 999px; height: 8px; overflow: hidden; min-width: 90px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.over > span { background: var(--err); }
.bar.low > span { background: #94a3b8; }

.kpis { display: flex; gap: .9rem; flex-wrap: wrap; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .95rem; min-width: 140px; }
.kpi .v { font-size: 1.35rem; font-weight: 700; }
.kpi .l { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- griglia turni ---------- */
.week-grid { display: grid; gap: 3px; min-width: 900px; }
.week-grid .cell { background: #fbfcfe; border: 1px solid var(--line); border-radius: 7px; padding: .3rem; min-height: 62px; }
.week-grid .head { font-weight: 600; font-size: .78rem; color: var(--muted); padding: .25rem .3rem; text-transform: uppercase; letter-spacing: .04em; }
.week-grid .rowhead { font-weight: 600; font-size: .82rem; padding: .5rem .3rem; display: flex; flex-direction: column; gap: .1rem; }
.week-grid .rowhead small { color: var(--muted); font-weight: 400; }

.shift {
  display: block; border-radius: 5px; padding: .18rem .35rem; margin-bottom: 3px;
  font-size: .76rem; background: var(--accent-soft); border-left: 3px solid var(--accent);
  cursor: default;
}
.shift.night { background: #e0e7ff; border-left-color: var(--night); }
.shift.r2 { background: #ecfdf5; border-left-color: #059669; }
.shift.r3 { background: #fff7ed; border-left-color: #ea580c; }
.shift.r4 { background: #fdf2f8; border-left-color: #db2777; }
.shift b { font-weight: 600; }
.shift button.mini { float: right; margin: -.1rem -.2rem 0 .2rem; line-height: 1; }
.shift small { display: block; color: var(--muted); font-size: .72rem; }
.legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }

/* ---------- modale e toast ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 28, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50;
  overflow-y: auto;
}
.modal { background: var(--panel); border-radius: 12px; width: min(620px, 100%); padding: 1.2rem 1.3rem; box-shadow: 0 18px 45px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 .9rem; font-size: 1.05rem; }
.modal .buttons { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 90; }
.toast {
  background: #1f2330; color: #fff; padding: .55rem .9rem; border-radius: 8px;
  font-size: .86rem; box-shadow: 0 8px 24px rgba(0,0,0,.22); max-width: 380px;
}
.toast.err { background: #991b1b; }
.toast.ok { background: #166534; }

.spinner { color: var(--muted); font-size: .88rem; padding: .5rem 0; }
.row-flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-flex.end { justify-content: flex-end; }
.sep { height: 1px; background: var(--line); margin: .9rem 0; }
code.k { background: #f1f2f6; padding: .05rem .3rem; border-radius: 4px; font-size: .82rem; }

/* ---------- accesso ---------- */
.login-page {
  min-height: 100vh; width: 100%; display: flex; align-items: center;
  justify-content: center; background: #171a24; padding: 2rem 1rem;
}
.login-box {
  background: var(--panel); border-radius: 14px; padding: 1.6rem 1.7rem;
  width: min(380px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.login-box .brand { color: var(--ink); padding: 0 0 .6rem; }
.login-box .brand small { color: var(--muted); }
.login-error { color: var(--err); font-size: .84rem; min-height: 1.2em; margin: .2rem 0; }

/* ---------- ente corrente e piè di pagina della barra laterale ---------- */
.org-box { padding: 0 1.1rem .9rem; }
.org-box > label {
  display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: #6d7488; margin-bottom: .2rem;
}
.org-select, .org-current {
  width: 100%; background: #21242f; color: #fff; border: 1px solid #2f3442;
  border-radius: 7px; padding: .32rem .5rem; font-size: .88rem;
}
.org-current { font-weight: 600; }
.sidebar-foot { padding: 1rem 1.1rem 0; margin-top: 1rem; border-top: 1px solid #262a36; }
.sidebar-foot .who { font-size: .85rem; color: #e6e9f0; font-weight: 600; }
.sidebar-foot .who-mail { font-size: .74rem; color: #6d7488; margin-bottom: .5rem; }
.sidebar-foot button { background: #21242f; color: #c9cedb; border-color: #2f3442; }
.sidebar-foot button:hover { background: #2b2f3d; color: #fff; }
