/* CRM Gira — stile Flexo (stesse variabili --fx-* di app.flexoapp.es) */
:root {
  --fx-bg: #ffffff;
  --fx-panel: #f7f9fc;
  --fx-panel-soft: #eff6ff;
  --fx-border: #e2e8f0;
  --fx-border-strong: #cbd5e1;
  --fx-text: #0f172a;
  --fx-muted: #475569;
  --fx-faint: #64748b;
  --fx-accent: #2563eb;
  --fx-accent-dark: #1e40af;
  --fx-success: #16a34a; --fx-success-bg: #ecfdf5; --fx-success-text: #065f46;
  --fx-warning: #f59e0b; --fx-warning-bg: #fef3c7; --fx-warning-text: #92400e;
  --fx-danger: #dc2626;  --fx-danger-bg: #fee2e2;  --fx-danger-text: #991b1b;
  --fx-info-bg: #dbeafe; --fx-info-text: #1e40af;
  --fx-violet-bg: #ede9fe; --fx-violet-text: #5b21b6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fx-bg); color: var(--fx-text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--fx-accent); }
h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--fx-faint); margin: 0; }
.small { font-size: .85rem; }

/* Icone a linea */
.ic { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ic svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Marchio */
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 4px 18px; }
.brand-mark { background: #0f172a; color: #fff; font-weight: 800; letter-spacing: .14em; font-size: .82rem; padding: 6px 10px; border-radius: 10px; }
.brand-sub { font-weight: 700; color: var(--fx-text); }
.brand-lg { justify-content: center; padding-bottom: 8px; }
.brand-lg .brand-mark { font-size: 1rem; padding: 8px 14px; }

/* Bottoni e campi */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--fx-border-strong); background: #fff; color: var(--fx-text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--fx-accent); color: var(--fx-accent); }
.btn:focus-visible, .field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid rgba(37, 99, 235, .25); outline-offset: 1px; }
.btn-primary { background: var(--fx-accent); border-color: var(--fx-accent); color: #fff; }
.btn-primary:hover { background: var(--fx-accent-dark); border-color: var(--fx-accent-dark); color: #fff; }
.btn-danger { color: var(--fx-danger-text); border-color: #fecaca; background: var(--fx-danger-bg); }
.btn-danger:hover { color: var(--fx-danger); border-color: var(--fx-danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--fx-muted); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--fx-muted); }
.field input, .field select, .field textarea { font: inherit; font-weight: 400; color: var(--fx-text); background: #fff; border: 1px solid var(--fx-border-strong);
  border-radius: 10px; padding: 9px 12px; min-height: 42px; width: 100%; }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--fx-muted); font-size: .9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--fx-accent); }
.form-error { background: var(--fx-danger-bg); color: var(--fx-danger-text); border-radius: 10px; padding: 10px 12px; margin: 0; font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .span2 { grid-column: 1 / -1; }

/* Accesso */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--fx-panel); padding: 20px; }
.login-card { width: min(380px, 100%); background: #fff; border: 1px solid var(--fx-border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); text-align: left; }
.login-card .muted { text-align: center; }

/* Struttura */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--fx-border); padding: 18px 14px; display: flex; flex-direction: column; background: #fff; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--fx-muted); font-weight: 600; text-decoration: none; }
.nav a:hover { background: var(--fx-panel); color: var(--fx-text); }
.nav a.active { background: var(--fx-panel-soft); color: var(--fx-accent-dark); }
.nav .count { margin-left: auto; background: var(--fx-accent); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 8px; line-height: 20px; }
.nav .count:empty { display: none; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }
.status-line { font-size: .8rem; color: var(--fx-faint); display: grid; gap: 4px; }
.status-line span { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fx-border-strong); display: inline-block; flex: none; }
.dot.ok { background: var(--fx-success); } .dot.warn { background: var(--fx-warning); } .dot.bad { background: var(--fx-danger); }
.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.banner { background: var(--fx-warning-bg); color: var(--fx-warning-text); border: 1px solid #fde68a; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; font-size: .9rem; }

/* Riquadri numerici */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { border: 1px solid var(--fx-border); border-radius: var(--radius); padding: 14px 16px; background: #fff; }
.kpi b { display: block; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--fx-faint); font-size: .82rem; font-weight: 600; }

.card { border: 1px solid var(--fx-border); border-radius: var(--radius); background: #fff; padding: 18px; }
.stack { display: grid; gap: 16px; align-content: start; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }

/* Liste «Oggi» */
.task { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 4px; border-top: 1px solid var(--fx-border); }
.task:first-of-type { border-top: 0; }
.task-name { font-weight: 700; cursor: pointer; }
.task-name:hover { color: var(--fx-accent); }
.task-sub { color: var(--fx-faint); font-size: .85rem; }
.empty { color: var(--fx-faint); padding: 18px 4px; text-align: center; }

/* Etichette */
.tag { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 9px; font-size: .75rem; font-weight: 700; white-space: nowrap; background: var(--fx-panel); color: var(--fx-muted); border: 1px solid var(--fx-border); }
.tag.w1 { background: var(--fx-success-bg); color: var(--fx-success-text); border-color: #bbf7d0; }
.tag.w2 { background: var(--fx-info-bg); color: var(--fx-info-text); border-color: #bfdbfe; }
.tag.w3 { background: var(--fx-violet-bg); color: var(--fx-violet-text); border-color: #ddd6fe; }
.tag.late, .tag.risk-alto, .tag.gelu { background: var(--fx-danger-bg); color: var(--fx-danger-text); border-color: #fecaca; }
.tag.today, .tag.risk-attenzione { background: var(--fx-warning-bg); color: var(--fx-warning-text); border-color: #fde68a; }
.tag.follow { background: var(--fx-info-bg); color: var(--fx-info-text); border-color: #bfdbfe; }
.tag.en { background: #fff; }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--fx-panel); border: 1px solid var(--fx-border); border-radius: var(--radius); padding: 10px; min-height: 60vh; display: flex; flex-direction: column; gap: 8px; }
.col.drop { outline: 2px dashed var(--fx-accent); outline-offset: -4px; background: var(--fx-panel-soft); }
.col-head { display: flex; justify-content: space-between; font-weight: 700; font-size: .85rem; color: var(--fx-muted); padding: 2px 4px 6px; text-transform: uppercase; letter-spacing: .05em; }
.deal { background: #fff; border: 1px solid var(--fx-border); border-radius: 10px; padding: 10px 12px; cursor: grab; display: grid; gap: 6px; }
.deal:hover { border-color: var(--fx-accent); box-shadow: var(--shadow); }
.deal.dragging { opacity: .5; }
.deal-name { font-weight: 700; font-size: .95rem; }
.deal-art { color: var(--fx-faint); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-foot { display: flex; gap: 6px; flex-wrap: wrap; }

/* Tabella contatti */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.toolbar .field { min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.table-wrap { border: 1px solid var(--fx-border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--fx-border); vertical-align: top; font-size: .9rem; }
th { background: var(--fx-panel); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--fx-faint); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--fx-panel); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { color: var(--fx-faint); font-size: .8rem; }

/* Scheda contatto */
.drawer-wrap, .modal-wrap { position: fixed; inset: 0; z-index: 50; }
.drawer-overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.drawer { position: absolute; top: 0; right: 0; height: 100%; width: min(880px, 100%); background: #fff; overflow-y: auto; box-shadow: -8px 0 32px rgba(15, 23, 42, .15); }
.drawer-head { position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--fx-border); padding: 16px 20px; display: flex; gap: 12px; align-items: center; z-index: 2; }
.drawer-head h2 { margin: 0; font-size: 1.25rem; }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-body { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; padding: 20px; align-items: start; }
.section-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fx-faint); font-weight: 700; margin: 0 0 10px; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.alert.bad { background: var(--fx-danger-bg); color: var(--fx-danger-text); }
.alert.warn { background: var(--fx-warning-bg); color: var(--fx-warning-text); }
.alert.info { background: var(--fx-panel-soft); color: var(--fx-info-text); }
.timeline { display: grid; gap: 0; }
.ev { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--fx-border); }
.ev:first-child { border-top: 0; }
.ev-ic { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--fx-panel); color: var(--fx-muted); }
.ev-ic .ic { width: 15px; height: 15px; }
.ev.email_in .ev-ic { background: var(--fx-success-bg); color: var(--fx-success); }
.ev.email_out .ev-ic { background: var(--fx-info-bg); color: var(--fx-accent); }
.ev-text { white-space: pre-wrap; font-size: .9rem; }
.ev-date { color: var(--fx-faint); font-size: .78rem; }
.composer { display: grid; gap: 10px; align-content: start; }
.drawer-head select { font: inherit; font-weight: 600; font-size: .9rem; color: var(--fx-text); border: 1px solid var(--fx-border-strong); border-radius: 10px; min-height: 34px; padding: 0 10px; background: #fff; }
.seg { display: inline-flex; border: 1px solid var(--fx-border-strong); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 12px; font: inherit; font-size: .85rem; font-weight: 600; color: var(--fx-muted); cursor: pointer; }
.seg button.on { background: var(--fx-panel-soft); color: var(--fx-accent-dark); }
.seg button + button { border-left: 1px solid var(--fx-border); }

/* Finestra email */
.modal-wrap { display: grid; place-items: center; padding: 16px; }
.modal { position: relative; width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: #fff; border-radius: 16px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(15, 23, 42, .25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal textarea { min-height: 300px; font-family: inherit; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 80; font-size: .9rem; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--fx-danger); }

.tpl-block { display: grid; gap: 10px; padding: 14px 0; border-top: 1px solid var(--fx-border); }
.tpl-block:first-of-type { border-top: 0; }
.tpl-block textarea { min-height: 220px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 12px; font-size: .9rem; }
.kv dt { color: var(--fx-faint); }
.kv dd { margin: 0; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col, .drawer-body { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 40; flex-direction: row; padding: 6px calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) 6px; border-right: 0; border-top: 1px solid var(--fx-border); }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .nav a { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 4px; position: relative; }
  .nav .count { position: absolute; top: 2px; right: 18%; }
  .main { padding: 18px 14px 96px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .drawer-head { flex-wrap: wrap; }
  .drawer-head .grow { flex: 1 1 calc(100% - 60px); order: 0; }
  .drawer-head .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .drawer-head [data-close] { order: 1; }
  .drawer-head select, .drawer-head #d-mail { order: 2; }
  .kv { grid-template-columns: 1fr; }
}
