/**
 * Tema avanzato riutilizzabile su tutte le pagine
 */

body.app-theme {
  --hero-border: rgba(13, 110, 253, 0.18);
  --hero-shadow: 0 25px 65px rgba(15, 23, 42, 0.15);
  --card-shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
}

body.app-theme main {
  padding-bottom: 3rem;
}

body.app-theme .card {
  border-radius: 1.25rem;
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.03);
  overflow: hidden;
}

:root[data-bs-theme='dark'] body.app-theme .card {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

body.app-theme .page-hero {
  border-radius: 1.8rem;
  border: 1px solid var(--hero-border);
  background: radial-gradient(circle at 10% 20%, rgba(13, 202, 240, 0.18), transparent 55%),
              linear-gradient(135deg, rgba(13, 110, 253, 0.08), rgba(116, 69, 255, 0.08));
  box-shadow: var(--hero-shadow);
  padding: clamp(1.75rem, 3vw, 2.75rem);
  overflow: hidden;
  position: relative;
}

body.app-theme .page-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 0%, rgba(255, 255, 255, 0.35), transparent 45%);
  pointer-events: none;
}

:root[data-bs-theme='dark'] body.app-theme {
  --hero-border: rgba(255, 255, 255, 0.1);
  --hero-shadow: 0 30px 70px rgba(0, 0, 0, 0.65);
}

:root[data-bs-theme='dark'] body.app-theme .page-hero {
  background: radial-gradient(circle at 15% 20%, rgba(13, 110, 253, 0.35), transparent 45%),
              linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(13, 110, 253, 0.2));
}

body.app-theme .hero-eyebrow {
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(15, 23, 42, 0.55);
}

:root[data-bs-theme='dark'] body.app-theme .hero-eyebrow {
  color: rgba(255, 255, 255, 0.7);
}

body.app-theme .hero-title {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 700;
}

body.app-theme .hero-subtitle {
  font-size: 0.95rem;
  max-width: 540px;
}

body.app-theme .hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

body.app-theme .hero-actions .btn {
  border-radius: 999px;
  padding-inline: 1rem;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.12);
}

body.app-theme .matteo-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

body.app-theme .matteo-nav .btn {
  border-radius: 999px;
  flex: 1 1 180px;
}

body.app-theme .hero-metrics {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

body.app-theme .hero-metric-card {
  border-radius: 1.2rem;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 15px 35px rgba(15, 23, 42, 0.12);
  min-height: 120px;
  overflow: hidden;
}

:root[data-bs-theme='dark'] body.app-theme .hero-metric-card {
  background: rgba(15, 23, 42, 0.8);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

body.app-theme .hero-metric-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  font-weight: 600;
}

body.app-theme .hero-metric-value {
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  font-weight: 700;
  margin-top: 0.2rem;
}

body.app-theme .hero-metric-caption {
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* Summary cards */
body.app-theme .agent-summary-card {
  border: none;
  border-radius: 1.25rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, rgba(13, 110, 253, 0.12), rgba(13, 110, 253, 0.02));
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

body.app-theme .agent-summary-card.academy {
  background: linear-gradient(135deg, rgba(131, 56, 236, 0.16), rgba(131, 56, 236, 0.04));
}

body.app-theme .agent-summary-card .value-amount {
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  font-weight: 700;
  display: flex;
  gap: 0.35rem;
  align-items: baseline;
}

body.app-theme .agent-summary-card .value-amount span {
  font-size: 1rem;
}

body.app-theme .agent-summary-card .metric-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(15, 23, 42, 0.6);
}

:root[data-bs-theme='dark'] body.app-theme .agent-summary-card .metric-label {
  color: rgba(255, 255, 255, 0.65);
}

body.app-theme .filter-card {
  border: none;
  box-shadow: var(--card-shadow);
}

body.app-theme .filter-card .card-header {
  border-bottom: none;
  background: transparent;
  padding-bottom: 0;
}

body.app-theme .filter-grid > div {
  min-width: 160px;
}

/* Matteo sections */
body.app-theme .matteo-form-stack {
  display: grid;
  gap: 1rem;
}

body.app-theme .matteo-agent-block {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 1.25rem;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

:root[data-bs-theme='dark'] body.app-theme .matteo-agent-block {
  background: rgba(15, 23, 42, 0.75);
  border-color: rgba(255, 255, 255, 0.12);
}

body.app-theme .agent-title {
  font-weight: 600;
}

body.app-theme .agent-subtitle {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
}

/* Accordion refinements */
body.app-theme .accordion-item {
  border-radius: 1.25rem;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
  margin-bottom: 0.75rem;
}

body.app-theme .accordion-button {
  font-weight: 600;
  gap: 0.75rem;
}

body.app-theme .accordion-button:not(.collapsed) {
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.05);
}

body.app-theme .accordion-body {
  background: color-mix(in srgb, var(--bs-body-bg) 92%, white);
}

@supports not (color-mix(in srgb, black 50%, white 50%)) {
  body.app-theme .accordion-body {
    background: rgba(0, 0, 0, 0.01);
  }
}

/* Tabelle */
body.app-theme .table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

body.app-theme .table tbody tr:hover {
  background: color-mix(in srgb, var(--bs-primary) 3%, transparent);
}

body.app-theme .table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Progress bar */
body.app-theme .target-progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(13, 110, 253, 0.15);
  position: relative;
  overflow: hidden;
}

body.app-theme .target-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--progress-width, 0%);
  max-width: 100%;
  background: linear-gradient(90deg, var(--bs-primary), var(--bs-info));
  border-radius: inherit;
  transition: width 0.45s ease;
}

body.app-theme .target-progress-bar.is-complete {
  background: linear-gradient(90deg, var(--bs-success), var(--bs-primary));
  box-shadow: 0 0 12px rgba(25, 135, 84, 0.4);
}

body.app-theme .target-progress-meta {
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
  color: var(--bs-secondary-color);
  flex-wrap: wrap;
}

body.app-theme .target-note {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Utility */
body.app-theme .badge.text-bg-primary-subtle {
  border-radius: 999px;
  padding-inline: 0.75rem;
}

@media (max-width: 991.98px) {
  body.app-theme .hero-actions {
    width: 100%;
  }
}

/* ============================================
   RESPONSIVE MOBILE ENHANCEMENTS
   Modifiche per tema avanzato su mobile
   ============================================ */

/* ===== TABLET (768px - 991px) ===== */
@media (max-width: 991.98px) and (min-width: 768px) {
  body.app-theme .page-hero {
    padding: 2rem 1.5rem;
  }

  body.app-theme .hero-metrics {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  body.app-theme .hero-metric-card {
    padding: 0.875rem 1rem;
    min-height: 100px;
  }
}

/* ===== MOBILE (max 767px) ===== */
@media (max-width: 767.98px) {
  /* Main spacing */
  body.app-theme main {
    padding-bottom: 2rem;
  }

  /* Hero compatto */
  body.app-theme .page-hero {
    padding: 1.5rem 1rem;
    border-radius: 1rem;
  }

  body.app-theme .hero-title {
    font-size: 1.25rem;
  }

  body.app-theme .hero-subtitle {
    font-size: 0.875rem;
    max-width: 100%;
  }

  body.app-theme .hero-eyebrow {
    font-size: 0.65rem;
  }

  /* Hero metrics stack */
  body.app-theme .hero-metrics {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  body.app-theme .hero-metric-card {
    padding: 0.875rem 1rem;
    min-height: auto;
  }

  body.app-theme .hero-metric-label {
    font-size: 0.65rem;
  }

  body.app-theme .hero-metric-value {
    font-size: 1.25rem;
  }

  body.app-theme .hero-metric-caption {
    font-size: 0.75rem;
  }

  /* Hero actions full width */
  body.app-theme .hero-actions {
    flex-direction: column;
    width: 100%;
  }

  body.app-theme .hero-actions .btn {
    width: 100%;
    padding: 0.65rem 1rem;
  }

  body.app-theme .matteo-nav {
    flex-direction: column;
  }

  body.app-theme .matteo-nav .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  /* Agent summary cards */
  body.app-theme .agent-summary-card {
    padding: 1rem;
  }

  body.app-theme .agent-summary-card .value-amount {
    font-size: 1.5rem;
  }

  body.app-theme .agent-summary-card .value-amount span {
    font-size: 0.875rem;
  }

  body.app-theme .agent-summary-card .metric-label {
    font-size: 0.75rem;
  }

  /* Filter card */
  body.app-theme .filter-card {
    margin-bottom: 1rem;
  }

  body.app-theme .filter-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  body.app-theme .filter-grid > div {
    min-width: 100%;
  }

  body.app-theme .ui-table-toolbar {
    width: 100%;
    gap: 0.75rem;
    align-items: stretch !important;
  }

  body.app-theme .ui-table-toolbar-search {
    width: 100%;
  }

  body.app-theme .ui-table-toolbar-actions,
  body.app-theme .ui-table-toolbar-filters {
    width: 100%;
    gap: 0.5rem;
  }

  body.app-theme .ui-table-toolbar-actions .btn,
  body.app-theme .ui-table-toolbar-filters .ui-filter-chip {
    flex: 1 1 calc(50% - 0.5rem);
  }

  /* Matteo form stack */
  body.app-theme .matteo-form-stack {
    gap: 0.75rem;
  }

  /* Matteo agent block */
  body.app-theme .matteo-agent-block {
    padding: 0.875rem 1rem;
    border-radius: 1rem;
  }

  body.app-theme .agent-title {
    font-size: 0.95rem;
  }

  body.app-theme .agent-subtitle {
    font-size: 0.8rem;
  }

  /* Accordion compatto */
  body.app-theme .accordion-item {
    border-radius: 1rem;
    margin-bottom: 0.5rem;
  }

  body.app-theme .accordion-button {
    padding: 0.875rem 1rem;
    font-size: 0.9rem;
    gap: 0.5rem;
  }

  body.app-theme .accordion-body {
    padding: 1rem;
    font-size: 0.875rem;
  }

  /* Table più compatte */
  body.app-theme .table thead th {
    font-size: 0.65rem;
    padding: 0.5rem 0.35rem;
  }

  body.app-theme .table tbody td {
    padding: 0.5rem 0.35rem;
  }

  /* Progress bar più piccola */
  body.app-theme .target-progress {
    height: 6px;
  }

  body.app-theme .target-progress-meta {
    font-size: 0.75rem;
    flex-direction: column;
    gap: 0.25rem;
  }

  body.app-theme .target-note {
    font-size: 0.75rem;
  }

  /* Badge più piccoli */
  body.app-theme .badge.text-bg-primary-subtle {
    padding-inline: 0.5rem;
    font-size: 0.75rem;
  }
}

/* ===== MOBILE SMALL (max 575px) ===== */
@media (max-width: 575.98px) {
  body.app-theme .page-hero {
    padding: 1rem 0.75rem;
  }

  body.app-theme .hero-title {
    font-size: 1.1rem;
  }

  body.app-theme .hero-metric-card {
    padding: 0.75rem 0.875rem;
  }

  body.app-theme .agent-summary-card {
    padding: 0.875rem;
  }

  body.app-theme .matteo-agent-block {
    padding: 0.75rem 0.875rem;
  }

  body.app-theme .card {
    border-radius: 0.875rem;
  }

  body.app-theme .ui-table-toolbar-actions .btn,
  body.app-theme .ui-table-toolbar-filters .ui-filter-chip {
    flex: 1 1 100%;
  }
}

/* ===== iPHONE SMALL (max 390px) - ULTRA COMPATTO ===== */
@media (max-width: 390px) {
  body.app-theme main {
    padding-bottom: 1rem;
  }

  body.app-theme .page-hero {
    padding: 1rem 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: 0.75rem;
  }

  body.app-theme .hero-title {
    font-size: 1.05rem;
    margin-bottom: 0.2rem;
  }

  body.app-theme .hero-subtitle {
    font-size: 0.8rem;
  }

  body.app-theme .hero-eyebrow {
    font-size: 0.6rem;
  }

  body.app-theme .hero-metrics {
    gap: 0.5rem;
  }

  body.app-theme .hero-metric-card {
    padding: 0.65rem 0.75rem;
    border-radius: 0.75rem;
    min-height: auto;
  }

  body.app-theme .hero-metric-label {
    font-size: 0.6rem;
  }

  body.app-theme .hero-metric-value {
    font-size: 1rem;
  }

  body.app-theme .hero-metric-caption {
    font-size: 0.7rem;
  }

  body.app-theme .card {
    border-radius: 0.75rem;
    margin-bottom: 0.65rem;
  }

  body.app-theme .card-body {
    padding: 0.75rem;
  }

  body.app-theme .agent-summary-card {
    padding: 0.7rem;
  }

  body.app-theme .agent-summary-card .value-amount {
    font-size: 1.2rem;
  }

  body.app-theme .agent-summary-card .metric-label {
    font-size: 0.7rem;
  }

  body.app-theme .filter-card {
    margin-bottom: 0.75rem;
  }

  body.app-theme .matteo-form-stack {
    gap: 0.5rem;
  }

  body.app-theme .matteo-agent-block {
    padding: 0.65rem 0.75rem;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
  }

  body.app-theme .agent-title {
    font-size: 0.8rem;
  }

  body.app-theme .agent-subtitle {
    font-size: 0.75rem;
  }

  body.app-theme .accordion-item {
    border-radius: 0.75rem;
    margin-bottom: 0.35rem;
  }

  body.app-theme .accordion-button {
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
    gap: 0.4rem;
  }

  body.app-theme .accordion-body {
    padding: 0.75rem;
    font-size: 0.8rem;
  }

  body.app-theme .table {
    font-size: 0.7rem;
  }

  body.app-theme .table thead th {
    font-size: 0.6rem;
    padding: 0.35rem 0.25rem;
  }

  body.app-theme .table tbody td {
    padding: 0.35rem 0.25rem;
  }

  body.app-theme .target-progress {
    height: 5px;
  }

  body.app-theme .target-progress-meta {
    font-size: 0.7rem;
    gap: 0.2rem;
  }

  body.app-theme .target-note {
    font-size: 0.7rem;
  }

  body.app-theme .badge.text-bg-primary-subtle {
    padding-inline: 0.4rem;
    font-size: 0.7rem;
  }
}

/* ===== iPHONE SE (max 375px) - ANCORA PIÙ STRETTO ===== */
@media (max-width: 375px) {
  body.app-theme .page-hero {
    padding: 0.75rem 0.6rem;
    margin-bottom: 0.65rem;
  }

  body.app-theme .hero-title {
    font-size: 0.95rem;
  }

  body.app-theme .hero-subtitle {
    font-size: 0.75rem;
  }

  body.app-theme .hero-metric-card {
    padding: 0.55rem 0.65rem;
  }

  body.app-theme .card-body {
    padding: 0.65rem;
  }

  body.app-theme .agent-summary-card {
    padding: 0.65rem;
  }

  body.app-theme .matteo-agent-block {
    padding: 0.55rem 0.65rem;
  }

  body.app-theme .table {
    font-size: 0.65rem;
  }

  body.app-theme .table thead th {
    font-size: 0.55rem;
    padding: 0.25rem 0.2rem;
  }

  body.app-theme .table tbody td {
    padding: 0.25rem 0.2rem;
  }
}
