/* Layout del gestionale */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 50; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.side-brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 750; overflow: hidden; flex: none; }
.side-brand .logo img { width: 100%; height: 100%; object-fit: cover; }
.side-brand .name { font-weight: 700; line-height: 1.15; font-size: 14px; }
.side-brand select { margin-top: 2px; min-height: 0; padding: 2px 4px; font-size: 12px; border: 0; background: transparent;
  color: var(--muted); width: auto; max-width: 150px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px 16px; }
.nav .sec { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text);
  font-weight: 550; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.nav a .count { margin-left: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px;
  padding: 0 6px; min-width: 18px; text-align: center; }
.side-foot { margin-top: auto; padding: 12px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; font-size: 13px; line-height: 1.2; }
.side-foot .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--bg);
  position: sticky; top: 0; z-index: 40; border-bottom: 1px solid transparent; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }
.page { padding: 4px 24px 40px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg); }
  .layout.open .sidebar { transform: none; }
  .layout.open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 45; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); flex-wrap: wrap; }
  .page { padding: 4px 16px 32px; }
}

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, var(--brand-soft), transparent 50%), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .logo { width: 48px; height: 48px; border-radius: 14px; background: var(--brand); margin-bottom: 18px; display: flex;
  align-items: center; justify-content: center; }
.demo-box { margin-top: 16px; font-size: 12.5px; }
.demo-box code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* Agenda */
.agenda-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.agenda-bar .date-label { font-weight: 650; font-size: 16px; min-width: 200px; text-transform: capitalize; }
.agenda-shell { display: grid; grid-template-columns: 1fr; gap: 16px; }
.agenda-shell.with-side { grid-template-columns: 1fr 280px; }
@media (max-width: 1100px) { .agenda-shell.with-side { grid-template-columns: 1fr; } }
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto;
  max-height: calc(100vh - 170px); position: relative; box-shadow: var(--shadow); }
.cal-grid { display: grid; position: relative; min-width: max-content; }
.cal-head { position: sticky; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 6px; text-align: center; font-weight: 650; font-size: 13px; display: flex; gap: 6px; align-items: center;
  justify-content: center; min-width: 0; }
.cal-head.corner { left: 0; z-index: 8; }
.cal-head.today { color: var(--brand-ink); }
.cal-times { position: sticky; left: 0; z-index: 5; background: var(--surface); border-right: 1px solid var(--border); }
.cal-times div { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); }
.cal-col { position: relative; border-right: 1px solid var(--border); cursor: crosshair; }
.cal-col:last-child { border-right: 0; }
.cal-col .off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, var(--surface-2),
  var(--surface-2) 6px, transparent 6px, transparent 12px); pointer-events: none; }
.cal-col .hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); pointer-events: none; }
.cal-col .hline.half { border-top-style: dashed; opacity: .6; }
.now-line { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 4; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); }
.appt { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 3px 6px; font-size: 12px; overflow: hidden;
  cursor: grab; z-index: 3; border-left: 4px solid var(--c); background: color-mix(in srgb, var(--c) 16%, var(--surface));
  color: var(--text); line-height: 1.25; user-select: none; touch-action: none; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.appt:hover { z-index: 4; box-shadow: var(--shadow); }
.appt.dragging { opacity: .85; cursor: grabbing; z-index: 10; box-shadow: var(--shadow-lg); }
.appt b { font-weight: 650; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .t { font-size: 11px; color: var(--muted); }
.appt.st-arrived { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); }
.appt.st-done { opacity: .62; }
.appt.st-noshow { background: var(--danger-soft); text-decoration: line-through; }
.appt .ico { position: absolute; right: 5px; top: 3px; font-size: 11px; }
.appt .resize { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize; }
.ghost-slot { position: absolute; left: 3px; right: 3px; border-radius: 7px; background: var(--brand-soft);
  border: 1px dashed var(--brand); pointer-events: none; z-index: 2; font-size: 11px; padding: 2px 6px; color: var(--brand-ink); }

.svc-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 260px;
  overflow-y: auto; }
.svc-pick label { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 13px; }
.svc-pick label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.svc-pick .meta { font-size: 11.5px; color: var(--muted); }
.cust-results { border: 1px solid var(--border); border-radius: 8px; max-height: 200px; overflow-y: auto; margin-top: 6px; }
.cust-results button { display: flex; width: 100%; text-align: left; padding: 8px 10px; background: none; border: 0;
  border-bottom: 1px solid var(--border); font: inherit; cursor: pointer; color: var(--text); gap: 8px; }
.cust-results button:hover { background: var(--surface-2); }
.chosen { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--brand);
  background: var(--brand-soft); border-radius: 8px; }

/* Cassa */
.pos { display: grid; grid-template-columns: 1fr 400px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .pos { grid-template-columns: 1fr; } }
.pos-catalog .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.pos-catalog .item { text-align: left; padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; font: inherit; color: var(--text); display: flex; flex-direction: column;
  gap: 2px; min-height: 64px; }
.pos-catalog .item:hover { border-color: var(--brand); background: var(--brand-soft); }
.pos-catalog .item .p { font-weight: 700; margin-top: auto; }
.ticket { position: sticky; top: 76px; }
.ticket-lines { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; max-height: 42vh; overflow-y: auto; }
.tline { display: grid; grid-template-columns: 1fr 70px 80px 28px; gap: 6px; align-items: center; padding: 6px 0;
  border-bottom: 1px dashed var(--border); font-size: 13px; }
.tline input, .tline select { min-height: 28px; padding: 3px 6px; font-size: 13px; }
.tline .name { min-width: 0; }
.tline .sub { font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.tline .sub select, .tline .sub input { width: auto; max-width: 150px; }
.totals { display: flex; flex-direction: column; gap: 4px; padding: 8px 0; }
.totals div { display: flex; justify-content: space-between; }
.totals .grand { font-size: 22px; font-weight: 750; }
.pay-row { display: grid; grid-template-columns: 1fr 110px 28px; gap: 6px; margin-bottom: 6px; }

/* Ricevuta */
.receipt { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; max-width: 340px; margin: 0 auto;
  background: #fff; color: #000; padding: 16px; border: 1px dashed #bbb; }
.receipt .r { display: flex; justify-content: space-between; gap: 8px; }
.receipt hr { border: 0; border-top: 1px dashed #999; }
@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; left: 0; top: 0; border: 0; }
}

/* Scheda cliente */
.profile-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.profile-head .avatar { width: 54px; height: 54px; font-size: 19px; }
.balances { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.balances .card { padding: 12px 14px; }

/* WhatsApp */
.wa { display: grid; grid-template-columns: 320px 1fr; gap: 0; height: calc(100vh - 150px); min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
@media (max-width: 800px) { .wa { grid-template-columns: 1fr; height: auto; } .wa .wa-list { max-height: 260px; } }
.wa-list { border-right: 1px solid var(--border); overflow-y: auto; }
.wa-list button { display: flex; gap: 10px; width: 100%; padding: 12px; border: 0; border-bottom: 1px solid var(--border);
  background: none; text-align: left; font: inherit; color: var(--text); cursor: pointer; align-items: center; }
.wa-list button:hover, .wa-list button.active { background: var(--surface-2); }
.wa-list .preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.wa-chat-head { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; }
.wa-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px;
  background: color-mix(in srgb, #e5ddd5 55%, var(--surface)); min-height: 300px; }
:root[data-theme="dark"] .wa-msgs { background: #0d1418; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .wa-msgs { background: #0d1418; } }
.bubble { max-width: min(78%, 420px); padding: 7px 10px 5px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word;
  font-size: 13.5px; box-shadow: 0 1px 1px rgba(0,0,0,.08); background: var(--surface); color: var(--text); }
.bubble.out { align-self: flex-end; background: #d9fdd3; color: #111b21; }
:root[data-theme="dark"] .bubble.out { background: #005c4b; color: #e9edef; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bubble.out { background: #005c4b; color: #e9edef; } }
.bubble.in { align-self: flex-start; }
.bubble.flip.out { align-self: flex-start; background: var(--surface); color: var(--text); }
.bubble.flip.in { align-self: flex-end; background: #d9fdd3; color: #111b21; }
.bubble .meta { font-size: 10.5px; opacity: .6; text-align: right; margin-top: 2px; }
.bubble .opts { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; border-top: 1px solid rgba(0,0,0,.08); padding-top: 6px; }
.bubble .opts button { background: none; border: 0; color: #027eb5; font: inherit; font-weight: 600; padding: 4px; cursor: pointer;
  text-align: center; border-radius: 6px; }
.bubble .opts button:hover { background: rgba(0,0,0,.05); }
.bubble .opts button:disabled { color: inherit; opacity: .5; cursor: default; }
.bubble .opts .desc { display: block; font-weight: 400; font-size: 11.5px; opacity: .7; }
.wa-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.phone-frame { max-width: 420px; margin: 0 auto; border: 1px solid var(--border); border-radius: 22px; overflow: hidden;
  display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 520px; box-shadow: var(--shadow-lg); }
.phone-frame .wa-chat-head { background: #008069; color: #fff; }
.list-sheet { position: absolute; inset: auto 0 0 0; background: var(--surface); border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg); max-height: 70%; overflow-y: auto; z-index: 5; padding: 8px 0; }
.list-sheet button { display: block; width: 100%; text-align: left; padding: 10px 18px; background: none; border: 0;
  font: inherit; color: var(--text); cursor: pointer; }
.list-sheet button:hover { background: var(--surface-2); }
.list-sheet h4 { padding: 6px 18px; margin: 0; color: #008069; font-size: 13px; }

/* Impostazioni orari */
.hours-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: start; padding: 8px 0;
  border-bottom: 1px solid var(--border); }
.hours-row .ranges { display: flex; flex-direction: column; gap: 6px; }
.hours-row .range { display: flex; gap: 6px; align-items: center; }
.hours-row input[type=time] { width: 120px; }
@media (max-width: 600px) {
  .hours-row { grid-template-columns: 1fr; gap: 6px; }
  .hours-row input[type=time] { width: auto; flex: 1; min-width: 0; }
  .hours-row .range { flex-wrap: nowrap; }
}
