:root {
  --pink: #ff8fb1;
  --pink-dark: #e26d92;
  --mint: #7fd8be;
  --mint-dark: #4bbfa0;
  --cream: #fff7f0;
  --ink: #3b2f38;
  --muted: #8a7f88;
  --line: #efe3e9;
  --danger: #e05252;
  --danger-bg: #fdecec;
  --ok: #3ba55d;
  --shadow: 0 8px 30px rgba(180, 120, 140, 0.15);
  --radius: 14px;
}

* { box-sizing: border-box; }
/* Blocca lo scroll orizzontale della pagina (zoom disattivato via viewport). */
html, body {
  margin: 0; padding: 0; width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}
body { overscroll-behavior-x: none; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #ffeef3 0%, #eafaf4 100%);
  color: var(--ink);
  min-height: 100vh;
}
/* Nessun contenitore può superare la larghezza dello schermo */
.app, .topbar, .card, .tabs { max-width: 100%; }
.table-wrap { max-width: 100%; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

.hidden { display: none !important; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 34px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .logo { font-size: 46px; }
.login-card h1 { font-size: 22px; margin: 8px 0 2px; }
.login-card .subtitle { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--pink); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-weight: 700;
  font-size: 14px;
  background: var(--pink-dark);
  color: #fff;
  text-decoration: none;
  display: inline-block;
  box-shadow: 0 2px 8px rgba(226, 109, 146, .35);
  transition: transform .05s, filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.05); box-shadow: 0 4px 12px rgba(226, 109, 146, .45); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-block { width: 100%; }
.btn-mint { background: var(--mint-dark); box-shadow: 0 2px 8px rgba(75, 191, 160, .35); }
.btn-wa { background: #25d366; box-shadow: 0 2px 8px rgba(37, 211, 102, .35); }
.btn-mint:hover { box-shadow: 0 4px 12px rgba(75, 191, 160, .45); }
.btn-ghost {
  background: #fff; color: var(--ink); border: 1.5px solid var(--line); box-shadow: none;
}
.btn-ghost:hover { background: #faf5f8; border-color: var(--pink); filter: none; box-shadow: none; }
.btn-danger { background: var(--danger); box-shadow: 0 2px 8px rgba(224, 82, 82, .3); }
.btn-danger:hover { box-shadow: 0 4px 12px rgba(224, 82, 82, .4); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }

.msg { font-size: 13px; margin-top: 12px; padding: 9px 12px; border-radius: 9px; }
.msg-error { background: var(--danger-bg); color: var(--danger); }
.msg-ok { background: #e7f6ec; color: var(--ok); }

/* ---- App layout ---- */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 60px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 4px; flex-wrap: wrap; gap: 10px;
}
.topbar .brand { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .user-box { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; }
.badge-admin { background: var(--pink); color: #fff; }
.badge-emp { background: var(--mint); color: #12604c; }

.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); margin-bottom: 22px; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; padding: 11px 16px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: 14px;
}
.tab.active { color: var(--pink-dark); border-bottom-color: var(--pink); }

.card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row .field { flex: 1; min-width: 130px; margin-bottom: 0; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fffafc; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 20px; font-weight: 600; }
.pill-open { background: #fff3d6; color: #a5760a; }
.pill-done { background: #e7f6ec; color: var(--ok); }
.pill-none { background: #f2eef1; color: var(--muted); }

.actions-cell { display: flex; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px; font-size: 14px; }

/* ---- Clock cards (dipendente) ---- */
.shift-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.shift-card { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; }
.shift-card.today { border-color: var(--mint); background: #f5fdfa; }
.shift-card .date { font-weight: 700; font-size: 15px; }
.shift-card .time { color: var(--muted); font-size: 13px; margin: 3px 0 10px; }
.shift-card .stamps { font-size: 13px; margin-bottom: 12px; }
.shift-card .stamps span { font-variant-numeric: tabular-nums; font-weight: 600; }
.clock-actions { display: flex; gap: 8px; }

/* ---- Stats ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--pink-dark); }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(59,47,56,.4);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---- Selettore lingua ---- */
.lang-switch { position: relative; display: inline-block; }
.login-lang { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 9px;
  padding: 6px 10px; font-weight: 700; font-size: 13px; color: var(--ink); cursor: pointer;
}
.lang-btn:hover { border-color: var(--pink); }
.lang-btn .caret { color: var(--muted); font-size: 10px; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px; min-width: 156px; z-index: 60;
}
.lang-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: none; padding: 9px 10px; border-radius: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left;
}
.lang-menu button:hover { background: #faf5f8; }
.lang-menu button.active { background: #fdeef4; color: var(--pink-dark); }
.flag {
  width: 24px; height: 16px; border-radius: 2px; flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); display: inline-block; vertical-align: middle;
}

/* ---- Branding (logo) ---- */
#brandLogo { display: inline-flex; align-items: center; }
.brand-logo-img { height: 30px; width: auto; vertical-align: middle; border-radius: 6px; }
.login-logo-img { max-height: 68px; max-width: 200px; border-radius: 10px; }
.logo-preview { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.logo-preview img { max-height: 56px; max-width: 170px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.logo-preview .placeholder { font-size: 40px; }
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.color-row input[type=color] { width: 46px; height: 40px; padding: 2px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }

/* ---- Selettore locale (super-admin) + contesto login ---- */
.login-context { margin-top: 14px; font-size: 12px; color: var(--muted); }
.tenant-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.tenant-switch select {
  padding: 6px 9px; border: 1.5px solid var(--line); border-radius: 9px;
  font-weight: 600; font-size: 13px; background: #fff; color: var(--ink); max-width: 190px;
}
.tenant-switch select:focus { border-color: var(--pink); outline: none; }
.badge-super { background: #5b6cc9; color: #fff; }
.shop-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.copy-url { font-family: monospace; font-size: 12px; background: #f5eef2; padding: 2px 7px; border-radius: 6px; }

/* ---- Griglia settimanale turni ---- */
.week-nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.week-nav .range { font-weight: 700; font-variant-numeric: tabular-nums; }
.week-nav .btn-ghost { white-space: nowrap; }
.week-arrow { padding: 6px 12px; font-size: 16px; line-height: 1; font-weight: 700; }

.grid-table { border-collapse: collapse; width: 100%; font-size: 12.5px; table-layout: fixed; }
.grid-table col.col-day { width: 84px; }
.grid-table col.col-emp { width: 120px; }
.grid-table col.col-tot { width: 60px; }
.grid-table col.col-cost { width: 70px; }
.grid-table col.col-act { width: 78px; }
.grid-table th, .grid-table td { border: 1px solid var(--line); padding: 5px 6px; vertical-align: top; }
.grid-table thead th {
  background: #faf3f6; text-align: center; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .02em; color: var(--muted); white-space: nowrap;
}
.grid-table thead th .dnum { display: block; font-size: 10.5px; color: var(--ink); font-weight: 600; }
.grid-table .emp-col { position: sticky; left: 0; z-index: 2; background: #fff; text-align: left; width: 116px; }
.grid-table thead .emp-col { z-index: 3; background: #faf3f6; }
.emp-name { font-weight: 700; }
.emp-role { font-size: 11px; color: var(--muted); }

/* Celle giorno: in lettura mostrano i chip, in modifica gli input impilati */
.day-cell { text-align: center; overflow: hidden; }
/* Orario scritto dal collaboratore stesso (verde chiaro); dal manager resta bianca */
.day-cell.self-written { background: #eafaf4; }
/* Collaboratore già in turno in un altro negozio quel giorno (ha precedenza) */
.day-cell.occupied { background: #fdecec; }
.busy-elsewhere {
  font-size: 10px; color: var(--danger); font-weight: 700; line-height: 1.15;
  margin-bottom: 4px; display: block;
}
/* Ogni occupazione in un altro negozio su due righe (negozio sopra, orario sotto) */
.be-item { display: block; margin-bottom: 3px; }

/* ---- Note (checklist condivisa) ---- */
.note-list { list-style: none; margin: 0; padding: 0; }
.note-item {
  display: flex; align-items: flex-start; gap: 9px; padding: 10px;
  border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: #fff;
}
.note-item.dragging { opacity: .5; }
.note-item.done .note-text { text-decoration: line-through; color: var(--muted); }
.note-handle { cursor: grab; color: var(--muted); font-size: 16px; user-select: none; padding-top: 2px; }
.note-check { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 auto; }
.note-body { flex: 1; min-width: 0; }
.note-text { font-size: 14px; word-break: break-word; }
.note-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.note-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.mini {
  border: 1.5px solid var(--line); background: #fff; border-radius: 6px; width: 24px; height: 24px;
  cursor: pointer; font-size: 10px; color: var(--muted); line-height: 1;
}
.mini:hover { border-color: var(--pink); }
.note-empty { color: var(--muted); text-align: center; padding: 16px; list-style: none; }
.cat-tag {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 8px;
  border-radius: 20px; background: #eef0fb; color: #5b6cc9; vertical-align: middle;
}
.completed-head {
  cursor: pointer; font-weight: 700; color: var(--muted); padding: 9px 2px; user-select: none;
  margin-top: 6px; border-top: 1px solid var(--line);
}
.completed-head .caret { display: inline-block; transition: transform .15s; }
.completed-head.open .caret { transform: rotate(90deg); }

/* ---- Mansioni ---- */
.mansione-list { list-style: none; margin: 0; padding: 0; }
.mansione-row {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px;
  border: 1.5px solid var(--line); border-radius: 8px; margin-bottom: 6px;
}
/* Ogni turno su una riga a sé: più turni nello stesso giorno si impilano in verticale */
.shift-chip {
  display: block; width: fit-content; max-width: 100%; font-size: 11.5px; padding: 3px 5px; margin: 0 auto 3px;
  background: #f5eef2; border-radius: 7px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.shift-chip.del { background: var(--danger-bg); color: var(--danger); cursor: pointer; }
.shift-chip.del:hover { box-shadow: inset 0 0 0 2px var(--danger); }
.chip-real { display: block; font-size: 10px; color: var(--ok); font-weight: 600; margin-bottom: 3px; }
.geo { text-decoration: none; margin-left: 2px; }

.cell-line { display: flex; flex-direction: column; gap: 3px; margin-bottom: 5px; }
.cell-line.add { opacity: .6; }
.cell-line.add:focus-within { opacity: 1; }
.t-in { width: 100%; padding: 5px 4px; border: 1.5px solid var(--line); border-radius: 7px; font-size: 12.5px; }
.t-in:focus { border-color: var(--pink); outline: none; }
.cell-real { font-size: 10px; color: var(--ok); width: 100%; font-weight: 600; text-align: center; }

/* Disponibilità: chip verde/rosso in lettura + fasce orarie modificabili */
.avail-chip {
  display: block; width: fit-content; max-width: 100%; margin: 0 auto 3px;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.avail-chip.available { background: var(--mint); color: #12604c; }
.avail-chip.unavailable { background: var(--danger-bg); color: var(--danger); }
.avail-chip.del { cursor: pointer; box-shadow: inset 0 0 0 2px currentColor; }
.a-in { width: 100%; padding: 5px 4px; border: 1.5px solid var(--line); border-radius: 7px; font-size: 12.5px; }
.a-in:focus { border-color: var(--pink); outline: none; }
.avail-line.available .a-in { border-color: var(--mint-dark); background: #f5fdfa; }
.avail-line.unavailable .a-in { border-color: var(--danger); background: #fdf2f2; }

.grid-tot { text-align: center; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { text-align: center; white-space: nowrap; }
.row-btn {
  border: 1.5px solid var(--line); background: #fff; width: 30px; height: 30px; margin: 0 1px;
  border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--ink);
}
.row-btn:hover { border-color: var(--pink); }
.row-btn.active { background: var(--pink); color: #fff; border-color: var(--pink); }
.row-btn.danger.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.grid-table tfoot td { background: #faf3f6; font-weight: 700; text-align: center; }
.grid-table tfoot .emp-col { text-align: right; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  body { font-size: 15px; -webkit-tap-highlight-color: rgba(255, 143, 177, .2); }
  .app { padding: 0 12px 48px; }
  .topbar { padding: 14px 2px; gap: 8px; justify-content: space-between; }
  .topbar .brand { font-size: 18px; }
  .topbar .user-box { gap: 8px; }

  /* Le tab vanno a capo su più righe: menu fisso, niente scorrimento che si trascina */
  .tabs { flex-wrap: wrap; gap: 4px; overflow: visible; }
  .tab { padding: 9px 11px; font-size: 13.5px; }

  /* I filtri e i campi in riga si impilano e diventano a tutta larghezza */
  .row .field { min-width: 100%; flex-basis: 100%; }
  .row > .btn { width: 100%; }

  /* 16px evita lo zoom automatico su iOS quando si tocca un campo */
  input, select, textarea { font-size: 16px; }

  .card { padding: 16px; }
  .card h2 { font-size: 16px; }
  .shift-cards { grid-template-columns: 1fr; }

  /* Target di tocco più grandi */
  .btn { padding: 12px 18px; }
  .clock-actions .btn { padding: 16px; font-size: 16px; }
  .btn-sm { padding: 8px 12px; font-size: 13px; }

  /* Modale a tutto schermo utile e scrollabile */
  .modal { max-height: 92vh; overflow-y: auto; padding: 20px; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; }

  th, td { padding: 10px 10px; }
  .actions-cell { flex-wrap: wrap; }

  /* Tabelle "impilabili": ogni riga diventa una scheda (niente scroll orizzontale) */
  .resp-table thead { display: none; }
  .resp-table, .resp-table tbody, .resp-table tr, .resp-table td { display: block; width: 100%; }
  .resp-table tr { margin-bottom: 8px; border: 1.5px solid var(--line); border-radius: 10px; padding: 4px 8px; background: #fff; }
  .resp-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none; padding: 6px 2px; white-space: normal; text-align: right;
  }
  .resp-table td::before {
    content: attr(data-label); font-weight: 700; color: var(--muted); font-size: 12px; text-align: left;
  }
  .resp-table tr:hover td { background: transparent; }
}

@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar .brand span { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
