/* Q-Max Profit · Gestionale desktop */
:root {
  --navy: #1A2C46;
  --navy-2: #24466F;
  --navy-3: #2F5487;
  --primary: #2F5487;
  --primary-h: #24466F;
  --bg: #F4F6F9;
  --bg-2: #E9EEF4;
  --card: #FFFFFF;
  --border: #DDE3EA;
  --muted-bg: #EEF1F5;
  --text: #0E1B2C;
  --muted: #4F5F73;
  --amber-bg: #FFF4E0;
  --amber: #6B4000;
  --red: #8A1C12;
  --red-bg: #FDECEA;
  --green-bg: #E8EDF4; /* verde riservato a WhatsApp: qui blu chiaro */
  --green: #24466F;
  --silver: #C9CED7;
  --shadow: 0 1px 2px rgba(22, 35, 58, .05), 0 4px 16px rgba(22, 35, 58, .06);
  --shadow-lg: 0 20px 60px rgba(22, 35, 58, .22);
  --r: 14px;
  --r-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--text); font-size: 14px; line-height: 1.45;
  background: radial-gradient(1200px 700px at 15% 0%, #F4F7FA 0%, transparent 60%), linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed; -webkit-font-smoothing: antialiased; min-width: 1000px;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  background: linear-gradient(155deg, #13203A 0%, var(--navy) 55%, #24466F 100%); color: #fff;
  padding: 56px 64px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.login-hero::after { content: ''; position: absolute; inset: 0; background: radial-gradient(600px 400px at 80% 20%, rgba(201, 207, 216, .12), transparent 70%); pointer-events: none; }
.login-hero .brand { display: flex; align-items: center; gap: 14px; }
.login-hero .brand img { width: 52px; height: 52px; }
.login-hero h1 { font-size: 46px; font-weight: 800; line-height: 1.05; margin-top: 18px; }
.login-hero .claim { font-size: 18px; color: #B9C4D6; margin-top: 12px; }
.login-hero ul { list-style: none; padding: 0; margin: 32px 0 0; color: #D6DEEA; }
.login-hero li { padding: 8px 0; display: flex; gap: 10px; align-items: center; }
.login-hero li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--silver); flex: none; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 34px; }
.login-card h2 { font-size: 22px; }
.demo-hint { background: var(--muted-bg); border-radius: var(--r-sm); padding: 12px 14px; font-size: 12.5px; color: var(--muted); margin-top: 18px; }
.demo-hint b { color: var(--text); }
.demo-hint button { margin-top: 8px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, #16243C 0%, var(--navy) 100%); color: #D3DBE7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 18px; border-bottom: 1px solid rgba(255, 255, 255, .07); }
.sb-brand img { width: 36px; height: 36px; }
.sb-brand .t1 { color: #fff; font-weight: 700; font-size: 15px; }
.sb-brand .t2 { font-size: 11px; color: #95A3B9; letter-spacing: .06em; text-transform: uppercase; }
.sb-nav { padding: 12px 10px; flex: 1; overflow: auto; }
.sb-nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: #C3CDDB; text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.sb-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sb-nav a.active { background: rgba(255, 255, 255, .11); color: #fff; }
.sb-nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.sb-nav .count { margin-left: auto; font-size: 11px; background: rgba(255, 255, 255, .12); border-radius: 99px; padding: 1px 8px; }
.sb-nav .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7E8CA3; padding: 14px 12px 6px; }
.sb-user { padding: 14px; border-top: 1px solid rgba(255, 255, 255, .07); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(145deg, #DDE2E9, #9AA5B4); color: var(--navy); font-weight: 700; display: grid; place-items: center; font-size: 12.5px; flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.sb-user .n { color: #fff; font-weight: 600; font-size: 13px; }
.sb-user .r { font-size: 11px; color: #95A3B9; }
.sb-user button { margin-left: auto; background: transparent; border: 1px solid rgba(255, 255, 255, .15); color: #C3CDDB; border-radius: 8px; padding: 5px 8px; cursor: pointer; font-size: 12px; }
.sb-user button:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 28px; position: sticky; top: 0; z-index: 20; background: rgba(238, 242, 246, .86); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(227, 232, 239, .8); }
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.search { position: relative; width: 300px; }
.search input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 360px; overflow: auto; z-index: 40; padding: 6px; }
.search-results .it { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.search-results .it:hover, .search-results .it.sel { background: var(--muted-bg); }
.content { padding: 24px 28px 48px; }

/* ---------- elements ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { font-size: 15px; font-weight: 700; }
.card-b { padding: 16px 18px 18px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g-main { grid-template-columns: 1.6fr 1fr; }
.kpi { padding: 18px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.dark { background: linear-gradient(150deg, var(--navy) 0%, var(--navy-3) 100%); color: #fff; border-color: transparent; }
.kpi.dark .l, .kpi.dark .s { color: #AEBAD0; }
.kpi.amber { background: var(--amber-bg); border-color: #F3E2B6; }
.kpi.amber .v { color: var(--amber); }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--muted-bg); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--red); border-color: #EBC9C0; }
.btn.danger:hover { background: var(--red-bg); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted-bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn svg { width: 15px; height: 15px; }
.icon-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: transparent; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--muted-bg); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--muted-bg); color: #44516A; white-space: nowrap; }
.pill.demo { background: rgba(255, 255, 255, .9); color: var(--navy); font-size: 10px; letter-spacing: .06em; padding: 1px 7px; border-radius: 5px; border: 1px solid var(--border); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: #E3EBF5; color: var(--primary); }
.pill.navy { background: var(--navy); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* tables */
.table-wrap { overflow: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: #FAFBFC; position: sticky; top: 0; white-space: nowrap; }
.t th.sortable { cursor: pointer; user-select: none; }
.t th.sortable:hover { color: var(--text); }
.t td { padding: 11px 14px; border-bottom: 1px solid #EEF1F5; vertical-align: middle; }
.t tr:last-child td { border-bottom: none; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover td { background: #F7F9FB; }
.t .strong { font-weight: 600; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* filters */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.input, select.input, textarea.input { padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px; background: #fff; min-width: 0; }
.input:focus, select.input:focus, textarea.input:focus, .search input:focus { outline: none; border-color: #9DB2CF; box-shadow: 0 0 0 3px rgba(47, 84, 135, .14); }
textarea.input { resize: vertical; min-height: 80px; }

/* bars */
.bar-row { margin-bottom: 14px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; gap: 10px; }
.bar { height: 8px; background: var(--muted-bg); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .5s ease; }
.bar.thin { height: 6px; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid #F0F2F6; font-size: 13px; }
.feed li:last-child { border-bottom: none; }
.feed .when { color: var(--muted); font-size: 11.5px; white-space: nowrap; margin-left: auto; padding-left: 8px; }
.note { border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.note.amber { background: var(--amber-bg); color: var(--amber); }
.note.red { background: var(--red-bg); color: var(--red); }
.note.green { background: var(--green-bg); color: var(--green); }
.note.muted { background: var(--muted-bg); color: #44516A; }
.note.navy { background: var(--navy); color: #E3E9F2; }

/* kanban */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 14px; align-items: start; }
.kcol { background: rgba(255, 255, 255, .55); border: 1px solid var(--border); border-radius: var(--r); padding: 10px; min-height: 300px; transition: background .15s, border-color .15s; }
.kcol.over { background: #E3EBF5; border-color: #9DB2CF; }
.kcol-h { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; font-weight: 700; font-size: 13px; }
.kcol-h .tot { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; margin-bottom: 9px; cursor: grab; box-shadow: 0 1px 2px rgba(22, 35, 58, .04); }
.kcard:hover { border-color: #C9D4E3; }
.kcard.dragging { opacity: .45; }
.kcard .c { font-weight: 600; }
.kcard .m { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.kcard .nums { display: flex; justify-content: space-between; margin-top: 9px; font-size: 12px; gap: 6px; }
.kcard .eur { background: var(--muted-bg); border-radius: 7px; padding: 2px 7px; font-weight: 700; }

/* modal + drawer */
.overlay { position: fixed; inset: 0; background: rgba(16, 26, 44, .42); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 20px; overflow: auto; animation: fade .15s ease; }
.modal { background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; animation: pop .18s ease; }
.modal.wide { max-width: 880px; }
.modal.narrow { max-width: 440px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-h h3 { font-size: 17px; }
.modal-b { padding: 20px 22px; max-height: 68vh; overflow: auto; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; background: #FAFBFC; border-radius: 0 0 16px 16px; }
.drawer-ov { position: fixed; inset: 0; background: rgba(16, 26, 44, .32); z-index: 90; animation: fade .15s ease; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 92vw); background: var(--bg); z-index: 91; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease; }
.drawer-h { background: var(--navy); color: #fff; padding: 20px 22px; display: flex; gap: 12px; align-items: flex-start; }
.drawer-h h2 { font-size: 20px; }
.drawer-h .sub { color: #AEBAD0; font-size: 12.5px; margin-top: 3px; }
.drawer-h .icon-btn { color: #C3CDDB; }
.drawer-h .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.drawer-b { padding: 18px 22px 30px; overflow: auto; flex: 1; }
.drawer-b .card + .card { margin-top: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

/* forms */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form .full { grid-column: 1 / -1; }
.form .f3 { grid-column: span 1; }
.field label { display: block; font-size: 12px; font-weight: 600; color: #44516A; margin-bottom: 5px; }
.field .input { width: 100%; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.field.err .input { border-color: var(--red); }
.field .errm { font-size: 11.5px; color: var(--red); margin-top: 4px; }
.fieldset { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 14px; margin-top: 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 13px; background: #fff; user-select: none; }
.check input { margin: 0; accent-color: var(--primary); }
.check.on { border-color: #9DB2CF; background: #F1F5FA; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #CBD3DE; border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }
.seg { display: inline-flex; background: var(--muted-bg); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* prodotti editor */
.prod-row { display: grid; grid-template-columns: 2fr 1fr .8fr 1fr 32px; gap: 8px; margin-bottom: 8px; align-items: center; }
.righe-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 32px; gap: 8px; margin-bottom: 8px; align-items: center; }

/* estratto verify */
.vrow { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid #EEF1F5; }
.vrow:last-child { border-bottom: none; }
.letter { white-space: pre-wrap; font-size: 13px; line-height: 1.55; background: #FAFBFC; border: 1px solid var(--border); border-radius: 12px; padding: 16px; font-family: var(--font); width: 100%; min-height: 260px; }

/* mandante card */
.mcard { padding: 18px; position: relative; overflow: hidden; }
.mcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--mc, var(--primary)); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }
.sim { background: var(--muted-bg); border-radius: 12px; padding: 14px; }
.sim .big { font-size: 22px; font-weight: 800; }

/* toast */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 14px; font-size: 13.5px; animation: pop .2s ease; min-width: 260px; }
.toast.err { background: var(--red); }
.toast button { background: rgba(255, 255, 255, .15); border: none; color: #fff; border-radius: 8px; padding: 5px 10px; cursor: pointer; font-weight: 600; margin-left: auto; }
.toast button:hover { background: rgba(255, 255, 255, .25); }

.section-title { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.section-title h2 { font-size: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button { border: none; background: transparent; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); }
.footer-note { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 30px; }

@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g-main { grid-template-columns: 1fr; }
  .search { width: 220px; }
  .login-wrap { grid-template-columns: 1fr 1fr; }
  .login-hero { padding: 40px; }
  .login-hero h1 { font-size: 36px; }
}
