/* ==========================================================================
   Incanto — token e componenti condivisi
   ========================================================================== */
:root {
  --bg: #f3f3ef;
  --surface: #ffffff;
  --surface-2: #f7f7f4;
  --soft: #efefea;
  --ink: #0f100d;
  --ink-2: #33352f;
  --muted: #7b7d75;
  --faint: #a9aba3;
  --line: #e6e6e0;
  --line-2: #dcdcd5;
  --accent: #d8f15d;
  --accent-2: #eef8b8;
  --accent-ink: #1d2600;
  --ok: #2f9a68;
  --ok-bg: #e6f4ec;
  --warn: #c7801b;
  --warn-bg: #fbf0dc;
  --info: #3c6fd8;
  --info-bg: #e7eefc;
  --danger: #d6452f;
  --r-xl: 32px;
  --r-lg: 24px;
  --r: 18px;
  --r-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 16, 13, .05);
  --shadow: 0 1px 2px rgba(15, 16, 13, .04), 0 10px 30px -8px rgba(15, 16, 13, .10);
  --shadow-lg: 0 2px 6px rgba(15, 16, 13, .05), 0 30px 80px -20px rgba(15, 16, 13, .25);
  --font: 'Inter Tight', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'ss01', 'cv11';
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
::selection { background: var(--accent); color: var(--accent-ink); }

.serif { font-family: var(--serif); font-weight: 400; font-style: italic; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* icone lucide */
.i { width: 18px; height: 18px; stroke-width: 1.7; flex: none; }
.i-sm { width: 15px; height: 15px; }
.i-xs { width: 13px; height: 13px; }
.i-lg { width: 22px; height: 22px; }

/* bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 999px;
  font-weight: 500; font-size: 14px; letter-spacing: -.005em; white-space: nowrap;
  transition: transform .2s var(--ease), background .2s, box-shadow .2s, color .2s;
}
.btn:active { transform: scale(.97); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #262822; }
.btn-dark .btn-ico { background: rgba(255, 255, 255, .14); }
.btn-light { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-light:hover { box-shadow: inset 0 0 0 1px var(--line-2), var(--shadow-sm); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--soft); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: #cfe94e; }
.btn-lg { height: 52px; padding: 0 24px; font-size: 15px; }
.btn-sm { height: 34px; padding: 0 13px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; margin-right: -8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); transition: .2s;
}
.icon-btn:hover { box-shadow: inset 0 0 0 1px var(--line-2), var(--shadow-sm); }

/* chip e badge */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
  font-size: 13px; font-weight: 500; color: var(--ink-2); transition: .2s; white-space: nowrap;
}
.chip:hover { color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.chip.is-on { background: var(--ink); color: #fff; box-shadow: none; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  background: var(--soft); color: var(--ink-2);
}
.badge-dark { background: var(--ink); color: #fff; }
.badge-accent { background: var(--accent); color: var(--accent-ink); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-glass { background: rgba(255, 255, 255, .88); color: var(--ink); backdrop-filter: blur(8px); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot-live { background: #62c23a; box-shadow: 0 0 0 0 rgba(98, 194, 58, .6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(98, 194, 58, .55); } 70% { box-shadow: 0 0 0 7px rgba(98, 194, 58, 0); } 100% { box-shadow: 0 0 0 0 rgba(98, 194, 58, 0); } }

/* form */
.field { display: grid; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 46px; padding: 0 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); outline: none; transition: .2s;
  font-size: 14.5px;
}
.textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%237b7d75' stroke-width='1.8' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--ink); background: var(--surface); box-shadow: 0 0 0 4px rgba(15, 16, 13, .06); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check input { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 0; border-radius: 7px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); cursor: pointer; flex: none; transition: .2s var(--ease); }
.check input:checked { background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d8f15d' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 13px no-repeat; box-shadow: none; }
.check input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input[type='number'] { -moz-appearance: textfield; appearance: textfield; }
input[type='number']::-webkit-outer-spin-button, input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* avatar */
.av {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--accent-2); color: var(--accent-ink);
}
.av-stack { display: flex; }
.av-stack > * { margin-left: -9px; box-shadow: 0 0 0 2px var(--surface); }
.av-stack > *:first-child { margin-left: 0; }

/* toast */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 9999; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px 12px 12px; border-radius: 16px;
  background: var(--ink); color: #fff; font-size: 14px; box-shadow: var(--shadow-lg); pointer-events: auto;
  animation: toastIn .45s var(--ease) both;
}
.toast .t-ico { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.toast.out { animation: toastOut .3s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* tendine su misura (assets/js/ui.js) */
.dd-native { display: none !important; }
.dd-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; cursor: pointer; }
.dd-trigger.select { background-image: none; padding-right: 14px; }
.dd-trigger.select.is-open { border-color: var(--ink); background: var(--surface); box-shadow: 0 0 0 4px rgba(15, 16, 13, .06); }
.dd-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-label.is-ph { color: var(--muted); }
.dd-chev { flex: none; color: var(--muted); transition: transform .3s var(--ease); }
.dd-trigger.is-open .dd-chev { transform: rotate(180deg); color: var(--ink); }
.dd-panel {
  position: fixed; z-index: 9000; display: flex; flex-direction: column; padding: 6px; max-width: calc(100vw - 16px);
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-radius: 20px; box-shadow: 0 2px 6px rgba(15, 16, 13, .06), 0 28px 70px -18px rgba(15, 16, 13, .32), inset 0 0 0 1px rgba(15, 16, 13, .07);
  transform-origin: top left; animation: ddIn .26s var(--ease) both;
}
.dd-panel.up { transform-origin: bottom left; animation-name: ddInUp; }
.dd-panel.out { animation: ddOut .14s ease both; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
@keyframes ddInUp { from { opacity: 0; transform: translateY(6px) scale(.97); } }
@keyframes ddOut { to { opacity: 0; transform: scale(.98); } }
.dd-search { display: flex; align-items: center; gap: 8px; flex: none; height: 42px; padding: 0 12px; margin-bottom: 4px; border-radius: 14px; background: var(--surface-2); color: var(--muted); cursor: text; }
.dd-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 14px; color: var(--ink); }
.dd-list { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; display: grid; gap: 1px; }
.dd-opt { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 42px; padding: 7px 8px 7px 12px; border-radius: 13px; text-align: left; font-size: 14px; color: var(--ink-2); transition: background .15s, color .15s; animation: ddOpt .3s var(--ease) both; }
.dd-opt:nth-child(2) { animation-delay: 15ms; } .dd-opt:nth-child(3) { animation-delay: 30ms; } .dd-opt:nth-child(4) { animation-delay: 45ms; } .dd-opt:nth-child(5) { animation-delay: 60ms; } .dd-opt:nth-child(n+6) { animation-delay: 75ms; }
@keyframes ddOpt { from { opacity: 0; transform: translateX(-4px); } }
.dd-opt.is-active { background: var(--surface-2); color: var(--ink); }
.dd-opt:disabled { opacity: .4; cursor: default; }
.dd-opt img { width: 40px; height: 40px; border-radius: 11px; object-fit: cover; flex: none; }
.dd-txt { flex: 1; min-width: 0; }
.dd-txt b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-txt small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-opt.is-sel { color: var(--ink); }
.dd-opt.is-sel b { font-weight: 650; }
.dd-opt.is-ph b { color: var(--muted); }
.dd-check { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent); color: var(--accent-ink); opacity: 0; transform: scale(.5); transition: .25s var(--ease); }
.dd-opt.is-sel .dd-check { opacity: 1; transform: none; }
.dd-empty { padding: 14px 12px; font-size: 13px; color: var(--muted); margin: 0; }

/* calendario su misura */
.dp-panel { width: 296px; padding: 12px; }
.dp-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-h b { font-size: 14px; font-weight: 600; text-transform: capitalize; }
.dp-h button { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); }
.dp-h button:hover { background: var(--surface-2); }
.dp-g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-g span { font-size: 10.5px; font-weight: 600; color: var(--faint); padding-bottom: 4px; }
.dp-g button { height: 34px; border-radius: 10px; font-size: 13px; color: var(--ink-2); transition: background .15s; }
.dp-g button:hover { background: var(--surface-2); }
.dp-g .is-today { box-shadow: inset 0 0 0 1px var(--line-2); }
.dp-g .is-sel, .dp-g .is-sel:hover { background: var(--ink); color: #fff; }

/* conferma inline (al posto di confirm()) */
.confirm-pop { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px; background: #fde9e5; color: var(--danger); font-size: 13px; font-weight: 550; animation: ddIn .25s var(--ease) both; }
.confirm-pop .btn { height: 32px; }

.osm-gray { filter: grayscale(1) contrast(.92) brightness(1.06); }

/* leaflet ritocchi */
.leaflet-tooltip { background: var(--ink); color: #fff; border: 0; border-radius: 10px; padding: 6px 10px; font: 500 12px/1.3 var(--font); box-shadow: 0 8px 24px -6px rgba(15, 16, 13, .4); }
.leaflet-tooltip-top::before { border-top-color: var(--ink); }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--ink); }
.leaflet-tooltip-left::before { border-left-color: var(--ink); }
.leaflet-tooltip-right::before { border-right-color: var(--ink); }
.leaflet-container { font-family: var(--font); background: #eceee8; }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, .7) !important; border-radius: 8px 0 0 0; }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bar { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 14px !important; overflow: hidden; }
.leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 36px !important; color: var(--ink) !important; border-color: var(--line) !important; }
.leaflet-div-icon { background: none; border: 0; }

/* scrollbar sottile */
.thin-scroll { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.thin-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.thin-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
