/* FLOWY Azienda AI — Mini App stylesheet
   Palette brand teal/dark, mobile-first, touch targets >= 44px */

:root {
  --teal-900: #134E4A;
  --teal-700: #0F766E;
  --teal-400: #14B8A6;
  --slate-900: #0F172A;
  --slate-800: #1E293B;
  --slate-700: #334155;
  --slate-400: #94A3B8;
  --slate-100: #F1F5F9;
  --red: #F43F5E;
  --green: #22C55E;
  --amber: #F59E0B;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--slate-900);
  color: var(--slate-100);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  min-height: 100vh;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.logo {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--teal-400), var(--teal-700));
  display: grid; place-items: center;
  font-size: 22px; font-weight: 800; color: #042f2c;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.header h1 { font-size: 20px; font-weight: 700; margin: 0; }
.header .subtitle { font-size: 13px; color: var(--slate-400); margin: 0; }

.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--slate-800);
  color: var(--slate-100);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 0 14px; height: 44px;
  font-size: 15px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background .15s ease, transform .1s ease;
}
.back-btn:active { transform: scale(0.97); background: var(--slate-700); }

/* --- Summary banner --- */
.summary {
  background: linear-gradient(135deg, var(--teal-900), var(--slate-800));
  border: 1px solid var(--teal-700);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  display: flex; align-items: center; justify-content: space-between;
}
.summary .big { font-size: 28px; font-weight: 800; color: var(--teal-400); }
.summary .lbl { font-size: 13px; color: var(--slate-400); }

/* --- Department grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.card {
  position: relative;
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 16px 14px;
  min-height: 110px;
  cursor: pointer;
  text-decoration: none;
  color: var(--slate-100);
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease;
  animation: rise .35s ease both;
}
.card:active { transform: scale(0.97); }
.card .emoji { font-size: 26px; }
.card .name { font-size: 15px; font-weight: 600; line-height: 1.25; }
.card .meta { font-size: 12px; color: var(--slate-400); margin-top: auto; }
.card .accent {
  position: absolute; top: 0; left: 16px; right: 16px; height: 3px;
  border-radius: 0 0 3px 3px;
}

/* Badge notifiche */
.badge {
  position: absolute;
  top: 12px; right: 12px;
  min-width: 24px; height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(244, 63, 94, .5);
}
.badge.zero { background: var(--slate-700); color: var(--slate-400); box-shadow: none; }

/* --- KPI row --- */
.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi .val { font-size: 24px; font-weight: 800; color: var(--teal-400); }
.kpi .lbl { font-size: 12px; color: var(--slate-400); }

/* --- Section titles --- */
.section-title {
  font-size: 13px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--slate-400);
  margin: 22px 0 10px;
}

/* --- Proposal list item --- */
.proposal {
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  cursor: pointer;
  text-decoration: none; color: var(--slate-100);
  display: block;
  transition: transform .12s ease, border-color .15s ease;
  animation: rise .35s ease both;
}
.proposal:active { transform: scale(0.985); border-color: var(--teal-700); }
.proposal .row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.proposal .lvl { font-size: 16px; }
.proposal .from {
  font-size: 12px; color: var(--teal-400); font-weight: 600;
  background: rgba(20,184,166,.12); padding: 2px 8px; border-radius: 999px;
}
.proposal .subj { font-size: 15px; font-weight: 600; line-height: 1.3; }
.proposal .det { font-size: 13px; color: var(--slate-400); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.proposal .chev { float: right; color: var(--slate-400); }

/* --- History --- */
.history-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--slate-700);
  font-size: 13px;
}
.history-item:last-child { border-bottom: none; }
.history-item .ico { flex-shrink: 0; }
.history-item .txt { flex: 1; }
.history-item .when { color: var(--slate-400); font-size: 11px; }

/* --- Approval detail --- */
.detail-card {
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  animation: rise .3s ease both;
}
.detail-card h2 { font-size: 19px; margin: 0 0 6px; line-height: 1.3; }
.detail-card .tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tag {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--slate-700); color: var(--slate-100);
}
.tag.teal { background: rgba(20,184,166,.16); color: var(--teal-400); }
.block { margin-bottom: 16px; }
.block .blabel {
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--slate-400); margin-bottom: 4px;
}
.block .btext { font-size: 15px; color: var(--slate-100); white-space: pre-wrap; }

/* --- Action buttons --- */
.actions {
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; bottom: 0;
  padding-top: 12px; padding-bottom: var(--safe-bottom);
  background: linear-gradient(to top, var(--slate-900) 70%, transparent);
}
.btn {
  height: 52px;
  border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 700;
  cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s ease, filter .15s ease;
}
.btn:active { transform: scale(0.98); filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-approve { background: var(--green); color: #052e16; }
.btn-reject { background: var(--red); }
.btn-discuss { background: var(--slate-700); color: var(--slate-100); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* Discuss textarea */
.discuss-box { margin-top: 4px; }
.discuss-box textarea {
  width: 100%; min-height: 90px;
  background: var(--slate-900);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  color: var(--slate-100);
  padding: 12px; font-size: 15px; font-family: inherit;
  resize: vertical;
}
.discuss-box textarea:focus { outline: none; border-color: var(--teal-400); }

/* --- States --- */
.empty {
  text-align: center; color: var(--slate-400);
  padding: 40px 20px;
}
.empty .e-emoji { font-size: 40px; display: block; margin-bottom: 10px; }
.loader {
  display: grid; place-items: center; padding: 60px 0;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--slate-700);
  border-top-color: var(--teal-400);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--slate-800); border: 1px solid var(--teal-700);
  color: var(--slate-100);
  padding: 12px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Pianificazioni (dashboard) --- */
.plan-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  text-decoration: none; color: var(--slate-100);
  transition: transform .12s ease, border-color .15s ease;
  animation: rise .35s ease both;
}
.plan-item[href]:active { transform: scale(0.985); border-color: var(--teal-700); }
.plan-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.plan-body { flex: 1; min-width: 0; }
.plan-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.plan-agent { font-size: 14px; font-weight: 600; }
.plan-when {
  font-size: 12px; font-weight: 700; color: var(--teal-400);
  white-space: nowrap; background: rgba(20,184,166,.12);
  padding: 2px 8px; border-radius: 999px;
}
.plan-task { font-size: 13px; color: var(--slate-100); margin-top: 3px; }
.plan-cad { font-size: 11px; color: var(--slate-400); margin-top: 2px; }

/* --- Riga agente (dipartimento) --- */
.agent-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  text-decoration: none; color: var(--slate-100);
  transition: transform .12s ease, border-color .15s ease;
  animation: rise .35s ease both;
}
.agent-row:active { transform: scale(0.985); border-color: var(--teal-700); }
.ar-main { min-width: 0; }
.ar-name { font-size: 14px; font-weight: 600; }
.ar-sched { font-size: 12px; color: var(--teal-400); }
.ar-sched.muted { color: var(--slate-400); }
.ar-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ar-dec { font-size: 11px; color: var(--slate-400); white-space: nowrap; }

/* --- Pianificazioni (pagina agente) --- */
.sched-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--slate-800);
  border: 1px solid var(--slate-700);
  border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px;
}
.sched-when {
  font-size: 12px; font-weight: 700; color: var(--teal-400);
  white-space: nowrap; background: rgba(20,184,166,.12);
  padding: 3px 8px; border-radius: 999px; margin-top: 1px;
}
.sched-body { flex: 1; min-width: 0; }
.sched-task { font-size: 14px; font-weight: 500; }
.sched-cad { font-size: 11px; color: var(--slate-400); margin-top: 2px; }

/* --- Badge stato decisione --- */
.st-badge {
  font-size: 11px; font-weight: 700; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px; flex-shrink: 0;
}
.st-badge.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.st-badge.no { background: rgba(244,63,94,.15); color: #fb7185; }
.st-badge.disc { background: rgba(245,158,11,.15); color: #fbbf24; }

/* --- Indicatori di stato live --- */
.stat-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; flex-shrink: 0;
}
.stat-dot.active { background: var(--green); animation: pulse 1.2s ease-in-out infinite; }
.stat-dot.waiting { background: var(--amber); }
.stat-dot.idle { display: none; }
.stat-label { font-size: 12px; }
.stat-label.active { color: #4ade80; }
.stat-label.waiting { color: #fbbf24; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); opacity: 1; }
  50% { box-shadow: 0 0 0 6px rgba(34,197,94,0); opacity: .55; }
}

/* KPI cliccabile */
.kpi.link { cursor: pointer; position: relative; transition: transform .12s ease, border-color .15s ease; }
.kpi.link:active { transform: scale(0.97); border-color: var(--teal-700); }
.kpi.link::after { content: "›"; position: absolute; top: 10px; right: 12px; color: var(--slate-400); }

/* --- Coda / attività --- */
.work-item {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, rgba(34,197,94,.08), var(--slate-800));
  border: 1px solid rgba(34,197,94,.35);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
}
.work-item .ag { font-size: 14px; font-weight: 600; }
.work-item .doing { font-size: 12px; color: var(--slate-400); }
.work-item .el { margin-left: auto; font-size: 11px; color: #4ade80; white-space: nowrap; }
.q-item {
  background: var(--slate-800); border: 1px solid var(--slate-700);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.q-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.q-type {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px; background: var(--slate-700); color: var(--slate-100);
}
.q-type.directive { background: rgba(20,184,166,.16); color: var(--teal-400); }
.q-type.decision { background: rgba(34,197,94,.15); color: #4ade80; }
.q-type.scheduledtask { background: rgba(245,158,11,.15); color: #fbbf24; }
.q-ag { font-size: 12px; color: var(--slate-400); }
.q-subj { font-size: 14px; font-weight: 500; }
.q-when { font-size: 11px; color: var(--slate-400); margin-top: 2px; }

/* box "apri maschera" generico */
.open-box {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--slate-800); border: 1px solid var(--slate-700);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  text-decoration: none; color: var(--slate-100);
  transition: transform .12s ease, border-color .15s ease;
}
.open-box:active { transform: scale(0.985); border-color: var(--teal-700); }
.open-box .ob-l { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.open-box .ob-r { color: var(--slate-400); display: flex; align-items: center; gap: 8px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Stagger animation per le card */
.grid .card:nth-child(1){animation-delay:.02s}.grid .card:nth-child(2){animation-delay:.05s}
.grid .card:nth-child(3){animation-delay:.08s}.grid .card:nth-child(4){animation-delay:.11s}
.grid .card:nth-child(5){animation-delay:.14s}.grid .card:nth-child(6){animation-delay:.17s}
.grid .card:nth-child(7){animation-delay:.20s}.grid .card:nth-child(8){animation-delay:.23s}
.grid .card:nth-child(9){animation-delay:.26s}
