/* Colori e forme dal design dell'app timbratura di Frequenze */
:root {
  --primary: #ff801c;
  --primary-dark: #b85a0e;
  --primary-soft: #ffe6d1;
  --bg: #fff2df;
  --surface: #ffffff;
  --ink: #1f1a17;
  --text-2: #4a3f37;
  --text-3: #6b5d52;
  --border: #d9cbb8;
  --border-soft: #eadbc6;
  --chip: #f5efe7;
  --focus: #3c6478;
  --ok-bg: #ddf1e5;
  --ok-fg: #1e6b44;
  --warn-bg: #ffe9cc;
  --warn-fg: #8a4b00;
  --err-bg: #fde2e0;
  --err-fg: #9b1c1c;
  --radius: 20px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 Arial, Helvetica, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* --- Login --- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 28px 28px;
  box-shadow: 0 10px 24px rgba(31, 26, 23, 0.1);
  text-align: center;
}
.login-card img { width: 120px; height: auto; margin-bottom: 16px; }
.login-card h1 { font-size: 22px; margin: 0 0 24px; }
.login-card form { display: grid; gap: 14px; text-align: left; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.error-text { color: var(--err-fg); min-height: 20px; margin: 12px 0 0; font-weight: bold; }

label.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: bold; }
input[type='text'], input[type='password'], input[type='date'], select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--surface);
}
input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--primary-dark); cursor: pointer; }

/* --- Bottoni --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: bold;
  white-space: nowrap;
}
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--ink); }
.btn.primary:hover { background: #f07010; }
.btn.danger { color: var(--err-fg); }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: wait; }

/* --- Testata --- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
}
.top .logo { height: 52px; width: auto; display: block; }
.top .app-title { font-weight: bold; font-size: 18px; }
.tabs { display: flex; gap: 6px; margin-left: 12px; }
.tab {
  border: 0;
  background: transparent;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: bold;
  color: var(--text-2);
}
.tab:hover { background: var(--chip); }
.tab[aria-selected='true'] { background: var(--primary-soft); color: var(--primary-dark); }
.top .spacer { flex: 1; }

main.content { max-width: 1400px; margin: 0 auto; padding: 24px; }
h1.page { font-size: 26px; margin: 0 0 4px; }
.lead { color: var(--text-3); margin: 0 0 20px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .spacer { flex: 1; }
.toolbar form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; font-size: 13px; color: var(--text-3); }
.legend span::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  vertical-align: -2px;
  margin-right: 6px;
  border: 1px solid var(--border);
}
.legend .l-empty::before { background: var(--err-bg); }
.legend .l-warn::before { background: var(--warn-bg); }
.legend .l-off::before { background: var(--chip); }

/* --- Tabelle --- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: middle; }
thead th { font-size: 13px; color: var(--text-2); background: var(--surface); white-space: nowrap; }
th small { display: block; font-weight: normal; color: var(--text-3); }
tr.area-row th {
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 6px 10px;
}
.center { text-align: center; }

.week h2 { font-size: 20px; margin: 0 0 12px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.week h2 small { font-size: 14px; color: var(--text-3); font-weight: normal; }
.week h2 .week-print { margin-left: auto; align-self: center; }
.plan td.task { min-width: 260px; }
.plan td.task .slot { display: block; font-size: 12px; color: var(--text-3); }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: bold;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok-fg);
  margin-left: 6px;
  vertical-align: 1px;
}
.plan td.cell { min-width: 150px; }
.plan td.cell select { width: 100%; min-height: 36px; padding: 4px 8px; }
.plan td.cell.empty select { background: var(--err-bg); border-color: #f1b8b3; }
.plan td.cell.warn select { background: var(--warn-bg); border-color: #f0c78e; }
.plan td.cell .why { font-size: 11px; color: var(--warn-fg); margin-top: 2px; }
.plan td.off { background: var(--chip); }

.avail th.day { text-align: center; border-left: 1px solid var(--border-soft); }
.avail td.slot { text-align: center; }
.avail td.slot.first, .avail th.first { border-left: 1px solid var(--border-soft); }
.avail input.name, .tasks input.name { width: 100%; min-width: 180px; }
.avail td.count { color: var(--text-3); white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

.summary td.num, .summary th.num { text-align: center; }
.empty-state { color: var(--text-3); padding: 24px 0; text-align: center; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--err-fg); }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .top .logo { height: 40px; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  main.content { padding: 16px; }
  .card { padding: 14px; }
}

/* --- Finestre di dialogo --- */
dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100vh - 48px);
  box-shadow: 0 20px 48px rgba(31, 26, 23, 0.25);
}
dialog::backdrop { background: rgba(31, 26, 23, 0.45); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dlg h2 { margin: 0; padding: 20px 24px 12px; font-size: 20px; }
.dlg-body { padding: 0 24px; overflow-y: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; border-top: 1px solid var(--border-soft); margin-top: 12px; }
.dlg fieldset { border: 0; padding: 0; margin: 0 0 12px; }
.dlg legend { font-weight: bold; font-size: 12px; letter-spacing: 0.06em; color: var(--text-2); padding: 0; margin-bottom: 4px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.choice small { color: var(--text-3); }
.choice input[type='radio'] { width: 18px; height: 18px; accent-color: var(--primary-dark); }
.hint { color: var(--text-3); font-size: 13px; margin: 8px 0 12px; }

label.field.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input[type='number'] {
  width: 64px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
}
.summary td.num { white-space: nowrap; }
.summary td.out { background: var(--warn-bg); color: var(--warn-fg); font-weight: bold; }
.avail td.fixed { max-width: 220px; }
.fixed-btn { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); font-weight: normal; }
.fixed-btn.on { background: var(--primary-soft); border-color: #f5c49b; color: var(--primary-dark); font-weight: bold; }

/* --- Stampa: una pagina A4 orizzontale per settimana --- */
#print-area { display: none; }
@media print {
  @page { size: A4 landscape; margin: 8mm 10mm; }
  html, body { background: #fff; }
  #app, #toast, dialog { display: none !important; }
  #print-area { display: block; color: #000; font-family: Arial, Helvetica, sans-serif; }
  .p-week { break-after: page; page-break-after: always; }
  .p-week:last-child { break-after: auto; page-break-after: auto; }
  .p-head { display: flex; align-items: center; gap: 5mm; margin-bottom: 3mm; }
  .p-head img { height: 15mm; width: auto; }
  .p-head h1 { font-size: 15pt; margin: 0; }
  .p-head p { font-size: 10.5pt; margin: 0.5mm 0 0; }
  .p-table { width: 100%; border-collapse: collapse; table-layout: fixed; line-height: 1.2; }
  .p-table col.p-col-task { width: 31%; }
  .p-table th, .p-table td { border: 0.25mm solid #888; padding: 0.35em 0.5em; text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
  .p-table thead th { background: #ffe6d1; }
  .p-table tr.p-area th { background: #1f1a17; color: #fff; font-size: 0.9em; letter-spacing: 0.06em; padding: 0.25em 0.55em; }
  .p-table td.p-off { background: #e4e4e4; }
  .p-table tr { break-inside: avoid; }
  .p-table thead th, .p-table tr.p-area th, .p-table td.p-off { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
