:root {
  --bg-ivory: #fffbf5;
  --bg-cream: #fdf3e6;
  --glass: rgba(255, 255, 255, 0.88);
  --glass-border: rgba(235, 198, 160, 0.55);
  --text-main: #2b1f18;
  --text-muted: #755f52;
  --neon-gold: #ff9f1c;
  --neon-coral: #ff5d73;
  --neon-magenta: #e83f6f;
  --neon-emerald: #10b981;
  --shadow-warm: 0 12px 32px rgba(154, 92, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  color: var(--text-main);
  background: linear-gradient(135deg, var(--bg-ivory) 0%, var(--bg-cream) 100%);
  overflow-x: hidden;
}

h1, h2, h3 { font-family: "Outfit", system-ui, sans-serif; margin: 0; }
.small { font-size: 0.84rem; }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }
.sr-hidden { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Sfondo animato Light Caldo */
.ambient-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.45;
  animation: floatBlob 18s ease-in-out infinite alternate;
}
.blob-1 { width: 460px; height: 460px; background: #ffd8a8; top: -120px; left: -80px; }
.blob-2 { width: 420px; height: 420px; background: #ffd1dc; bottom: -140px; right: -80px; animation-delay: -6s; }
.blob-3 { width: 340px; height: 340px; background: #ffeec2; top: 38%; left: 42%; animation-delay: -11s; }

@keyframes floatBlob {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(28px, -24px) scale(1.08); }
}

.glass-card {
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-warm);
}

/* Luci Neon Calde */
.neon-gold { border-color: rgba(255, 159, 28, 0.55); box-shadow: 0 8px 28px rgba(255, 159, 28, 0.18), inset 0 0 18px rgba(255, 159, 28, 0.06); }
.neon-coral { border-color: rgba(255, 93, 115, 0.52); box-shadow: 0 8px 28px rgba(255, 93, 115, 0.18), inset 0 0 18px rgba(255, 93, 115, 0.05); }
.neon-coral-soft { border-color: rgba(255, 93, 115, 0.42); box-shadow: 0 8px 24px rgba(255, 93, 115, 0.13); }
.neon-magenta { border-color: rgba(232, 63, 111, 0.5); box-shadow: 0 8px 28px rgba(232, 63, 111, 0.16), inset 0 0 18px rgba(232, 63, 111, 0.05); }
.neon-emerald { border-color: rgba(16, 185, 129, 0.5); box-shadow: 0 8px 28px rgba(16, 185, 129, 0.16), inset 0 0 18px rgba(16, 185, 129, 0.05); }

/* Layout Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { position: relative; z-index: 2; width: 100%; max-width: 410px; padding: 32px; }
.login-badge {
  display: inline-block; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.06em;
  color: #b45309; background: #fff3db; border: 1px solid #ffd48a; padding: 4px 10px; border-radius: 999px; margin-bottom: 12px;
}
.login-card h1 { font-size: 1.7rem; margin-bottom: 8px; }
.field-label { display: block; font-size: 0.82rem; font-weight: 600; margin: 14px 0 6px; color: var(--text-muted); }
.login-err { color: #dc2626; font-size: 0.86rem; font-weight: 600; margin-top: 10px; min-height: 20px; }

/* App Shell */
.app-shell { position: relative; z-index: 1; display: grid; grid-template-columns: 268px 1fr; gap: 18px; padding: 16px; min-height: 100vh; }

/* Sidebar */
.sidebar {
  position: sticky; top: 16px; height: calc(100vh - 32px); display: flex; flex-direction: column;
  padding: 16px 14px; overflow-y: auto;
}
.brand-box { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; border-bottom: 1px solid rgba(226, 188, 148, 0.45); }
.brand-logo {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem;
  background: linear-gradient(135deg, #ff9f1c, #ff5d73); color: #fff;
  box-shadow: 0 0 18px rgba(255, 159, 28, 0.45);
}
.brand-title { font-family: "Outfit", sans-serif; font-weight: 800; font-size: 1.1rem; }
.brand-sub { font-size: 0.76rem; color: var(--text-muted); }

.nav-list { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid transparent; background: transparent;
  padding: 10px 12px; border-radius: 12px; cursor: pointer; font-size: 0.91rem; font-weight: 600;
  color: var(--text-main); text-align: left; transition: all 0.22s ease;
}
.nav-item:hover { background: rgba(255, 240, 220, 0.75); transform: translateX(3px); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(255, 159, 28, 0.20), rgba(255, 93, 115, 0.12));
  border-color: rgba(255, 159, 28, 0.65);
  box-shadow: 0 0 18px rgba(255, 159, 28, 0.28);
  color: #7c2d12;
}

.sidebar-divider { height: 1px; background: rgba(226, 188, 148, 0.45); margin: 14px 0; }
.preset-title { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  border: 1px solid rgba(224, 178, 130, 0.7); background: #fff9f0; color: var(--text-main);
  padding: 5px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.chip-btn:hover, .chip-btn.active {
  background: #ff9f1c; color: #fff; border-color: #ff9f1c;
  box-shadow: 0 0 14px rgba(255, 159, 28, 0.45);
}

.sidebar-footer { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid rgba(226, 188, 148, 0.4); }
.footer-link { font-size: 0.8rem; color: #b45309; text-decoration: none; font-weight: 600; }
.footer-link:hover { text-decoration: underline; }

/* Main & Topbar */
.main-wrap { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { font-size: 1.35rem; }
.topbar-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  font-size: 0.79rem; font-weight: 700; border: 1px solid transparent;
}
.pill-emerald { background: #ecfdf5; color: #065f46; border-color: rgba(16, 185, 129, 0.45); box-shadow: 0 0 12px rgba(16, 185, 129, 0.18); }
.pill-amber { background: #fffbeb; color: #92400e; border-color: rgba(255, 159, 28, 0.5); box-shadow: 0 0 12px rgba(255, 159, 28, 0.18); }
.pill-coral { background: #fff1f2; color: #9f1239; border-color: rgba(255, 93, 115, 0.5); box-shadow: 0 0 12px rgba(255, 93, 115, 0.22); }

.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neon-emerald); box-shadow: 0 0 8px var(--neon-emerald); animation: pulseDot 2s infinite; }
@keyframes pulseDot { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.4); opacity: 0.65; } }

/* Inputs & Buttons */
input, select {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid rgba(214, 174, 138, 0.75);
  background: #fffdf9; color: var(--text-main); font-family: inherit; font-size: 0.88rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus { outline: none; border-color: var(--neon-gold); box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.22); }

.btn {
  border: 1px solid transparent; border-radius: 11px; padding: 9px 15px; font-family: inherit; font-weight: 700;
  font-size: 0.86rem; cursor: pointer; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 6px;
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-neon-gold { background: linear-gradient(135deg, #ff9f1c, #f97316); color: #fff; box-shadow: 0 4px 16px rgba(255, 159, 28, 0.42); }
.btn-neon-gold:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(255, 159, 28, 0.58); }
.btn-neon-emerald { background: linear-gradient(135deg, #10b981, #059669); color: #fff; box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35); }
.btn-neon-coral { background: linear-gradient(135deg, #ff5d73, #e11d48); color: #fff; box-shadow: 0 4px 16px rgba(255, 93, 115, 0.40); }
.btn-neon-magenta { background: linear-gradient(135deg, #e83f6f, #db2777); color: #fff; box-shadow: 0 4px 16px rgba(232, 63, 111, 0.40); }
.btn-soft { background: #fff4e5; border-color: rgba(235, 182, 128, 0.7); color: var(--text-main); }
.btn-soft:hover { background: #ffe8c8; }
.btn-ghost-sm { background: transparent; border: 1px solid rgba(200, 160, 128, 0.5); border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 0.78rem; color: var(--text-muted); }
.icon-btn { background: #fff5e6; border: 1px solid var(--glass-border); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 700; }

/* Panels & Animations */
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; animation: fadeSlideUp 0.28s ease; }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 14px 18px; }
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 140px; flex: 1; }
.filter-group label { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.filter-actions { display: flex; gap: 8px; align-items: center; }
.toggle-inline { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.86rem; font-weight: 600; padding: 8px 4px; }
.toggle-inline input { width: auto; }

/* KPI Grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi-card { padding: 16px 18px; transition: transform 0.22s ease; }
.kpi-card:hover { transform: translateY(-2px); }
.kpi-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-family: "Outfit", sans-serif; font-size: 1.9rem; font-weight: 800; margin: 6px 0 4px; }
.kpi-foot { font-size: 0.78rem; color: var(--text-muted); }

/* Charts & Tables */
.charts-2col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card, .table-card { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { font-size: 1.04rem; }
.chart-box { position: relative; height: 295px; width: 100%; }
.search-input { max-width: 260px; }

.table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  position: sticky; top: 0; background: #fff3e2; color: #5c371c; font-weight: 700; text-align: left;
  padding: 10px 10px; border-bottom: 2px solid #f2cfa6; white-space: nowrap; z-index: 1;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid rgba(235, 200, 168, 0.45); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(255, 244, 226, 0.7); }

/* Heatmap */
.heatmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.heat-cell {
  border-radius: 14px; padding: 11px 12px; border: 1px solid transparent; transition: transform 0.2s;
}
.heat-cell:hover { transform: translateY(-2px); }
.heat-ok { background: #ecfdf5; border-color: rgba(16, 185, 129, 0.45); box-shadow: 0 0 12px rgba(16, 185, 129, 0.14); }
.heat-warn { background: #fffbeb; border-color: rgba(255, 159, 28, 0.5); box-shadow: 0 0 12px rgba(255, 159, 28, 0.14); }
.heat-crit { background: #fff1f2; border-color: rgba(255, 93, 115, 0.55); box-shadow: 0 0 12px rgba(255, 93, 115, 0.18); }
.legend-inline { display: flex; gap: 10px; font-size: 0.78rem; font-weight: 700; }
.dot-leg { padding: 3px 9px; border-radius: 999px; }
.leg-ok { background: #d1fae5; color: #065f46; }
.leg-warn { background: #fef3c7; color: #92400e; }
.leg-crit { background: #ffe4e6; color: #9f1239; }

/* Calendar */
.calendar-split { grid-template-columns: 1.35fr 1fr; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; font-size: 0.76rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  min-height: 76px; border-radius: 12px; padding: 6px; border: 1px solid rgba(232, 196, 162, 0.45);
  background: rgba(255, 255, 255, 0.65); display: flex; flex-direction: column; justify-content: space-between;
  transition: all 0.2s;
}
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.has-data { cursor: pointer; border-color: rgba(255, 159, 28, 0.55); background: #fff8ed; }
.cal-cell.has-data.lvl-2 { background: #ffeed6; box-shadow: 0 0 12px rgba(255, 159, 28, 0.22); }
.cal-cell.has-data.lvl-3 { background: #ffe0c2; border-color: var(--neon-coral); box-shadow: 0 0 14px rgba(255, 93, 115, 0.24); }
.cal-cell.has-data:hover, .cal-cell.selected { transform: scale(1.03); border-color: var(--neon-magenta); box-shadow: 0 0 18px rgba(232, 63, 111, 0.35); }
.cal-day-num { font-weight: 800; font-size: 0.85rem; }
.cal-day-metrics { font-size: 0.71rem; line-height: 1.25; font-weight: 700; color: #7c2d12; }
.day-detail-body { display: flex; flex-direction: column; gap: 10px; }

/* Magazzino & Badges */
.priority-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; flex-wrap: wrap; }
.badge-neon { display: inline-block; font-size: 0.74rem; font-weight: 800; color: #9a3412; background: #ffedd5; border: 1px solid #fb923c; border-radius: 999px; padding: 3px 10px; margin-bottom: 4px; }
.badge-soft { display: inline-block; font-size: 0.76rem; font-weight: 700; background: #fff3db; color: #92400e; padding: 4px 10px; border-radius: 999px; }
.subtab-bar { display: flex; gap: 8px; }
.subtab-btn { padding: 7px 14px; border-radius: 10px; border: 1px solid var(--glass-border); background: #fff8ee; font-weight: 700; cursor: pointer; }
.subtab-btn.active { background: var(--neon-gold); color: #fff; border-color: var(--neon-gold); box-shadow: 0 0 14px rgba(255, 159, 28, 0.35); }

.info-banner, .info-banner-inline {
  padding: 12px 16px; border-radius: 12px; background: #fff4e0; border: 1px solid #f7c782; color: #7c3b12; font-size: 0.86rem; font-weight: 600;
}

/* Forms, Rules, Campaigns */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid-1 { display: flex; flex-direction: column; gap: 12px; }
.form-span-2 { grid-column: span 2; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.rules-grid, .campaigns-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.rule-box { background: #fff9f0; border: 1px solid rgba(235, 198, 160, 0.6); border-radius: 14px; padding: 14px; }
.campaign-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.checks-wrap { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; background: #fffaf2; border: 1px solid rgba(235, 198, 160, 0.55); border-radius: 12px; }
.check-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; padding: 3px 8px; background: #fff; border: 1px solid #ebd1b4; border-radius: 8px; cursor: pointer; }
.check-chip input { width: auto; }
.check-group { display: flex; flex-direction: column; gap: 4px; }
.preview-pre { background: #2b1f18; color: #fef3c7; padding: 12px; border-radius: 12px; font-size: 0.78rem; overflow-x: auto; max-height: 240px; }

/* Bot */
.bot-panel { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.bot-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bot-messages { display: flex; flex-direction: column; gap: 10px; min-height: 240px; max-height: 430px; overflow-y: auto; padding: 10px; background: #fffaf3; border: 1px solid rgba(235, 198, 160, 0.55); border-radius: 14px; }
.bot-msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; font-size: 0.88rem; line-height: 1.48; white-space: pre-wrap; }
.bot-user { align-self: flex-end; background: linear-gradient(135deg, #ff9f1c, #f97316); color: #fff; font-weight: 600; }
.bot-assistant { align-self: flex-start; background: #ffffff; border: 1px solid #f3d6b6; }
.bot-input-row { display: flex; gap: 10px; }
.bot-input-row input { flex: 1; }

.floating-bot-btn {
  position: fixed; right: 22px; bottom: 22px; z-index: 40; border: 0; border-radius: 999px;
  padding: 12px 18px; font-family: inherit; font-weight: 800; font-size: 0.9rem; cursor: pointer;
  background: linear-gradient(135deg, #e83f6f, #ff9f1c); color: #fff;
  box-shadow: 0 8px 26px rgba(232, 63, 111, 0.42);
}
.bot-drawer {
  position: fixed; right: 22px; bottom: 76px; width: min(400px, calc(100vw - 32px)); z-index: 45;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.drawer-msgs { min-height: 200px; max-height: 280px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: #2b1f18; color: #fffbf5; padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 0.88rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.mobile-only { display: none; }

@media (max-width: 1120px) {
  .kpi-grid, .kpi-grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-2col, .calendar-split, .rules-grid, .campaigns-grid { grid-template-columns: 1fr; }
}
@media (max-width: 840px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed; left: -300px; top: 10px; bottom: 10px; width: 272px; z-index: 50;
    height: auto; transition: left 0.25s ease;
  }
  .sidebar.open { left: 10px; }
  .form-grid, .form-grid-2 { grid-template-columns: 1fr; }
  .form-span-2 { grid-column: span 1; }
}
@media (prefers-reduced-motion: reduce) {
  .blob, .pulse-dot, .tab-panel.active { animation: none !important; }
}
