/* ============================================================
   Ekomlab OS — Widget system (core styles)
   Stile "repository impeccabile": pulito, denso, tipografico.
   Costruito sulle CSS variables già definite in index.html.
   Ogni widget è isolato: questo file definisce solo la "cornice".
   ============================================================ */

/* ── Bento: griglia a 12 colonne, righe di altezza fissa, packing denso ── */
.wdg-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 170px;
  grid-auto-flow: row dense;
  gap: 16px;
}
@media (max-width: 1100px) { .wdg-grid { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 640px)  { .wdg-grid { grid-template-columns: 1fr; grid-auto-rows: auto; } }

.wdg {
  background: var(--surface);
  /* stile Sneat/PlainAdmin: card senza bordo, solo ombra morbida */
  border: 1px solid transparent;
  border-radius: var(--r);
  box-shadow: var(--sh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* easing raffinato, mai bounce/elastic (principio impeccable) */
  transition: border-color .18s cubic-bezier(.2,0,0,1), box-shadow .18s cubic-bezier(.2,0,0,1), transform .18s cubic-bezier(.2,0,0,1);
}
.wdg:hover { box-shadow: var(--sh-md); transform: translateY(-1px); }

/* entrata morbida e scaglionata; disattivata per chi preferisce meno movimento */
@media (prefers-reduced-motion: no-preference) {
  .wdg { animation: wdgIn .4s cubic-bezier(.16,1,.3,1) both; }
  .wdg:nth-child(2) { animation-delay: .04s; }
  .wdg:nth-child(3) { animation-delay: .08s; }
  .wdg:nth-child(4) { animation-delay: .12s; }
  .wdg:nth-child(5) { animation-delay: .16s; }
  .wdg:nth-child(n+6) { animation-delay: .2s; }
}
@keyframes wdgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* span colonne (def.span, su 12) e righe (def.rows) */
.wdg[data-span="3"]  { grid-column: span 3; }
.wdg[data-span="4"]  { grid-column: span 4; }
.wdg[data-span="5"]  { grid-column: span 5; }
.wdg[data-span="6"]  { grid-column: span 6; }
.wdg[data-span="7"]  { grid-column: span 7; }
.wdg[data-span="8"]  { grid-column: span 8; }
.wdg[data-span="12"] { grid-column: span 12; }
.wdg[data-rows="2"]  { grid-row: span 2; }
.wdg[data-rows="3"]  { grid-row: span 3; }
.wdg[data-rows="4"]  { grid-row: span 4; }
.wdg[data-rows="5"]  { grid-row: span 5; }
.wdg[data-rows="6"]  { grid-row: span 6; }

/* breakpoint medio: tutto rientra in 6 colonne */
@media (max-width: 1100px) {
  .wdg[data-span="3"] { grid-column: span 3; }
  .wdg[data-span="4"], .wdg[data-span="5"] { grid-column: span 3; }
  .wdg[data-span="6"], .wdg[data-span="7"], .wdg[data-span="8"], .wdg[data-span="12"] { grid-column: span 6; }
}
/* mobile: ogni tile a piena larghezza, niente row-span forzato */
@media (max-width: 640px) {
  .wdg[data-span] { grid-column: span 1 !important; }
  .wdg[data-rows] { grid-row: auto !important; min-height: 200px; }
}

/* tile "nudo" (hero dark): nessuna intestazione, il widget riempie tutto */
.wdg-bare > .wdg-body { padding: 0; height: 100%; }
.wdg-bare { overflow: hidden; }

.wdg-head {
  display: flex;
  align-items: center;
  gap: 11px;
  /* niente riga divisoria: struttura uniforme e pulita (Sneat-like) */
  padding: 16px 18px 4px;
}
.wdg-ico {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px;
  background: var(--teal-l); color: var(--teal);
}
.wdg-ico svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wdg-title { font-weight: 600; font-size: 14px; color: var(--text); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wdg-tag {
  flex: 0 0 auto;
  font-size: 10px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text3);
  padding: 3px 8px; border-radius: 999px; background: var(--bg);
}
.wdg-refresh {
  flex: 0 0 auto; cursor: pointer; border: none; background: transparent; color: var(--text3);
  width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.wdg-refresh:hover { background: var(--bg); color: var(--text); }
.wdg-refresh svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.wdg-body { padding: 12px 18px 18px; flex: 1; }

/* categorie: colore del chip icona */
.wdg-cat-dati   .wdg-ico { background: var(--primary-l); color: var(--primary-d); }
.wdg-cat-azione .wdg-ico { background: var(--teal-l);    color: var(--teal); }
.wdg-cat-ai     .wdg-ico { background: var(--amber-l);   color: var(--amber); }

/* ---- blocchi statistiche (widget "dati") ---- */
.wdg-stats { display: flex; gap: 14px; flex-wrap: wrap; }
.wdg-stat { flex: 1 1 0; min-width: 90px; }
.wdg-num { font-family: 'Public Sans', sans-serif; font-size: 28px; font-weight: 700; line-height: 1.05; letter-spacing: -.015em; font-variant-numeric: tabular-nums lining-nums; color: var(--num); }
.wdg-lab { font-size: 12px; color: var(--text2); margin-top: 3px; }
.wdg-note { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 12.5px; color: var(--text2); display: flex; align-items: center; gap: 7px; }
.wdg-note b { color: var(--text); font-weight: 600; }

/* ---- tile METRICA (numero grande + chip + sparkline) — usata da più widget ----
   Vocabolario condiviso: il widget riempie .wdg-body con .wdg-metric. */
.wdg-metric { display: flex; flex-direction: column; height: 100%; }
.wdg-metric .m-big { font-family: 'Public Sans', sans-serif; font-size: 40px; font-weight: 800; letter-spacing: -1.2px; line-height: 1; margin-top: auto; color: var(--num); font-variant-numeric: tabular-nums lining-nums; }
.wdg-metric .m-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: 12px; }
.wdg-chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 7px; background: var(--primary-l); color: var(--primary-d); white-space: nowrap; }
.wdg-chip.up { background: var(--sage-l); color: var(--sage); }
.wdg-chip.down { background: var(--coral-l); color: var(--coral); }
.wdg-spark { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.wdg-spark i { width: 6px; border-radius: 3px; background: var(--primary-l); }
.wdg-spark i.on { background: var(--primary); }

/* ---- form (widget "azione") ---- */
.wdg-field { margin-bottom: 11px; }
.wdg-field:last-of-type { margin-bottom: 14px; }
.wdg-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.wdg-input, .wdg-textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 9px 11px; transition: border-color .12s, box-shadow .12s; outline: none;
}
.wdg-input:focus, .wdg-textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-l); }
.wdg-textarea { resize: vertical; min-height: 72px; }
.wdg-row { display: flex; gap: 10px; }
.wdg-row > .wdg-field { flex: 1; }

.wdg-btn {
  width: 100%; cursor: pointer; font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: #fff; background: var(--primary); border: none; border-radius: var(--r-sm);
  padding: 10px 14px; transition: filter .15s cubic-bezier(.2,0,0,1), transform .08s cubic-bezier(.2,0,0,1); display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.wdg-btn:hover { filter: brightness(1.06); }
.wdg-btn:active { transform: scale(.985); }
.wdg-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.wdg-btn:disabled { opacity: .55; cursor: default; }
.wdg-btn { background: var(--primary-d); }
.wdg-btn:hover { background: var(--primary); filter: none; }

/* widget azione: il form riempie l'altezza della tile, il pulsante (e lo stato
   sotto) sono ancorati in basso → niente spazio bianco sotto al bottone. */
.wdg-cat-azione .wdg-body { display: flex; flex-direction: column; }
.wdg-cat-azione .wdg-btn { margin-top: auto; }

/* ---- stati: loading / errore / placeholder ---- */
.wdg-skel { display: flex; flex-direction: column; gap: 10px; }
.wdg-skel span { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--bg) 25%, var(--border) 37%, var(--bg) 63%); background-size: 400% 100%; animation: wdgpulse 1.3s ease infinite; }
@keyframes wdgpulse { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.wdg-err { font-size: 12.5px; color: var(--coral); display: flex; align-items: center; gap: 7px; }
.wdg-soon { font-size: 12.5px; color: var(--text2); line-height: 1.55; }
.wdg-soon b { color: var(--text); }
.wdg-badge-soon { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--amber); background: var(--amber-l); padding: 2px 7px; border-radius: 999px; margin-bottom: 10px; }
.wdg-ok { font-size: 12.5px; color: var(--sage); font-weight: 600; }

/* ============================================================
   AI HERO — chat AI prominente stile BioLog
   ============================================================ */
.ai-hero-card {
  background: linear-gradient(140deg, #4f9bce 0%, #6492d0 50%, #846db0 100%) !important;
  border: none !important;
  box-shadow: 0 14px 40px -16px rgba(79,155,206,0.42), 0 4px 12px rgba(79,155,206,0.14) !important;
  overflow: hidden;
  position: relative;
}
.ai-hero-card::before {
  content: '';
  position: absolute;
  top: -40%; right: -10%;
  width: 60%; height: 180%;
  background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 60%);
  pointer-events: none;
}
.ai-hero-card .wdg-body { padding: 26px 28px !important; height: 100%; }
.ai-hero-inner {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 28px;
  height: 100%;
  align-items: center;
  position: relative;
  z-index: 1;
}
.ai-hero-left { color: white; }
.ai-hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.95);
  background: rgba(255,255,255,0.16);
  backdrop-filter: blur(8px);
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.22);
  margin-bottom: 14px;
}
.ai-hero-title {
  font-family: 'Public Sans', sans-serif;
  font-size: 26px; font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.15;
  color: white;
  margin-bottom: 8px;
}
.ai-hero-sub {
  font-size: 13.5px;
  color: rgba(255,255,255,0.82);
  line-height: 1.5;
  max-width: 340px;
}

.ai-hero-right {
  display: flex; flex-direction: column;
  gap: 12px;
  justify-content: center;
}
.ai-hero-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
}
.ai-hero-chip {
  font-size: 12px; font-weight: 500;
  color: rgba(255,255,255,0.92);
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.14s, transform 0.08s;
  white-space: nowrap;
}
.ai-hero-chip:hover { background: rgba(255,255,255,0.22); }
.ai-hero-chip:active { transform: scale(.97); }

.ai-hero-inputrow {
  display: flex; align-items: flex-end;
  gap: 8px;
  background: rgba(255,255,255,0.98);
  border-radius: 16px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.2);
}
.ai-hero-input {
  flex: 1; min-width: 0;
  border: none; outline: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 8px 0;
  line-height: 1.45;
  max-height: 160px;
}
.ai-hero-input::placeholder { color: var(--text3); }
.ai-hero-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  color: white;
  border: 1.5px solid rgba(255,255,255,0.35);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.08s;
}
.ai-hero-send:hover { background: rgba(255,255,255,0.32); }
.ai-hero-send:active { transform: scale(.94); }
.ai-hero-send:disabled { background: var(--text3); cursor: default; }

.ai-hero-status {
  font-size: 12.5px;
  color: rgba(255,255,255,0.9);
  min-height: 18px;
  display: flex; align-items: center; gap: 6px;
}
.ai-hero-status a {
  color: white; font-weight: 600;
  text-decoration: underline;
}
.ai-hero-status.err { color: #fecaca; }
.ai-hero-status.ok { color: #d1fae5; }
.ai-hero-spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: aihspin 0.7s linear infinite;
}
@keyframes aihspin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .ai-hero-inner { grid-template-columns: 1fr; gap: 18px; }
  .ai-hero-title { font-size: 22px; }
}
