/* ============================================================= *
 *  Mentelocale Orchestratore — design system (static, no build) *
 * ============================================================= */

/* ---- Tokens ---- */
:root {
  /* Color */
  --c-bg:        #f4f5f7;
  --c-surface:   #ffffff;
  --c-ink:       #1a1a2e;
  --c-ink-soft:  #5a6072;
  --c-muted:     #6b7280;
  --c-line:      #eef0f4;
  --c-accent:    #4a6cf7;
  --c-accent-d:  #3a5be0;
  --c-accent-bg: #eef2ff;
  --c-accent-bd: #d8deff;
  --c-success:   #1a7f43;
  --c-success-d: #156c39;
  --c-success-bg:#e7f6ec;
  --c-danger:    #c0392b;
  --c-danger-bg: #fdeaea;
  --c-danger-bd: #f3c0c0;
  --c-warn-bg:   #fff4e0;
  --c-warn-ink:  #9a6a00;

  /* Spacing scale (4px base) */
  --s-1: .25rem;  --s-2: .5rem;  --s-3: .75rem;  --s-4: 1rem;
  --s-5: 1.5rem;  --s-6: 2rem;   --s-7: 3rem;

  /* Type scale */
  --fs-xs: .72rem; --fs-sm: .82rem; --fs-md: .9rem;
  --fs-lg: 1rem;   --fs-xl: 1.25rem; --fs-2xl: 1.6rem; --fs-3xl: 2rem;

  /* Radii */
  --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-pill: 999px;

  /* Shadows */
  --sh-1: 0 1px 6px rgba(0,0,0,.06);
  --sh-2: 0 2px 12px rgba(74,108,247,.18);
  --sh-3: 0 -2px 14px rgba(0,0,0,.10);

  /* Layout */
  --maxw: 1100px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0; background: var(--c-bg); color: var(--c-ink);
  font-size: 16px; line-height: 1.45;
}

/* ---- Shell ---- */
.topbar {
  background: var(--c-surface); box-shadow: var(--sh-1);
  padding: 0 var(--s-5); min-height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-5);
  position: sticky; top: 0; z-index: 40; flex-wrap: wrap;
}
.brand { font-weight: 800; letter-spacing: -.3px; }
.brand span { color: var(--c-accent); }
.tabs { display: flex; gap: var(--s-1); flex-wrap: wrap; overflow-x: auto; }
.tabs a {
  text-decoration: none; color: var(--c-ink-soft); font-size: var(--fs-md);
  font-weight: 600; padding: var(--s-2) var(--s-3); border-radius: var(--r-md);
  white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center;
}
.tabs a.active, .tabs a:hover { background: var(--c-accent-bg); color: var(--c-accent); }
.logout-form { margin-left: auto; }
main { padding: var(--s-5); max-width: var(--maxw); margin: 0 auto; padding-bottom: 88px; }

/* ---- Login page ---- */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--s-5);
}
.login-card { width: 100%; max-width: 360px; }
.login-card h2 { margin-top: 0; }
.login-error {
  background: var(--c-danger-bg); color: var(--c-danger); border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3); font-size: var(--fs-sm); margin: var(--s-3) 0 0;
}
.login-submit { width: 100%; margin-top: var(--s-4); }

h2 { font-size: var(--fs-2xl); margin: var(--s-1) 0; }
h3 { font-size: var(--fs-lg); }
.muted { color: var(--c-muted); font-size: var(--fs-sm); }
code { background: var(--c-line); padding: .05rem .3rem; border-radius: var(--r-sm); font-size: .8em; }

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: var(--r-sm);
  font-size: var(--fs-xs); font-weight: 600;
}
.badge--cat   { background: var(--c-accent-bg); color: var(--c-accent); }
.badge--yes   { background: var(--c-success-bg); color: var(--c-success); }
.badge--no    { background: var(--c-danger-bg); color: var(--c-danger); }
.badge--past  { background: #f0f0f0; color: #888; }
.badge--alta  { background: var(--c-success-bg); color: var(--c-success); }
.badge--media { background: var(--c-warn-bg); color: var(--c-warn-ink); }
.badge--bassa { background: var(--c-danger-bg); color: var(--c-danger); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  padding: .5rem .9rem; border-radius: var(--r-md); border: 1px solid var(--c-accent-bd);
  background: var(--c-surface); color: var(--c-accent); text-decoration: none;
  min-height: 40px;
}
.btn:hover { background: var(--c-accent-bg); }
.btn--primary { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn--primary:hover { background: var(--c-accent-d); }
.btn--danger { background: var(--c-surface); border-color: var(--c-danger-bd); color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger-bg); }
.btn--ghost { border-color: #e0e3ea; color: var(--c-ink-soft); }
.btn--ghost:hover { background: var(--c-bg); }
.btn--approve { background: var(--c-success); border-color: var(--c-success); color: #fff; }
.btn--approve:hover { background: var(--c-success-d); }
.btn--reject { background: var(--c-surface); border-color: var(--c-danger-bd); color: var(--c-danger); }
.btn--reject:hover { background: var(--c-danger-bg); }
.btn--send { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn--send:hover { background: var(--c-accent-d); }
.btn-lg { font-size: var(--fs-md); padding: .6rem 1.1rem; border-radius: var(--r-lg); }
.btn-sm { font-size: var(--fs-xs); padding: .3rem .6rem; min-height: 32px; }

/* ---- Cards (dashboard) ---- */
.card { background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: var(--s-4) var(--s-5); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); }
.cards a.card { text-decoration: none; color: inherit; }
.cards a.card:hover { box-shadow: var(--sh-2); }
.card .big { font-size: var(--fs-3xl); font-weight: 800; color: var(--c-accent); line-height: 1.1; }
.card-hint { font-size: var(--fs-xs); color: var(--c-muted); margin-top: var(--s-1); }

/* ---- Forms ---- */
label { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--c-ink-soft); margin: var(--s-3) 0 var(--s-1); }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; font: inherit; font-size: var(--fs-sm); padding: .5rem .6rem;
  border: 1px solid var(--c-accent-bd); border-radius: var(--r-md);
  background: var(--c-surface); color: var(--c-ink); min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 2px var(--c-accent-bg); }
textarea { resize: vertical; min-height: auto; }

/* ---- Filter bar ---- */
.filter-bar {
  display: flex; gap: var(--s-3); align-items: flex-end; flex-wrap: wrap;
  background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4);
}
.filter-field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 140px; flex: 1 1 140px; }
.filter-field label { margin: 0; }
.filter-actions { display: flex; gap: var(--s-2); align-items: flex-end; }

/* ---- Table (desktop) ---- */
.toolbar { display: flex; gap: var(--s-3); align-items: center; margin-bottom: var(--s-4); flex-wrap: wrap; }
.evt-table { width: 100%; border-collapse: collapse; background: var(--c-surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-1); }
.evt-table th, .evt-table td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--c-line); font-size: var(--fs-sm); vertical-align: top; }
.evt-table th { background: #fafbff; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); }
.evt-table tr:last-child td { border-bottom: none; }
.evt-table a.title-link { color: var(--c-ink); text-decoration: none; font-weight: 600; }
.evt-table a.title-link:hover { color: var(--c-accent); }
th.col-check, td.col-check { width: 36px; text-align: center; }
.chk-row, .chk-all { width: 20px; height: 20px; cursor: pointer; }
.empty { color: var(--c-muted); font-size: var(--fs-md); padding: var(--s-6); text-align: center; background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-1); }

/* ---- Responsive: table -> stacked cards (<=720px) ---- */
@media (max-width: 720px) {
  .evt-table, .evt-table thead, .evt-table tbody,
  .evt-table tr, .evt-table th, .evt-table td { display: block; }
  .evt-table { box-shadow: none; background: transparent; }
  .evt-table thead { position: absolute; left: -9999px; }      /* hide header row */
  .evt-table tr {
    background: var(--c-surface); border-radius: var(--r-lg);
    box-shadow: var(--sh-1); margin-bottom: var(--s-3); padding: var(--s-2) var(--s-3);
    position: relative;
  }
  .evt-table td { border: none; padding: .35rem 0 .35rem 42%; position: relative; min-height: 28px; }
  .evt-table td::before {
    content: attr(data-label); position: absolute; left: 0; top: .35rem;
    width: 38%; font-size: var(--fs-xs); font-weight: 700; color: var(--c-muted);
    text-transform: uppercase; letter-spacing: .03em;
  }
  /* The selection checkbox floats top-right of the card; no label. Pad the
     cell and enlarge the box so the tap target is finger-sized (WCAG 2.5.5). */
  .evt-table td.col-check { position: absolute; top: var(--s-1); right: var(--s-2); width: auto; padding: var(--s-2); min-height: 0; }
  .evt-table td.col-check::before { content: none; }
  .evt-table .chk-row, .evt-table .chk-all { width: 28px; height: 28px; }
}

/* ---- Sticky bulk action bar ---- */
.bulk-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: none; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  background: var(--c-surface); box-shadow: var(--sh-3);
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--c-line);
}
.bulk-bar--show { display: flex; }
.bulk-count { font-weight: 700; color: var(--c-accent); }
.bulk-bar form { margin: 0; display: inline; }
@media (max-width: 720px) {
  .bulk-bar { padding: var(--s-2) var(--s-3); gap: var(--s-2); }
  .bulk-bar .btn { flex: 1 1 auto; }
}

/* ---- In elaborazione: live pipeline stepper ---- */
.proc-list { display: flex; flex-direction: column; gap: var(--s-3); }
.proc-card {
  background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: var(--s-4) var(--s-5); border: 1px solid var(--c-line);
}
.proc-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.proc-title { font-weight: 700; color: var(--c-ink); text-decoration: none; font-size: var(--fs-lg); }
.proc-title:hover { color: var(--c-accent); }
.proc-meta { display: inline-flex; align-items: center; gap: var(--s-2); }
.proc-elapsed { display: inline-flex; align-items: center; gap: .25rem; color: var(--c-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.proc-status { margin-top: var(--s-3); font-size: var(--fs-sm); }

/* The stepper: a row of 4 nodes joined by connector lines. */
.stepper { list-style: none; display: flex; margin: var(--s-4) 0 0; padding: 0; }
.step { position: relative; flex: 1 1 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); min-width: 0; }
/* Connector line to the NEXT node (drawn from this node's centre rightward). */
.step[data-connector]::after {
  content: ""; position: absolute; top: 15px; left: 50%; width: 100%; height: 3px;
  background: var(--c-line); z-index: 0;
}
.step[data-connector="done"]::after { background: var(--c-success); }
.step-node {
  position: relative; z-index: 1; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--c-surface); border: 2px solid var(--c-line); color: var(--c-muted);
  transition: background .2s, border-color .2s, color .2s;
}
.step-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .5; }
.step-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.step-label { font-size: var(--fs-sm); font-weight: 600; color: var(--c-ink-soft); }
.step-caption { font-size: var(--fs-xs); color: var(--c-muted); }
/* Done */
.step--done .step-node { background: var(--c-success); border-color: var(--c-success); color: #fff; }
.step--done .step-label { color: var(--c-ink); }
/* Active — accent ring + pulsing halo + spinner */
.step--active .step-node { border-color: var(--c-accent); color: var(--c-accent); box-shadow: 0 0 0 0 rgba(74,108,247,.45); animation: proc-pulse 1.5s ease-out infinite; }
.step--active .step-label { color: var(--c-accent); }
.step-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--c-accent-bd); border-top-color: var(--c-accent);
  animation: proc-spin .7s linear infinite;
}
@keyframes proc-spin { to { transform: rotate(360deg); } }
@keyframes proc-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,108,247,.45); }
  70%  { box-shadow: 0 0 0 8px rgba(74,108,247,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,108,247,0); }
}
@media (prefers-reduced-motion: reduce) {
  .step-spinner { animation: none; border-top-color: var(--c-accent-bd); }
  .step--active .step-node { animation: none; }
}
/* Mobile: stack the stepper vertically with a left rail connector. */
@media (max-width: 620px) {
  .stepper { flex-direction: column; align-items: stretch; gap: var(--s-3); }
  .step { flex-direction: row; align-items: center; text-align: left; gap: var(--s-3); }
  .step[data-connector]::after { top: 32px; left: 15px; width: 3px; height: 100%; }
  .step-text { flex: 1; }
}

/* ── Import bar (Da elaborare → Importa nuovi eventi) ── */
.import-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-4); padding: var(--s-3) var(--s-4);
  background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.import-form { margin: 0; }
.import-subtitle { margin: 0; font-size: var(--fs-sm); }
.import-status { width: 100%; display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); }
.import-status--done {
  flex-direction: column; align-items: flex-start; gap: var(--s-2);
  padding: var(--s-3); border-radius: var(--r-md);
  background: var(--c-success-bg); color: var(--c-success);
}
.import-status--error {
  flex-direction: column; align-items: flex-start; gap: var(--s-1);
  padding: var(--s-3); border-radius: var(--r-md);
  background: var(--c-danger-bg); color: var(--c-danger);
}
.import-error-msg { margin: 0; font-weight: 600; word-break: break-word; }
.import-counts {
  display: flex; flex-wrap: wrap; gap: var(--s-3);
  margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--c-ink);
}

/* ===== Editor (detail) — preserved component classes ===== */
.check { display: inline-flex; align-items: center; gap: var(--s-1); }
.check input { width: auto; }
.fields th { text-transform: none; font-size: var(--fs-sm); }
.field-row { display: flex; align-items: flex-start; gap: var(--s-2); }
.field-val { flex: 1; min-width: 0; word-break: break-word; }
.ro-html { font-size: var(--fs-sm); }
.btn-edit { display: inline-flex; align-items: center; justify-content: center; padding: .3rem; line-height: 0; cursor: pointer; border: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: #8a90a2; }
.btn-edit:hover { background: var(--c-accent-bg); color: var(--c-accent); border-color: var(--c-accent-bd); }
.btn .ic, .btn-lg .ic { vertical-align: -2px; margin-right: .3rem; }
.info { position: relative; display: inline-flex; vertical-align: middle; margin-left: .25rem; color: #b3b8c6; cursor: help; }
.info:hover, .info:focus { color: var(--c-accent); outline: none; }
.info-bubble { position: absolute; left: 0; top: 130%; z-index: 20; width: max-content; max-width: 260px;
  background: var(--c-ink); color: #fff; font-size: var(--fs-xs); font-weight: 400; line-height: 1.35; text-transform: none;
  letter-spacing: 0; padding: .45rem .6rem; border-radius: var(--r-md); box-shadow: 0 4px 14px rgba(0,0,0,.22);
  opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none; }
.info:hover .info-bubble, .info:focus .info-bubble { opacity: 1; visibility: visible; }
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 6px);
  z-index: 30; width: max-content; max-width: 280px; background: var(--c-ink); color: #fff;
  font-size: var(--fs-xs); font-weight: 400; line-height: 1.35; text-align: left; padding: .45rem .6rem;
  border-radius: var(--r-md); box-shadow: 0 4px 14px rgba(0,0,0,.22); opacity: 0; visibility: hidden;
  transition: opacity .12s; pointer-events: none; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; }
.field-edit { align-items: center; }
.field-edit > input, .field-edit > select, .field-edit > textarea { flex: 1; }
.field-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.actions { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; }
.action-with-note { display: flex; gap: var(--s-2); align-items: center; margin: 0; }
.action-with-note input { width: 180px; }
.action-primary { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.err { background: var(--c-danger-bg); color: var(--c-danger); padding: var(--s-4); border-radius: var(--r-lg); }
@media (max-width: 720px) {
  .action-with-note { flex-wrap: wrap; }
  .action-with-note input { width: 100%; }
  .actions .btn, .action-primary .btn { width: 100%; }
}
