:root {
  --paper: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #fbf9f6;
  --ink: #1f1a15;
  --ink-2: #4b443c;
  --muted: #7a7166;
  --line: #e7dfd3;
  --line-2: #d8cebf;
  --accent: #a8481f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e6dc;
  --ok: #2f7a4a;
  --ok-soft: #e3f1e7;
  --warn: #9a6a00;
  --warn-soft: #fbf0d6;
  --danger: #b3261e;
  --danger-soft: #fbe5e3;
  --closed: repeating-linear-gradient(135deg, #efe9e0 0 6px, #e8e1d6 6px 12px);
  --shadow: 0 1px 2px rgba(31, 26, 21, .06), 0 6px 20px rgba(31, 26, 21, .06);
  --radius: 12px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16130f; --surface: #1f1b17; --surface-2: #231f1a; --ink: #f2ece4; --ink-2: #d4ccc1;
    --muted: #a39a8e; --line: #342e27; --line-2: #463e35; --accent: #e07a4a; --accent-ink: #1b120d;
    --accent-soft: #3a2519; --ok: #6cc28c; --ok-soft: #1d3326; --warn: #e6b450; --warn-soft: #3a2f16;
    --danger: #ff8a80; --danger-soft: #3b1f1d;
    --closed: repeating-linear-gradient(135deg, #1b1814 0 6px, #211d18 6px 12px);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- top bar & nav */
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 16px; padding: 10px 20px; max-width: 1400px; margin: 0 auto; }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.brand small { font-family: var(--sans); font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a { text-decoration: none; padding: 7px 12px; border-radius: 999px; color: var(--ink-2); font-size: 14px; position: relative; }
.nav a:hover { background: var(--line); }
.nav a.on { background: var(--ink); color: var(--paper); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent);
  color: var(--accent-ink); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; margin-left: 4px; }
.bottomnav { display: none; }
main { max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px; }

@media (max-width: 760px) {
  .nav { display: none; }
  .topbar-inner { padding: 10px 16px; }
  main { padding: 12px 12px calc(var(--nav-h) + 24px); }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; font-size: 11px; color: var(--muted); position: relative; }
  .bottomnav a.on { color: var(--accent); font-weight: 600; }
  .bottomnav svg { width: 22px; height: 22px; }
  .bottomnav .badge { position: absolute; top: 4px; left: 55%; }
}

/* ---------- buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2);
  background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; text-decoration: none;
  white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 8px; width: 38px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label, .lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface-2); min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); padding: 6px 11px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* ---------- page header */
.pagehead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h1 { font-size: 24px; margin-right: 6px; }
.pagehead .spacer { flex: 1; }
.datenav { display: flex; align-items: center; gap: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.closed { background: var(--danger-soft); color: var(--danger); }
.pill.special { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--line); color: var(--ink-2); }
.stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.stats b { color: var(--ink); font-size: 15px; }

/* ---------- agenda giorno */
.agenda { position: relative; overflow: auto; max-height: calc(100vh - 170px); border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.agenda-grid { display: grid; position: relative; min-width: 100%; }
.agenda-head { position: sticky; top: 0; z-index: 6; display: grid; background: var(--surface); border-bottom: 1px solid var(--line); }
.agenda-head .corner { position: sticky; left: 0; background: var(--surface); z-index: 7; }
.ophead { padding: 9px 8px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; border-left: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ophead .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ophead .cnt { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 500; }
.timecol { position: sticky; left: 0; z-index: 5; background: var(--surface); border-right: 1px solid var(--line); }
.timecol .t { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.opcol { position: relative; border-left: 1px solid var(--line); }
.opcol .slot { position: absolute; left: 0; right: 0; border-top: 1px solid transparent; cursor: cell; }
.opcol .slot.h { border-top-color: var(--line); }
.opcol .slot.hh { border-top: 1px dashed color-mix(in srgb, var(--line) 70%, transparent); }
.opcol .slot:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.closedzone { position: absolute; left: 0; right: 0; background: var(--closed); pointer-events: none; z-index: 1; }
.block { position: absolute; left: 3px; right: 3px; z-index: 2; background: var(--closed); border: 1px dashed var(--line-2);
  border-radius: 8px; padding: 4px 7px; font-size: 12px; color: var(--muted); cursor: pointer; overflow: hidden; }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 4; pointer-events: none; }
.nowline::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.appt { position: absolute; z-index: 3; border-radius: 8px; overflow: hidden; cursor: grab; user-select: none; -webkit-user-select: none;
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); background: color-mix(in srgb, var(--c) 10%, var(--surface));
  touch-action: pan-y; transition: box-shadow .12s; }
.appt:hover { box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.appt .seg { position: absolute; left: 0; right: 0; }
.appt .seg.busy { background: color-mix(in srgb, var(--c) 26%, var(--surface)); }
.appt .seg.posa { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 9%, var(--surface)) 0 5px,
  color-mix(in srgb, var(--c) 17%, var(--surface)) 5px 10px); }
.appt .txt { position: relative; padding: 4px 7px; font-size: 12px; line-height: 1.25; }
.appt .txt b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .txt .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; color: var(--ink-2); }
.appt .tag { position: absolute; top: 4px; right: 5px; font-size: 11px; }
.appt.done { opacity: .6; }
.appt.no_show { opacity: .5; text-decoration: line-through; }
.appt.dragging { opacity: .35; }
.appt.ghost { opacity: .9; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 20; pointer-events: none; cursor: grabbing; }
.appt.bad { outline: 2px solid var(--danger); }
.agenda.day-closed .opcol { background: var(--closed); }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 16px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line-2); }
.legend .lb { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
.legend .lp { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, var(--surface)) 0 4px, color-mix(in srgb, var(--accent) 20%, var(--surface)) 4px 8px); }
.legend .lc { background: var(--closed); }

/* ---------- settimana */
.week { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
.week .wh { padding: 10px 8px; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); text-align: center; cursor: pointer; }
.week .wh:hover { background: var(--surface-2); }
.week .wh .d { font-family: var(--serif); font-size: 22px; font-weight: 600; line-height: 1; }
.week .wh .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.week .wh .n { font-size: 12px; margin-top: 4px; color: var(--ink-2); }
.week .wh.today .d { color: var(--accent); }
.week .th { font-size: 11px; color: var(--muted); text-align: right; padding: 4px 8px 0 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.week .cell { border-top: 1px solid var(--line); border-left: 1px solid var(--line); min-height: 38px; position: relative; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.week .cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.week .cell.off { background: var(--closed); cursor: default; }
.week .cell.off:hover { outline: none; }
.week .util { height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 0; width: 70%; overflow: hidden; }
.week .util span { display: block; height: 100%; background: var(--accent); }
.scale { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.scale span { width: 22px; height: 12px; border-radius: 3px; }

/* ---------- dialog / sheet */
dialog.sheet { border: none; padding: 0; border-radius: 16px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.sheet::backdrop { background: rgba(20, 15, 10, .45); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-head h2 { font-size: 20px; flex: 1; }
.sheet-body { padding: 4px 18px 16px; }
.sheet-foot { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.sheet-foot .spacer { flex: 1; }
@media (max-width: 760px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 88vh; }
}
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 14px; margin-bottom: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.warnbox { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 8px 0; }
.errbox { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 8px 0; }
.slotpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; max-height: 160px; overflow: auto; }
.slotpick button { border: 1px solid var(--line-2); background: var(--surface); border-radius: 8px; padding: 6px 0; cursor: pointer; font-variant-numeric: tabular-nums; }
.slotpick button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 760px) { .toast { bottom: calc(var(--nav-h) + 20px); } }

/* ---------- tabelle */
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list tr:last-child td { border-bottom: none; }
table.list tr.link { cursor: pointer; }
table.list tr.link:hover td { background: var(--surface-2); }
table.edit td { padding: 6px 6px; vertical-align: middle; }
table.edit input[type=text] { min-width: 120px; }
table.edit input[type=number] { width: 72px; min-width: 64px; }
table.edit input[type=time] { width: 110px; }
.tablewrap { overflow-x: auto; }
.section { margin-bottom: 22px; }
.section h2 { font-size: 19px; margin-bottom: 4px; }
.section p.muted { margin: 0 0 12px; font-size: 14px; }

/* ---------- inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr; gap: 14px; min-height: 60vh; }
.convlist { overflow: auto; max-height: calc(100vh - 150px); }
.conv { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover, .conv.on { background: var(--surface-2); }
.conv .who { font-weight: 600; }
.thread { display: flex; flex-direction: column; min-height: 60vh; }
.thread-msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 260px); }
.bubble { max-width: 78%; padding: 8px 11px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; }
.bubble.out { background: var(--accent-soft); align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble .opts { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.thread-foot { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
@media (max-width: 760px) { .inbox { grid-template-columns: 1fr; } .convlist { max-height: 35vh; } }

/* ---------- login */
.loginwrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.loginbox { width: min(360px, 100%); }
.loginbox h1 { font-size: 28px; margin-bottom: 4px; }

/* ---------- simulatore */
.simwrap { display: grid; grid-template-columns: 380px 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .simwrap { grid-template-columns: 1fr; } }
.phone { background: #0b141a; border-radius: 28px; padding: 10px; box-shadow: var(--shadow); max-width: 380px; width: 100%; margin: 0 auto; }
.phone-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #1f2c34; border-radius: 20px 20px 0 0; color: #e9edef; }
.phone-top .av { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-weight: 700; color: #fff; }
.phone-top small { display: block; color: #8696a0; font-size: 12px; }
.chat { height: 560px; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px;
  background: #0b141a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23182229'/%3E%3C/svg%3E"); }
.wa { max-width: 86%; padding: 6px 9px 4px; border-radius: 8px; font-size: 14.5px; line-height: 1.35; color: #e9edef; white-space: pre-wrap; word-wrap: break-word; }
.wa.in { background: #005c4b; align-self: flex-end; border-top-right-radius: 2px; }
.wa.out { background: #202c33; align-self: flex-start; border-top-left-radius: 2px; }
.wa .time { font-size: 11px; color: #8696a0; text-align: right; margin-top: 2px; }
.wa .tpl { font-size: 11px; color: #ffd279; margin-bottom: 3px; }
.wa-btns { display: flex; flex-direction: column; gap: 3px; align-self: flex-start; max-width: 86%; width: 86%; }
.wa-btns button { background: #202c33; color: #53bdeb; border: none; padding: 9px; border-radius: 8px; cursor: pointer; font-size: 14.5px; }
.wa-btns button:hover { background: #2a3942; }
.wa-btns button:disabled { color: #5b6b74; cursor: default; }
.phone-foot { display: flex; gap: 6px; padding: 8px; background: #0b141a; border-radius: 0 0 20px 20px; }
.phone-foot input { background: #2a3942; border: none; color: #e9edef; border-radius: 20px; padding: 10px 14px; min-height: 42px; }
.phone-foot button { background: #00a884; border: none; border-radius: 50%; width: 42px; height: 42px; color: #fff; cursor: pointer; flex: none; }
.wa-list { position: absolute; inset: auto 0 0 0; background: #111b21; border-radius: 16px 16px 0 0; max-height: 75%; overflow: auto; color: #e9edef; z-index: 3; }
.wa-list h4 { margin: 0; padding: 14px 16px 6px; font-size: 13px; color: #00a884; font-family: var(--sans); }
.wa-list .r { padding: 10px 16px; border-bottom: 1px solid #222d34; cursor: pointer; }
.wa-list .r:hover { background: #202c33; }
.wa-list .r small { display: block; color: #8696a0; }
.wa-list .x { text-align: center; padding: 12px; color: #53bdeb; cursor: pointer; }
.chat-shell { position: relative; }

/* ---------- agenda su telefono */
#dayTitle { cursor: pointer; }
@media (max-width: 760px) {
  .pagehead { gap: 8px; }
  .pagehead h1 { font-size: 21px; order: -1; flex: 1 1 100%; }
  .datenav input[type=date] { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
  .stats { font-size: 12px; gap: 10px; }
  .pagehead .spacer { display: none; }
  .pagehead .btn { min-height: 36px; padding: 6px 11px; font-size: 13px; }
  .agenda { max-height: calc(100vh - 250px); }
  .appt .txt { padding: 3px 5px; font-size: 11px; }
  .appt .txt b { font-size: 12px; }
  .appt .en, .appt .tag { display: none; }
  .ophead { font-size: 13px; padding: 8px 6px; }
  .legend label.check { margin-left: 0 !important; }
}
