/* ===== Turni GPG — stile (tema scuro come l'app originale) ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --info: #06b6d4;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --border: #334155;

  --shift-M: #3b82f6; --shift-P: #8b5cf6; --shift-N: #1e40af;
  --shift-D12: #06b6d4; --shift-N12: #0891b2;
  --shift-S: #64748b; --shift-R: #475569; --shift-RL: #f59e0b; --shift-RR: #84cc16;
  --shift-SPEZ: #ec4899; --shift-EXTRA: #d946ef;
  --absence-MAL: #ef4444; --absence-104: #f97316; --absence-INF: #dc2626; --absence-PER: #eab308; --absence-FER: #34d399;

  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px;
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) fixed;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-light); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ----- Schermate centrate (login, setup, blocchi) ----- */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.center-card {
  width: 100%; max-width: 400px;
  background: rgba(30, 41, 59, .9);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.center-card .field { text-align: left; }
.brand-logo { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--primary-light); object-fit: cover; }
.brand-logo.lg { width: 88px; height: 88px; margin: 0 auto; }
.brand-title {
  font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 700; line-height: 1.2;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--info) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.form-error { color: #fca5a5; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .4); border-radius: var(--r-sm); padding: 8px 10px; font-size: .9rem; text-align: left; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--text); }

/* ----- Campi ----- */
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: .85rem; color: var(--text-2); font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=month], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 11px;
  min-height: 42px;
}
input[type=color] { width: 64px; height: 42px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); padding: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); outline-offset: 1px; }
input[readonly] { color: var(--muted); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }

/* ----- Pulsanti ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px;
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 600; cursor: pointer; transition: filter .15s, background .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-secondary { background: var(--bg-3); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #3e4c63; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-text { background: none; color: var(--text-2); }
.btn-text:hover { color: var(--text); }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon {
  width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer;
}
.btn-icon:hover { background: #3e4c63; }
.btn-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ----- Layout app ----- */
.app-container { max-width: 1400px; margin: 0 auto; padding: 16px; }
.app-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--bg-2) 0%, var(--bg-3) 100%);
  border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: 16px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.header-title { display: flex; align-items: center; gap: 14px; }
.subtitle { color: var(--text-2); font-size: .9rem; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-chip { color: var(--text-2); font-weight: 500; font-size: .9rem; margin-right: 4px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); flex: none; }
.sync-dot.pending { background: var(--warning); }
.sync-dot.offline { background: var(--danger); }

.banner { border-radius: var(--r-md); padding: 10px 14px; margin-bottom: 12px; font-size: .9rem; }
.banner-warning { background: rgba(245, 158, 11, .15); border: 1px solid rgba(245, 158, 11, .5); color: #fde68a; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tab {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 9px 14px; cursor: pointer; white-space: nowrap; font-weight: 500; color: var(--text-2);
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tab-content { display: none; }
.tab-content.active { display: block; }
body:not(.is-admin) .admin-only { display: none !important; }

.period-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.segmented { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 3px; }
.seg { background: none; border: none; padding: 6px 14px; border-radius: var(--r-sm); cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg.active { background: var(--bg-3); color: var(--text); }
.date-nav { display: flex; align-items: center; gap: 6px; }
.btn-nav { width: 40px; height: 42px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer; }
.date-picker { width: auto; }
.period-label { color: var(--text-2); font-weight: 600; text-transform: capitalize; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ----- Legenda ----- */
.legend { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px; margin-bottom: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-2); }

/* ----- Calendario ----- */
.calendar-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--card); -webkit-overflow-scrolling: touch; }
.calendar-grid { display: grid; grid-template-columns: 150px repeat(var(--days), minmax(68px, 1fr)); min-width: max-content; }
.cal-head, .cal-op, .cal-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-head { position: sticky; top: 0; background: var(--bg-2); padding: 6px 4px; text-align: center; font-size: .8rem; color: var(--text-2); z-index: 1; }
.cal-head .dname { text-transform: capitalize; }
.cal-head .dnum { font-weight: 700; color: var(--text); font-size: .95rem; }
.cal-head .hol { font-size: .65rem; color: #fca5a5; line-height: 1.1; }
.cal-head.weekend { background: #243147; }
.cal-head.holiday { background: rgba(239, 68, 68, .15); }
.cal-head.today { box-shadow: inset 0 -3px 0 var(--primary-light); }
.cal-corner { left: 0; z-index: 2; text-align: left; padding-left: 10px; }
.cal-op {
  position: sticky; left: 0; z-index: 1; background: var(--bg-2);
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-weight: 500; font-size: .9rem;
}
.op-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.cal-cell { min-height: 74px; padding: 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; transition: background .1s; }
.cal-cell:hover { background: rgba(59, 130, 246, .08); }
.cal-cell.readonly { cursor: default; }
.cal-cell.weekend { background: rgba(51, 65, 85, .25); }
.cal-cell.holiday { background: rgba(239, 68, 68, .07); }
.cal-cell.rest-violation { box-shadow: inset 0 0 0 2px var(--danger); }
.badge { display: inline-block; min-width: 34px; padding: 2px 6px; border-radius: var(--r-sm); font-weight: 700; font-size: .8rem; color: #fff; text-align: center; }
.cell-times { font-size: .68rem; color: var(--text-2); text-align: center; line-height: 1.2; }
.cell-stats { font-size: .68rem; color: var(--muted); }
.cell-notes { font-size: .65rem; color: #fde68a; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shift-M { background: var(--shift-M); } .shift-P { background: var(--shift-P); } .shift-N { background: var(--shift-N); }
.shift-D12 { background: var(--shift-D12); } .shift-N12 { background: var(--shift-N12); }
.shift-S { background: var(--shift-S); } .shift-R { background: var(--shift-R); } .shift-RL { background: var(--shift-RL); color: #111; }
.shift-RR { background: var(--shift-RR); color: #111; } .shift-SPEZ { background: var(--shift-SPEZ); } .shift-EXTRA { background: var(--shift-EXTRA); }
.absence-MAL { background: var(--absence-MAL); } .absence-104 { background: var(--absence-104); } .absence-INF { background: var(--absence-INF); }
.absence-PER { background: var(--absence-PER); color: #111; } .absence-FER { background: var(--absence-FER); color: #111; }

/* ----- Card e liste ----- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; margin-bottom: 12px; }
.card h3 { font-size: 1rem; margin: 4px 0 10px; }
.card h3:not(:first-child) { margin-top: 18px; }
.card.info { border-color: rgba(6, 182, 212, .4); }
.card-list { display: grid; gap: 10px; margin-bottom: 12px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px 14px; }
.list-item .who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list-item .who > div { min-width: 0; }
.list-item .name { font-weight: 600; }
.list-item .sub { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.list-item .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.pill { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--bg-3); color: var(--text-2); margin-left: 6px; }
.pill.admin { background: rgba(37, 99, 235, .3); color: #bfdbfe; }
.pill.off { background: rgba(239, 68, 68, .25); color: #fecaca; }
details.card summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }

.grid-times { display: grid; grid-template-columns: 110px 1fr auto 1fr; gap: 8px; align-items: center; }
.grid-times span { color: var(--muted); }

/* Switch */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; margin: 6px 0 10px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { width: 44px; height: 24px; border-radius: 999px; background: var(--bg-3); position: relative; flex: none; transition: background .15s; }
.switch .slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary-light); outline-offset: 2px; }

/* Riepilogo */
.summary-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.summary-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px; }
.summary-card header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.summary-card h3 { font-size: 1rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--bg); border-radius: var(--r-md); padding: 8px; }
.stat .label { font-size: .72rem; color: var(--muted); }
.stat .value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .badge { min-width: 0; }

/* Registro */
.logbook { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; max-height: 65vh; overflow-y: auto; }
.log-row { padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); overflow-wrap: anywhere; }
.log-row time { color: var(--primary-light); margin-right: 6px; }
.log-row .act { color: var(--muted); }

/* ----- Modali ----- */
dialog.modal { margin: auto; padding: 0; border: none; background: transparent; color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog.modal-sm { width: min(420px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(2, 6, 23, .7); }
.modal-content { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 1.15rem; }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); width: 36px; height: 36px; }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.modal-body h3 { font-size: .95rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.segment { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.validation .err { color: #fca5a5; background: rgba(239, 68, 68, .12); border-left: 3px solid var(--danger); padding: 8px 10px; border-radius: var(--r-sm); font-size: .9rem; }
.info-box { background: rgba(6, 182, 212, .1); border: 1px solid rgba(6, 182, 212, .35); border-radius: var(--r-md); padding: 10px 12px; font-size: .88rem; }

/* ----- Toast ----- */
.toast-stack { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 1000; pointer-events: none; }
.toast { background: var(--bg-3); border: 1px solid var(--border); border-left: 4px solid var(--success); border-radius: var(--r-md); padding: 10px 14px; box-shadow: var(--shadow); max-width: 420px; pointer-events: auto; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ----- Mobile ----- */
@media (max-width: 640px) {
  .app-container { padding: 10px; }
  .app-header { padding: 12px; }
  .brand-logo { width: 44px; height: 44px; }
  .user-chip { width: 100%; order: -1; }
  .grid-times { grid-template-columns: 1fr 1fr; }
  .grid-times label { grid-column: 1 / -1; }
  .grid-times span { display: none; }
  .calendar-grid { grid-template-columns: 110px repeat(var(--days), minmax(60px, 1fr)); }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
}

/* ----- Stampa ----- */
#print-area { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff !important; color: #000; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-family: Arial, sans-serif; font-size: 9pt; color: #000; }
  #print-area h1 { font-size: 14pt; margin-bottom: 4mm; }
  #print-area h2 { font-size: 12pt; margin: 0 0 3mm; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 2px 3px; text-align: center; }
  #print-area th { background: #eee; }
  #print-area td.op { text-align: left; white-space: nowrap; font-weight: bold; }
  #print-area .we { background: #f2f2f2; }
  #print-area .page { page-break-after: always; }
  #print-area .page:last-child { page-break-after: auto; }
  #print-area .sig td { height: 7mm; }
  #print-area .foot { margin-top: 3mm; font-size: 8pt; color: #555; }
}
