/* =====================================================================
   CARAMIA LEAD CRM — stile
   Bianco · Fucsia CaramiaLab (solo accenti) · Grigio scuro · Grigi chiari
   ===================================================================== */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --text: #17171c;
  --text-2: #4a4a55;
  --muted: #8a8a96;
  --border: #e7e7ec;
  --border-strong: #d6d6de;
  --accent: #d4176f;
  --accent-hover: #b8105f;
  --accent-soft: #fdebf3;
  --accent-ink: #9d0d50;
  --dark: #1c1c22;
  --red: #dc2626;   --red-soft: #fdecec;
  --orange: #e67e0a; --orange-soft: #fff3e3;
  --green: #16a34a; --green-soft: #e8f7ee;
  --grey: #8e8e99;  --grey-soft: #f0f0f3;
  --blue: #2563eb;  --blue-soft: #eaf1fe;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 2px 10px rgba(20, 20, 30, .04);
  --shadow-lg: 0 20px 60px rgba(20, 20, 30, .18);
  --sidebar: 248px;
  --sidebar-collapsed: 76px;
  --topbar: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
.num, .money, td.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
body.role-viewer .admin-only { display: none !important; }

/* ---------- boot / login ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.boot-logo, .brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 22px; margin: 0 auto;
}
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 32px; }
.auth-card h1 { font-size: 22px; margin: 16px 0 4px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 40;
  transition: width .2s ease, transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; min-height: var(--topbar); }
.brand-mark { margin: 0; width: 38px; height: 38px; font-size: 19px; flex: none; }
.brand-text { line-height: 1.1; overflow: hidden; white-space: nowrap; }
.brand-text strong { display: block; font-size: 14px; letter-spacing: .02em; }
.brand-text span { font-size: 12px; color: var(--muted); }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 12px 6px; white-space: nowrap; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; text-decoration: none; min-height: 44px; white-space: nowrap;
}
.nav a svg { flex: none; width: 20px; height: 20px; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.nav a.active svg { color: var(--accent); }
.nav .badge { margin-left: auto; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--dark); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-box .meta { overflow: hidden; white-space: nowrap; }
.user-box .meta strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.user-box .meta span { font-size: 12px; color: var(--muted); }
.foot-btn { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; border: 0; background: none; cursor: pointer; color: var(--text-2); min-height: 42px; white-space: nowrap; text-align: left; }
.foot-btn:hover { background: var(--bg); }
.foot-btn svg { width: 20px; height: 20px; flex: none; }

.main { flex: 1; margin-left: var(--sidebar); min-width: 0; transition: margin-left .2s ease; }
body.collapsed .sidebar { width: var(--sidebar-collapsed); }
body.collapsed .main { margin-left: var(--sidebar-collapsed); }
body.collapsed .brand-text, body.collapsed .nav-section, body.collapsed .nav a span,
body.collapsed .nav .badge, body.collapsed .user-box .meta, body.collapsed .foot-btn span { display: none; }
body.collapsed .nav a, body.collapsed .foot-btn { justify-content: center; }
body.collapsed .foot-btn .rot { transform: rotate(180deg); }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); background: rgba(255,255,255,.88);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 24px;
}
.btn.menu-toggle { display: none; }
.search { position: relative; flex: 1; max-width: 560px; }
.search input {
  width: 100%; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg);
  padding: 0 14px 0 40px; outline: none; font-size: 15px;
}
.search input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.search > svg { position: absolute; left: 13px; top: 11px; width: 20px; height: 20px; color: var(--muted); }
.search-results {
  position: absolute; top: 48px; left: 0; right: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); max-height: 70vh; overflow: auto; padding: 6px;
}
.search-results .sr-item { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; cursor: pointer; }
.search-results .sr-item:hover, .search-results .sr-item.focus { background: var(--bg); }
.search-results .sr-title { font-weight: 600; }
.search-results .sr-sub { font-size: 13px; color: var(--muted); }
.search-results .sr-head { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 10px 4px; }
.access-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 10px; border-radius: 999px; background: var(--grey-soft); color: var(--text-2); white-space: nowrap; }
.access-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.access-chip.viewer .dot { background: var(--blue); }

.demo-banner { background: repeating-linear-gradient(45deg, #fff3e3, #fff3e3 12px, #ffe8c8 12px, #ffe8c8 24px); color: #7a4300; text-align: center; font-weight: 700; font-size: 13px; padding: 6px 12px; letter-spacing: .03em; }
.page { padding: 24px; max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 26px; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--border-strong); background: #fff; color: var(--text); cursor: pointer;
  font-weight: 600; white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.dark { background: var(--dark); border-color: var(--dark); color: #fff; }
.btn.danger { color: var(--red); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn.lg { height: 50px; padding: 0 22px; font-size: 16px; }
.btn.icon { width: 42px; padding: 0; }
.btn.sm.icon { width: 34px; }
.btn.wa { background: #1faa55; border-color: #1faa55; color: #fff; }
.btn.wa:hover { background: #178f47; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); min-width: 0; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--border-strong); background: #fff;
  padding: 10px 12px; font-size: 15px; font-weight: 400; color: var(--text); outline: none;
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.money { text-align: right; font-variant-numeric: tabular-nums; }
.input.invalid { border-color: var(--red); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8a96' stroke-width='2' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-section { margin: 4px 0 18px; }
.form-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.segmented { display: inline-flex; background: var(--bg); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--text-2); min-height: 36px; }
.segmented button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 18px; }
.filters label.field { min-width: 150px; flex: 1 1 150px; max-width: 240px; }
.filters .input { min-height: 40px; padding: 8px 10px; }
.filters select.input { padding-right: 30px; }
.filter-note { font-size: 12px; color: var(--muted); margin: -10px 0 16px 4px; }

/* ---------- cards & KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 16px; }
.card-head .sub { font-size: 13px; color: var(--muted); }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 14px 18px 18px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 10px 2px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.section-title .tag { text-transform: none; letter-spacing: 0; font-weight: 500; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; text-align: left; min-height: 98px;
  position: relative; border-left: 4px solid var(--kpi-color, var(--border));
}
button.kpi { cursor: pointer; font: inherit; transition: transform .1s, box-shadow .1s; }
button.kpi:hover { box-shadow: 0 6px 20px rgba(20,20,30,.08); transform: translateY(-1px); }
button.kpi::after { content: "›"; position: absolute; right: 14px; top: 10px; color: var(--muted); font-size: 20px; }
.kpi .label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .value.md { font-size: 22px; }
.kpi .foot { font-size: 12px; color: var(--muted); }
.kpi.red { --kpi-color: var(--red); } .kpi.red .value { color: var(--red); }
.kpi.orange { --kpi-color: var(--orange); } .kpi.orange .value { color: var(--orange); }
.kpi.green { --kpi-color: var(--green); }
.kpi.grey { --kpi-color: var(--grey); }
.kpi.accent { --kpi-color: var(--accent); }
.kpi.dark { --kpi-color: var(--dark); }
.kpi.blue { --kpi-color: var(--blue); }

.exec-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.exec { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; min-height: 150px; }
.exec .q { font-size: 14px; color: var(--text-2); font-weight: 600; }
.exec .a { overflow-wrap: anywhere; font-size: 34px; font-weight: 780; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.exec .d { font-size: 13px; color: var(--muted); margin-top: auto; }
.exec.hl { background: var(--dark); color: #fff; border-color: var(--dark); }
.exec.hl .q, .exec.hl .d { color: #c9c9d3; }
.exec.alert .a { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-lead { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; }
.empty-chart { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; letter-spacing: .01em; background: var(--grey-soft); color: var(--text-2); }
.pill .d { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.adv { background: var(--accent-soft); color: var(--accent-ink); }
.pill.dir { background: var(--blue-soft); color: #1d4ed8; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.orange { background: var(--orange-soft); color: #b45f06; }
.pill.green { background: var(--green-soft); color: #15803d; }
.pill.grey { background: var(--grey-soft); color: var(--text-2); }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.temp { font-size: 13px; white-space: nowrap; }

/* ---------- tables ---------- */
.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table-tools .input { min-height: 40px; max-width: 320px; }
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { color: var(--accent); }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #fcf7fa; }
table.data td.num, table.data th.num { text-align: right; }
table.data .strong { font-weight: 650; }
table.data .sub { font-size: 12px; color: var(--muted); }
table.data tfoot td { font-weight: 700; background: var(--surface-2); }
.table-foot { padding: 10px 14px; font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }

/* ---------- lead detail ---------- */
.lead-hero { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; padding: 20px; }
.lead-hero .who { flex: 1 1 320px; min-width: 0; }
.lead-hero h1 { font-size: 26px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.lead-hero .company { color: var(--text-2); margin-top: 4px; font-size: 16px; }
.lead-hero .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.lead-hero .contact-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 10px; flex: 1 1 360px; }
.hero-stat { background: var(--bg); border-radius: 12px; padding: 12px 14px; }
.hero-stat .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.hero-stat .v { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 2px; }
.status-select { font-weight: 700; border-radius: 999px; min-height: 36px; padding: 6px 34px 6px 14px; border: 2px solid var(--st, var(--border)); color: var(--st, var(--text)); background-color: #fff; }
dl.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 8px 14px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1 1 200px; min-width: 0; }
.list-item .li-title { font-weight: 650; }
.list-item .li-sub { font-size: 13px; color: var(--muted); }
.list-item .li-amount { font-weight: 750; font-variant-numeric: tabular-nums; font-size: 17px; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before { content: ""; position: absolute; left: -21px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--tl, var(--grey)); }
.tl-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; }
.tl-details { font-size: 13px; color: var(--text-2); white-space: pre-wrap; }

/* ---------- follow-up board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; border-top: 5px solid var(--col); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.col-head h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--col); }
.col-head .count { margin-left: auto; font-size: 22px; font-weight: 800; color: var(--col); font-variant-numeric: tabular-nums; }
.col-body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; }
.fu-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #fff; }
.fu-card .t { font-weight: 650; cursor: pointer; }
.fu-card .t:hover { color: var(--accent-ink); }
.fu-card .m { font-size: 13px; color: var(--muted); margin-top: 2px; }
.fu-card .n { font-size: 13px; color: var(--text-2); margin-top: 6px; white-space: pre-wrap; }
.fu-card .a { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.col.red { --col: var(--red); } .col.orange { --col: var(--orange); } .col.green { --col: var(--green); } .col.grey { --col: var(--grey); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 12px 14px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; min-height: 46px; }
.tabs button.on { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 28, .45); z-index: 100; display: grid; place-items: center; padding: 20px; animation: fade .15s ease; }
.modal { background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .18s ease; }
.modal.lg { max-width: 860px; }
.modal.xl { max-width: 1100px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 19px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 20px 22px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.dup-box { background: var(--orange-soft); border: 1px solid #f6d3a4; border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.dup-box h3 { color: #8a4a00; font-size: 16px; margin-bottom: 8px; }
.notice { background: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--text-2); }
.notice.warn { background: var(--orange-soft); color: #7a4300; }
.notice.accent { background: var(--accent-soft); color: var(--accent-ink); }
.computed { display: flex; gap: 10px; flex-wrap: wrap; }
.computed div { background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.computed b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- toast / popover ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--dark); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .2s ease; max-width: 90vw; }
.toast.error { background: var(--red); }
.toast.ok { background: #14532d; }
.popover { position: fixed; z-index: 150; background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 240px; max-width: 320px; }
.popover button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 11px 12px; border-radius: 9px; cursor: pointer; }
.popover button:hover { background: var(--bg); }
.popover .ph { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 12px 4px; }

.progress { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }
.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.steps span { padding: 6px 12px; border-radius: 999px; background: var(--bg); color: var(--muted); font-weight: 600; font-size: 13px; }
.steps span.on { background: var(--accent-soft); color: var(--accent-ink); }
.steps span.done { background: var(--green-soft); color: #15803d; }
.color-dot { width: 22px; height: 22px; border-radius: 6px; display: inline-block; vertical-align: middle; border: 1px solid rgba(0,0,0,.08); }
input[type=color].input { padding: 4px; height: 44px; }
.token-box { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--bg); padding: 12px; border-radius: 10px; overflow-wrap: anywhere; user-select: all; }

/* ---------- responsive: iPad landscape ---------- */
@media (max-width: 1280px) {
  .exec-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-lg { display: none !important; }
}
/* ---------- iPad portrait / small laptop ---------- */
@media (max-width: 1100px) {
  .grid-lead { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-md { display: none !important; }
}
@media (max-width: 1023px) {
  :root { --sidebar: 280px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(20,20,28,.35); z-index: 35; }
  .main, body.collapsed .main { margin-left: 0; }
  body.collapsed .sidebar { width: var(--sidebar); }
  body.collapsed .brand-text, body.collapsed .nav-section, body.collapsed .nav a span, body.collapsed .nav .badge,
  body.collapsed .user-box .meta, body.collapsed .foot-btn span { display: revert; }
  body.collapsed .nav a, body.collapsed .foot-btn { justify-content: flex-start; }
  .collapse-btn { display: none !important; }
  .btn.menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .page { padding: 18px 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm-tab { display: none !important; }
}
/* ---------- phone ---------- */
@media (max-width: 760px) {
  .exec-grid, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .board { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 24px; }
  .access-chip span.txt { display: none; }
  .hide-sm { display: none !important; }
  .hero-stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal, .modal.lg, .modal.xl { max-width: none; border-radius: 20px 20px 0 0; max-height: 94vh; }
  /* tabelle → schede */
  table.data.cards thead { display: none; }
  table.data.cards, table.data.cards tbody, table.data.cards tr, table.data.cards td { display: block; width: 100%; }
  table.data.cards tr { border-bottom: 1px solid var(--border); padding: 8px 4px; }
  table.data.cards td { border: 0; padding: 4px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
  table.data.cards td.primary { font-size: 16px; text-align: left; display: block; }
  table.data.cards td.primary::before { content: none; }
  table.data.cards td.hide-sm { display: none !important; }
  table.data.cards tfoot { display: block; }
  .page-head h1 { font-size: 22px; }
  .dl-stack dl.kv { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- stampa ---------- */
@media print {
  .sidebar, .topbar, .filters, .page-head .actions, .table-tools, .demo-banner, .no-print, #toast-root { display: none !important; }
  .main { margin: 0 !important; }
  body { background: #fff; font-size: 11px; }
  .card { box-shadow: none; border: 0; }
  table.data th { position: static; }
  table.data td, table.data th { padding: 5px 6px; }
  .page { padding: 0; max-width: none; }
}
