/*
 * FlowForge · Layout "soft dashboard"
 *
 * Strato di stile caricato dopo styles.css. Porta nella piattaforma:
 * - superfici bianche/chiare molto arrotondate con ombre morbide, su un fondo neutro;
 * - un solo colore d'accento forte (il teal del marchio), usato per la card in evidenza,
 *   i pulsanti primari e lo stato attivo;
 * - barra superiore e sidebar "flottanti" come pannelli separati;
 * - micro-animazioni: le card si sollevano al passaggio del mouse;
 * - tema chiaro (predefinito) e tema scuro, scelti con il pulsante sole/luna.
 *
 * Tutti i colori passano dalle variabili: per cambiare l'accento basta modificare
 * --accent / --accent-strong / --accent-gradient qui sotto.
 */

:root {
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --accent-gradient: linear-gradient(135deg, #2fbfa8 0%, #1f9d8a 48%, #157a6c 100%);
  --hover-lift: translateY(-3px);
}

/* ---------- Tema scuro (valori raffinati rispetto alla palette storica) ---------- */
:root[data-theme="dark"] {
  --bg: #0c110f;
  --surface: #141b17;
  --surface-strong: #1b241f;
  --line: #26322b;
  --sidebar-bg: #101612;
  --topbar-bg: rgba(20, 27, 23, 0.78);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px rgba(0, 0, 0, 0.32);
  --shadow-hover: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 18px 42px rgba(0, 0, 0, 0.42);
  --pill-bg: #1b241f;
  --pill-active-bg: #eef5ef;
  --pill-active-ink: #0c110f;
  color-scheme: dark;
}

/* ---------- Tema chiaro ---------- */
:root[data-theme="light"] {
  --bg: #f1f3f2;
  --surface: #ffffff;
  --surface-strong: #f5f7f6;
  --ink: #131a16;
  --muted: #62706a;
  --line: #e2e7e4;
  --accent: #178a78;
  --accent-strong: #0f6b5e;
  --amber: #a8650c;
  --red: #cf3a28;
  --blue: #2f66c2;
  --sidebar-bg: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --shadow: 0 1px 2px rgba(19, 26, 22, 0.04), 0 8px 24px rgba(19, 26, 22, 0.06);
  --shadow-hover: 0 2px 4px rgba(19, 26, 22, 0.05), 0 16px 36px rgba(19, 26, 22, 0.1);
  --pill-bg: #f1f3f2;
  --pill-active-bg: #131a16;
  --pill-active-ink: #ffffff;

  --deep-0: #eef1ef;
  --deep-1: #f5f7f6;
  --deep-2: #f3f5f4;
  --surface-raised: #e9eeeb;
  --muted-strong: #4f5d56;
  --accent-ink-soft: #0f6b5e;
  --tone-red-ink: #c0392b;
  --tone-amber-ink: #95590a;
  --tone-amber: #b8730a;
  --tone-green-ink: #2b8a3e;
  --tone-green: #2f9e44;
  --tone-blue-ink: #2f66c2;
  --tone-blue: #2f66c2;
  --glass-1: rgba(255, 255, 255, 0.94);
  --glass-2: rgba(245, 247, 246, 0.92);
  --glass-3: rgba(255, 255, 255, 0.94);
  --surface-selected: #e3f3ef;
  color-scheme: light;
}

body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.workspace {
  background: var(--bg);
}

/* ---------- Shell: sidebar e workspace come pannelli flottanti ---------- */
@media (min-width: 981px) {
  .app-shell {
    gap: 14px;
    padding: 14px 0 14px 14px;
  }

  .sidebar {
    top: 14px;
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--sidebar-bg);
    box-shadow: var(--shadow);
    scrollbar-color: var(--line) transparent;
  }

  .sidebar::-webkit-scrollbar-track {
    background: transparent;
  }

  .workspace {
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
    padding: 0 14px 32px 0;
    border-radius: var(--radius-xl);
  }
}

@media (max-width: 980px) {
  .sidebar {
    background: var(--sidebar-bg);
  }
}

.brand-mark {
  border-radius: 12px;
  background: var(--accent-gradient);
  box-shadow: 0 6px 16px rgba(23, 138, 120, 0.28);
}

.nav-group-label {
  color: var(--muted);
  letter-spacing: 0.12em;
}

.nav-item {
  border-radius: var(--radius-md);
  transition: background-color 160ms ease, color 160ms ease;
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface-strong);
}

.nav-item.active {
  color: var(--ink);
  font-weight: 700;
}

.nav-item.active .nav-icon {
  color: var(--accent);
}

.nav-item.active::before {
  display: none;
}

.sidebar-toggle {
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
}

/* ---------- Barra superiore "a vetro" ---------- */
@media (min-width: 981px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
  }
}

.topbar {
  align-items: center;
  margin: 0 0 18px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--topbar-bg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
}

.topbar h1 {
  font-size: clamp(1.6rem, 2.6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar .eyebrow {
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.view-subtitle {
  margin-top: 4px;
  font-size: 0.92rem;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  transition: transform 200ms var(--ease-out), border-color 160ms ease;
}

.theme-toggle:hover {
  border-color: var(--accent);
  transform: rotate(-12deg);
}

.theme-toggle::before {
  content: "";
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: url("/assets/icons/moon.svg") center / contain no-repeat;
  mask: url("/assets/icons/moon.svg") center / contain no-repeat;
}

:root[data-theme="dark"] .theme-toggle::before {
  -webkit-mask-image: url("/assets/icons/sun.svg");
  mask-image: url("/assets/icons/sun.svg");
}

/* ---------- Pulsanti a pillola ---------- */
.primary-button,
.danger-button,
.ghost-button,
.icon-button,
.mini-button,
.workspace-switcher summary,
.tenant-status,
.record-count {
  border-radius: var(--radius-pill);
}

.primary-button {
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(23, 138, 120, 0.24);
  transition: transform 180ms var(--ease-out), box-shadow 180ms ease, background-color 160ms ease;
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.ghost-button,
.mini-button {
  transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease;
}

.mini-button {
  padding: 0 12px;
}

:root[data-theme="light"] .tenant-status {
  border-color: #cfe5df;
  background: #eaf6f2;
  color: var(--accent-strong);
}

:root[data-theme="light"] .tenant-status.demo,
:root[data-theme="light"] .tenant-status.scheduled {
  border-color: #ecd9a6;
  background: #fff6db;
  color: #6f5409;
}

/* ---------- Card e pannelli ---------- */
.metric,
.panel,
.card,
.custom-dashboard-card,
.dashboard-kpi {
  border-color: var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.modal-card,
.modal {
  border-radius: var(--radius-xl);
}

.metric,
.dashboard-kpi,
.custom-dashboard-card {
  transition: transform 260ms var(--ease-out), box-shadow 260ms ease;
}

@media (hover: hover) {
  .metric:hover,
  .dashboard-kpi:hover,
  .custom-dashboard-card:hover {
    transform: var(--hover-lift);
    box-shadow: var(--shadow-hover);
  }
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

input,
select,
textarea {
  border-radius: var(--radius-md);
}

input[type="search"] {
  border-radius: var(--radius-pill);
}

/* ---------- Home: KPI in stile "saldo in evidenza" ---------- */
#home .metric-grid {
  gap: 14px;
  margin-bottom: 18px;
}

#home .metric {
  min-height: 104px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

#home .home-kpi-icon {
  border-radius: 14px;
}

#home .metric-grid > .home-kpi-card:first-child {
  position: relative;
  overflow: hidden;
  border-color: transparent;
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 14px 34px rgba(23, 138, 120, 0.34);
}

#home .metric-grid > .home-kpi-card:first-child::after {
  content: "";
  position: absolute;
  inset: auto -30% -70% auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), transparent 65%);
  pointer-events: none;
}

#home .metric-grid > .home-kpi-card:first-child .home-kpi-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

#home .metric-grid > .home-kpi-card:first-child .home-kpi-label,
#home .metric-grid > .home-kpi-card:first-child .home-kpi-value,
#home .metric-grid > .home-kpi-card:first-child .home-kpi-delta,
#home .metric-grid > .home-kpi-card:first-child .home-kpi-detail {
  color: #fff;
}

#home .metric-grid > .home-kpi-card:first-child .home-kpi-detail {
  opacity: 0.8;
}

/* ---------- Comparsa morbida delle sezioni ---------- */
.view.active > * {
  animation: ff-rise 420ms var(--ease-out) both;
}

.view.active > :nth-child(2) { animation-delay: 40ms; }
.view.active > :nth-child(3) { animation-delay: 80ms; }
.view.active > :nth-child(4) { animation-delay: 120ms; }

@keyframes ff-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .view.active > *,
  .metric,
  .primary-button,
  .theme-toggle {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Barra superiore su telefono ---------- */
@media (max-width: 680px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    margin-bottom: 14px;
    padding: 12px 14px;
  }

  .topbar-main {
    align-items: center;
  }

  .topbar h1 {
    font-size: 1.45rem;
    overflow-wrap: anywhere;
  }

  .topbar .eyebrow {
    margin-bottom: 2px;
    font-size: 0.72rem;
  }

  .view-subtitle {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 0.85rem;
  }

  .topbar-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
  }

  .topbar-actions > * {
    flex: 0 1 auto;
    min-width: 0;
  }

  .topbar-actions .ghost-button,
  .topbar-actions .primary-button,
  .topbar-actions .tenant-status {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  .topbar-actions .tenant-status {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Il contatore ripete il titolo della vista: su telefono occupa solo spazio. */
  .topbar-actions .record-count {
    display: none;
  }

  .topbar-actions .workspace-switcher {
    flex: 1 1 100%;
  }
}

/* Ricerca globale */
.global-search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.global-search-trigger:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.global-search-icon {
  display: inline-block;
  width: 17px;
  height: 17px;
  flex: none;
  background: currentColor;
  -webkit-mask: url('/assets/icons/search.svg') center / contain no-repeat;
  mask: url('/assets/icons/search.svg') center / contain no-repeat;
}

.global-search-trigger kbd,
.global-search-footer kbd {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font: inherit;
  font-size: 0.72rem;
  color: var(--muted);
}

.global-search-modal {
  width: min(640px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 64px));
  margin-top: 10vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.global-search-modal::backdrop {
  background: rgba(8, 12, 10, 0.45);
}

.global-search-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: inherit;
}

.global-search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.global-search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.05rem;
  outline: none;
  box-shadow: none;
}

.global-search-results {
  overflow-y: auto;
  padding: 6px 8px 10px;
}

.global-search-group {
  margin: 10px 8px 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.global-search-group span {
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.global-search-result {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.global-search-result span {
  color: var(--muted);
  font-size: 0.86rem;
}

.global-search-result.active {
  border-color: var(--accent);
  background: var(--surface-selected);
}

.global-search-empty {
  margin: 18px 10px;
  color: var(--muted);
}

.global-search-footer {
  margin: 0;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}

@media (max-width: 720px) {
  .global-search-trigger {
    width: 40px;
    padding: 0;
    justify-content: center;
  }

  .global-search-label,
  .global-search-trigger kbd,
  .global-search-footer {
    display: none;
  }

  .global-search-modal {
    margin-top: 16px;
  }
}

/* Verifica in due passaggi */
.actor-status-button {
  cursor: pointer;
  font: inherit;
}

.actor-status-button:hover {
  border-color: var(--accent);
}

.mfa-steps {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
}

.mfa-qr {
  justify-self: center;
  width: 196px;
  height: 196px;
  padding: 8px;
  border-radius: 10px;
  background: #fff;
}

.mfa-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.mfa-secret {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.86rem;
}

.mfa-secret span {
  color: var(--muted);
}

.mfa-secret code,
.mfa-recovery-codes code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

.mfa-setup,
.mfa-recovery {
  display: grid;
  gap: 12px;
}

.mfa-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.mfa-recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  margin: 0;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  list-style: none;
}

.mfa-recovery-actions,
.account-security-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mfa-back {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.account-security-modal {
  width: min(520px, calc(100vw - 32px));
}

.account-security-section {
  display: grid;
  gap: 12px;
}

.account-security-section h3,
.account-security-section p {
  margin: 0;
}

.account-security-who {
  color: var(--muted);
  font-size: 0.86rem;
}

.account-security-form {
  display: grid;
  gap: 10px;
}

.account-security-form label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.mfa-recovery-actions a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* Notifiche (campanella) */
.notification-center {
  position: relative;
}

.notification-bell {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
}

.notification-bell:hover {
  border-color: var(--accent);
}

.notification-bell-icon {
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: url("/assets/icons/bell.svg") center / contain no-repeat;
  mask: url("/assets/icons/bell.svg") center / contain no-repeat;
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e5484d;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 19px;
  text-align: center;
}

.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(380px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 120px));
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.notification-panel[hidden] {
  display: none;
}

.notification-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.notification-list {
  overflow-y: auto;
  padding: 6px;
}

.notification-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 0;
  padding: 9px 10px 9px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  position: relative;
}

.notification-item:hover {
  background: var(--surface-selected);
}

.notification-item.unread::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 14px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}

.notification-item:not(.unread) strong {
  font-weight: 600;
}

.notification-kind {
  color: var(--accent-strong, var(--accent));
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.notification-body,
.notification-item small {
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .notification-panel {
    position: fixed;
    top: 72px;
    left: 16px;
    right: 16px;
    width: auto;
  }
}
