/* Import Google Fonts for distinctive typography */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;1,300&display=swap');

/* CSS Variables for cohesive theme */
:root {
  /* Palette derivata dal logo Chronos: arancione #E37B3A, grigio cerchi #A3A3A3, grigio testo #6B6B6E */
  --primary-color: #B85A1E;      /* Arancione logo scurito: regge testo bianco (~4.7:1) */
  --primary-color-end: #C4642A;  /* Secondo stop dei gradienti primari */
  --accent-color: #E37B3A;       /* Arancione esatto del logo: accenti, bordi, focus */
  --secondary-color: #8F4413;    /* Arancione bruciato: hover dei link */
  --surface-header: #E9E9E9;     /* Grigio chiaro per header di card */
  --border-color: #DAD7D3;       /* Grigio caldo per bordi e divisori */
  --neutral-light: #F5F4F2;
  --neutral-dark: #3F4045;
  --text-primary: #4A4B50;
  --text-secondary: #6B6B6E;
  --text-ice-white: #FAFAF9;     /* Testo chiaro su fondi arancioni o grigio scuro */
  --shadow-soft: 0 4px 20px rgba(63, 64, 69, 0.08);
  --shadow-strong: 0 8px 32px rgba(63, 64, 69, 0.14);

  /* Allinea le classi Bootstrap (text-primary, bg-primary, link, ecc.) alla palette */
  --bs-primary: #B85A1E;
  --bs-primary-rgb: 184, 90, 30;
  --bs-link-color: #B85A1E;
  --bs-link-color-rgb: 184, 90, 30;
  --bs-link-hover-color: #8F4413;
  --bs-link-hover-color-rgb: 143, 68, 19;
  --bs-primary-text-emphasis: #5C2D0F;
  --bs-primary-bg-subtle: #F8E6DA;
  --bs-primary-border-subtle: #EBC2A5;
  --bs-focus-ring-color: rgba(227, 123, 58, 0.25);

  /* Il tema Bootswatch Flatly ha info azzurro e grigi bluastri: li riportiamo su grigi caldi */
  --bs-info: #6B6B6E;
  --bs-info-rgb: 107, 107, 110;
  --bs-info-text-emphasis: #3F4045;
  --bs-info-bg-subtle: #EDEDED;
  --bs-info-border-subtle: #D4D4D4;
  --bs-secondary: #6B6B6E;
  --bs-secondary-rgb: 107, 107, 110;
  --bs-light: #F5F4F2;
  --bs-light-rgb: 245, 244, 242;
  --border-radius: 2px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global body styling with atmospheric background */
html, body {
  font-family: 'Source Sans Pro', sans-serif;
  background: linear-gradient(135deg, #FAF8F6 0%, #F6F4F1 50%, #F1EFEC 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Enhanced links */
a, .btn-link {
  color: var(--primary-color);
  text-decoration: none;
  transition: var(--transition);
  position: relative;
}

a:hover, .btn-link:hover {
  color: var(--secondary-color);
}

/* Refined primary buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-color-end));
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  color: var(--text-ice-white);
  font-weight: 600;
  padding: 12px 24px;
  box-shadow: var(--shadow-soft);
  transition: var(--transition);
}

.btn-primary:hover {
  border-color: var(--accent-color);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

/* Uniform all buttons to match primary style */
.btn {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-color-end)) !important;
  border: 2px solid transparent !important;
  border-radius: var(--border-radius) !important;
  color: var(--text-ice-white) !important;
  font-weight: 600 !important;
  padding: 12px 24px !important;
  box-shadow: var(--shadow-soft) !important;
  transition: var(--transition) !important;
}

.btn:hover {
  border-color: var(--accent-color) !important;
  box-shadow: var(--shadow-soft) !important;
  transform: translateY(-1px) !important;
}

/* Enhanced focus states */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(227, 123, 58, 0.25);
  border-color: var(--accent-color);
}

/* Content spacing */
.content {
  padding-top: 2rem;
}

/* Typography hierarchy */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 600;
  color: var(--neutral-dark);
  margin-bottom: 1rem;
  line-height: 1.2;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }

/* Form elements */
.form-control {
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 12px 16px;
  font-size: 1rem;
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
}

.form-control:focus {
  border-color: var(--accent-color);
  background: white;
}

/* Cards with depth */
.card {
  border: none;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-soft);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(15px);
  transition: var(--transition);
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-strong);
}

.card-header {
  background: var(--surface-header) !important;
  color: var(--neutral-dark) !important;
  border-bottom: 3px solid var(--accent-color) !important;
  padding: 1.5rem !important;
  text-align: left !important;
}

/* Override any bg-white or bg-light on card headers with maximum specificity */
.card .card-header.bg-white,
.card .card-header.bg-light,
.card-header.bg-white,
.card-header.bg-light {
  background: var(--surface-header) !important;
  color: var(--neutral-dark) !important;
  border-bottom: 3px solid var(--accent-color) !important;
}

.card-body {
  padding: 2rem;
}

/* Alert styling */
.alert {
  border: none;
  border-radius: var(--border-radius);
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
  position: relative;
  overflow: hidden;
}

.alert::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: currentColor;
}

.alert-info {
  background: linear-gradient(135deg, #d4edda, #c3e6cb);
  color: #155724;
}

.alert-danger {
  background: linear-gradient(135deg, #f8d7da, #f5c6cb);
  color: #721c24;
}

.alert-success {
  background: linear-gradient(135deg, #d1ecf1, #bee5eb);
  color: #0c5460;
}

/* Badge styling */
.badge {
  border-radius: 20px;
  font-weight: 500;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.badge.bg-primary,
.badge.bg-primary.bg-opacity-10,
.badge.bg-primary.text-primary,
.badge.bg-primary.text-white {
  color: #40474F !important;
}

/* Table enhancements */
.table {
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.table thead th {
  background: linear-gradient(135deg, var(--neutral-light), #ECEAE7);
  border: none;
  font-weight: 600;
  color: var(--text-primary);
  padding: 1rem;
}

.table tbody tr {
  transition: var(--transition);
}

.table tbody tr:hover {
  background: rgba(227, 123, 58, 0.05);
}

/* List group styling */
.list-group-item {
  border: none;
  border-radius: var(--border-radius) !important;
  margin-bottom: 8px;
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.8);
}

/* Override Bootstrap rounded classes to limit border-radius to 2px max */
.rounded, .rounded-sm, .rounded-lg, .rounded-xl, .rounded-2, .rounded-3, .rounded-pill, .rounded-circle {
  border-radius: 2px !important;
}

/* Specific overrides for different rounded sizes */
.rounded-pill {
  border-radius: 2px !important;
}

.rounded-circle {
  border-radius: 2px !important;
}

/* Ensure all elements with primary color background have ice white text */
.bg-primary,
.bg-primary * {
  color: var(--text-ice-white) !important;
}

/* Custom hover effects for table rows */
.hover-shadow:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-1px);
  transition: all 0.2s ease;
}

/* Override Bootstrap nav-pills rounded corners */
.nav-pills .nav-link {
  border-radius: 0 !important;
}

.nav-pills .nav-link.active {
  border-radius: 0 !important;
}

/* Elements with a primary-colored background get light text */
.bg-primary,
.bg-primary *,
.nav-link.active[style*="background-color"] {
  color: var(--text-ice-white) !important;
}

/* Force white text on all active nav-pills tabs */
.nav-pills .nav-link.active {
  color: var(--text-ice-white) !important;
  background-color: var(--primary-color) !important;
}

.list-group-item:hover {
  background: rgba(227, 123, 58, 0.08);
}

/* Navigation pills */
.nav-pills .nav-link {
  border-radius: 25px;
  margin: 0 4px;
  transition: var(--transition);
  font-weight: 500;
}

.nav-pills .nav-link.active {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-color-end));
}

/* Breadcrumb styling */
.breadcrumb {
  background: rgba(255, 255, 255, 0.8);
  border-radius: var(--border-radius);
  padding: 12px 20px;
  box-shadow: var(--shadow-soft);
}

.breadcrumb-item a {
  color: var(--primary-color);
  text-decoration: none;
  transition: var(--transition);
}

.breadcrumb-item a:hover {
  color: var(--secondary-color);
}

/* Validation styling */
.valid.modified:not([type=checkbox]) {
  border-color: #3C9A5F;
  box-shadow: 0 0 0 3px rgba(60, 154, 95, 0.25);
}

/* Componenti del tema Flatly con il blu notte #2c3e50 scritto nel CSS: li riportiamo alla palette */
.dropdown-menu {
  --bs-dropdown-link-color: var(--text-primary);
  --bs-dropdown-link-hover-color: var(--primary-color);
  --bs-dropdown-link-hover-bg: rgba(227, 123, 58, 0.08);
  --bs-dropdown-link-active-color: var(--text-ice-white);
  --bs-dropdown-link-active-bg: var(--primary-color);
  --bs-dropdown-header-color: var(--text-secondary);
}

.nav-pills {
  --bs-nav-pills-link-active-bg: var(--primary-color);
}

.list-group {
  --bs-list-group-active-bg: var(--primary-color);
  --bs-list-group-active-border-color: var(--primary-color);
  --bs-list-group-action-hover-bg: var(--neutral-light);
}

.progress, .progress-stacked {
  --bs-progress-bar-bg: var(--primary-color);
}

.form-check-input:checked,
.form-check-input[type=checkbox]:indeterminate {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.form-select:focus,
.form-check-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 0.25rem rgba(227, 123, 58, 0.25);
}

.nav-link:focus-visible {
  box-shadow: 0 0 0 0.25rem rgba(227, 123, 58, 0.25);
}

.form-range::-webkit-slider-thumb { background-color: var(--primary-color); }
.form-range::-moz-range-thumb { background-color: var(--primary-color); }

.invalid {
  border-color: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.25);
}

.validation-message {
  color: #e74c3c;
  font-size: 0.875rem;
  margin-top: 4px;
}

/* Error boundary */
.blazor-error-boundary {
  background: linear-gradient(135deg, #ffeaa7, #fab1a0);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-strong);
  color: #d63031;
  padding: 1.5rem 1.5rem 1.5rem 4rem;
  margin: 1rem 0;
}

/* Custom checkbox */
.darker-border-checkbox.form-check-input {
  border-color: var(--text-secondary);
}

/* Animation keyframes */
@keyframes slideUp {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse {
  0% { }
  50% { }
  100% { }
}

/* Utility classes */
.animate-in {
  animation: slideUp 0.4s ease-out;
}

.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.pulse {
  animation: pulse 1s infinite;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .card-body {
    padding: 1.5rem;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.5rem; }

  .btn {
    padding: 10px 20px;
    font-size: 0.9rem;
  }
}

/* Subtle texture overlay */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(circle at 25% 25%, rgba(227, 123, 58, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(163, 163, 163, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* FocusOnNavigate porta il focus sul primo h1 a ogni cambio pagina (serve ai lettori di schermo):
   il titolo non è cliccabile, quindi niente anello di focus visibile */
h1:focus,
h1:focus-visible {
  outline: none;
}

/* Gruppi icona + campo: l'icona prende lo stesso bordo e gli stessi angoli del campo,
   altrimenti Bootstrap le dà 1px e angoli più tondi e i due pezzi non combaciano */
.input-group > .input-group-text {
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  background: #fff;
}

/* Campo di ricerca unico (filtri, tabelle di impostazioni): un solo bordo sul contenitore,
   icona e input senza bordi propri; il focus evidenzia tutto il contenitore */
.search-field {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-field:focus-within {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(227, 123, 58, 0.2);
}

.search-field > .input-group-text,
.search-field > .search-icon {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 0 0 0 0.85rem;
}

.search-field > .form-control,
.search-field > .form-control:focus {
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  padding: 0.6rem 0.85rem;
}

/* Tendina di autocompletamento (sostituisce il datalist del sistema operativo) */
.autocomplete {
  position: relative;
}

.autocomplete-menu {
  position: absolute;
  z-index: 1050;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-strong);
  max-height: 260px;
  overflow-y: auto;
}

.autocomplete-menu li {
  padding: 0.5rem 0.75rem;
  border-radius: 0.35rem;
  cursor: pointer;
  color: var(--text-primary);
}

.autocomplete-menu li.active,
.autocomplete-menu li:hover {
  background: var(--bs-primary-bg-subtle);
  color: var(--bs-primary-text-emphasis);
}

.autocomplete-menu li mark {
  padding: 0;
  background: none;
  color: inherit;
  font-weight: 700;
}

.autocomplete-empty {
  padding: 0.5rem 0.75rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Barra di filtro sopra le tabelle di impostazioni */
.settings-search {
  max-width: 420px;
}

/* Le celle della tabella utenti non vanno a capo a meta': si scorre in orizzontale sugli schermi stretti */
.users-table td,
.users-table th {
  vertical-align: middle;
}

.users-table .row-actions {
  padding: 0.25rem 0.6rem !important;
  background: #fff !important;
  color: var(--text-secondary) !important;
  box-shadow: none !important;
}

/* Il contenuto di una card non si attacca mai al filo arancione dell'intestazione,
   anche dove la pagina usa pt-0 / pt-2 sul body */
.card-header + .card-body {
  padding-top: 1.5rem !important;
}

/* Le tendine hanno lo stesso aspetto dei campi di testo (bordo, angoli, altezza) */
.form-select {
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 12px 40px 12px 16px;
  font-size: 1rem;
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.8);
  transition: var(--transition);
}

.form-select-sm {
  padding: 6px 32px 6px 10px;
  font-size: 0.875rem;
}

/* Colori delle icone dei file per formato (componente FileIcon) */
.file-icon-pdf { color: #C62828; }
.file-icon-excel { color: #1E7145; }
.file-icon-word { color: #2B579A; }
.file-icon-ppt { color: #C43E1C; }
.file-icon-image { color: #8E5BA8; }
.file-icon-other { color: var(--text-secondary); }
