:root {
  --sidebar-width: 260px;
  --header-height: 60px;
  --sidebar-bg: #050608;
  --sidebar-bg-soft: #0b0e12;
  --sidebar-text: #f8fafc;
  --sidebar-text-muted: #9ca3af;
  --sidebar-pill-active: #f03738;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  background-color: #f4f7fa !important;
  color: #111827;
  margin: 0;
  overflow-x: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  display: flex;
  flex-direction: column;
  top: 0;
  left: 0;
  background: var(--sidebar-bg);
  color: #fff;
  transition: all 0.3s;
  z-index: 1000;
}

.sidebar-header {
  height: 88px;
  display: flex;
  align-items: center;
  padding: 12px 18px 10px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.sidebar-logo {
  height: 40px;
  width: auto;
}

.sidebar-subtitle {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sidebar-text-muted);
}

.sidebar-menu {
  padding: 16px 12px 24px;
  flex: 1 1 auto;
  overflow: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  margin: 3px 4px;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}

.sidebar-link i {
  width: 20px;
  text-align: center;
  font-size: 0.95rem;
}

.sidebar-link:hover {
  background-color: rgba(148, 163, 184, 0.16);
  color: var(--sidebar-text);
}

.sidebar-link.active {
  background-color: var(--sidebar-pill-active);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(248, 250, 252, 0.08);
}

.sidebar-link.active i {
  color: #ffffff;
}

.sidebar-link-with-children {
  margin: 4px 0 2px;
}

.sidebar-link-with-children > .sidebar-link {
  width: 100%;
  justify-content: space-between;
  padding-right: 14px;
  background-color: transparent;
  margin: 4px 0;
}

.sidebar-link-with-children > .sidebar-link span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.sidebar-link-with-children > .sidebar-link .fa-chevron-down {
  font-size: 0.65rem;
  opacity: 0.75;
  transition: transform 0.15s ease;
}

.sidebar-link-with-children
  > .sidebar-link[aria-expanded="true"]
  .fa-chevron-down {
  transform: rotate(180deg);
}

.sidebar-sublink {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 32px;
  margin: 2px 4px;
  font-size: 0.9rem;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  border-radius: 10px;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}

.sidebar-sublink i {
  width: 18px;
  text-align: center;
  font-size: 0.85rem;
}

.sidebar-sublink:hover {
  background-color: rgba(148, 163, 184, 0.16);
  color: var(--sidebar-text);
}

.sidebar-sublink.active {
  background-color: var(--sidebar-pill-active);
  color: #ffffff;
}

.main-wrapper {
  margin-left: var(--sidebar-width);
  transition: all 0.3s;
  background-color: transparent;
}

.top-header {
  height: var(--header-height);
  background-color: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 999;
}

.content-container {
  padding: 1.5rem 2rem;
}

@media (max-width: 768px) {
  .sidebar {
    margin-left: calc(var(--sidebar-width) * -1);
  }

  .sidebar.active {
    margin-left: 0;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
  }

  .sidebar-overlay.active {
    display: block;
  }
}

.page-header-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card.shadow-sm {
  box-shadow:
    0 0.125rem 0.25rem rgba(0, 0, 0, 0.075),
    0 0.5rem 1rem rgba(0, 0, 0, 0.05) !important;
  border-radius: 12px;
}

.dashboard-card {
  border-radius: 1rem;
  border: 1px solid rgba(0, 0, 0, 0.05) !important;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  background-color: #ffffff;
}

.dashboard-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1) !important;
}

.dashboard-card.card-aziende {
  border-left: 5px solid #0d6efd !important;
}

.contratto-card {
  border-radius: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.35) !important;
  background-color: #ffffff;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.contratto-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.1) !important;
  border-color: rgba(248, 113, 113, 0.8) !important;
}

.contratto-card .contratto-title {
  font-size: 0.96rem;
}

.dashboard-card.card-personale {
  border-left: 5px solid #198754 !important;
}

.dashboard-card.card-utenti {
  border-left: 5px solid #fd7e14 !important;
}

.dashboard-card.card-filiali {
  border-left: 5px solid #6c757d !important;
}

.icon-wrapper {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* KPI compact cards per dashboard */
.kpi-card {
  background-color: #ffffff;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
}

.kpi-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.kpi-card-body {
  flex: 1 1 auto;
}

.kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  font-weight: 600;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  color: #111827;
}

.kpi-card-total .kpi-card-icon {
  background-color: #fee2e2;
  color: #b91c1c;
}

.kpi-card-todo .kpi-card-icon {
  background-color: #fef3c7;
  color: #b45309;
}

.kpi-card-in-corso .kpi-card-icon {
  background-color: #e0f2fe;
  color: #0369a1;
}

.kpi-card-done .kpi-card-icon {
  background-color: #dcfce7;
  color: #15803d;
}

.kpi-card-lavorazioni .kpi-card-icon {
  background-color: #e5e7eb;
  color: #374151;
}

.kpi-card-pendenti .kpi-card-icon {
  background-color: #fef3c7;
  color: #b45309;
}

.kpi-card-contratti .kpi-card-icon {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.kpi-card-incassi .kpi-card-icon {
  background-color: #dcfce7;
  color: #15803d;
}

/* Stile base per pagina login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #ffffff;
  border-radius: 1rem;
  padding: 1.75rem 1.75rem 1.25rem;
  box-shadow: 0 15px 30px rgba(15, 23, 42, 0.2);
}

.login-header h4 {
  font-weight: 600;
}

.login-body {
  margin-top: 1rem;
}

/* Clienti page - stile tipo pill cards */
.clienti-search-form {
  margin: 0 0 1.5rem;
}

.clienti-search-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.clienti-search-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: #f9fafb;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
}

.clienti-search-inner i {
  font-size: 0.95rem;
}

.clienti-search-input {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  padding-left: 0;
}

.clienti-search-input:focus {
  outline: none;
}

.client-pill-card {
  width: 100%;
  border-radius: 999px;
  background-color: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 0.35rem 0.6rem 0.35rem 0.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.06);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease;
}

.client-pill-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
  border-color: rgba(248, 113, 113, 0.8);
}

.client-pill-main {
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.4rem;
  flex: 1 1 auto;
  text-align: left;
  min-width: 0; /* Crucial for ellipsis in flexbox */
}

.client-pill-main:focus {
  outline: none;
}

.client-pill-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 999px;
  background-color: #fee2e2;
  color: #dc2626;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.client-pill-name {
  font-weight: 500;
  font-size: 0.95rem;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.client-pill-actions {
  flex-shrink: 0;
}

.client-pill-actions .btn {
  border-radius: 999px !important;
  padding: 0.25rem 0.6rem;
}

@media (max-width: 576px) {
  .clienti-search-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .clienti-search-wrapper .btn {
    width: 100%;
  }

  .client-pill-card {
    border-radius: 12px;
    padding-right: 0.4rem;
  }

  .client-pill-name {
    font-size: 0.9rem;
  }

  .client-pill-main {
    gap: 0.5rem;
  }

  .client-pill-icon {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
}

/* Autocomplete suggestions */
.autocomplete-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  z-index: 1050;
  max-height: 250px;
  overflow-y: auto;
  margin-top: 2px;
}

.suggestion-item {
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
  transition: background-color 0.15s;
}

.suggestion-item:hover {
  background-color: #f8fafc;
}

.suggestion-item:last-child {
  border-bottom: none;
}

/* Mobile Enhancements for Vertical Viewport */
@media (max-width: 576px) {
  .content-container {
    padding: 1rem 0.5rem;
  }

  .main-container {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
  }

  .top-header {
    padding: 0 12px;
  }

  h2 {
    font-size: 1.5rem;
  }

  .card-body {
    padding: 1rem;
  }

  /* Stack KPI cards more tightly */
  .kpi-card {
    padding: 12px 16px;
    gap: 12px;
  }

  .kpi-value {
    font-size: 1.5rem;
  }

  .kpi-card-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  /* Form fields optimization */
  .form-label {
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
  }

  .form-control,
  .form-select {
    padding: 0.6rem 0.75rem;
    font-size: 1rem; /* Prevent zoom on iOS */
  }

  /* Buttons on mobile */
  .btn {
    padding: 0.6rem 1rem;
  }

  .d-flex.justify-content-end.gap-2 {
    flex-direction: column-reverse;
  }

  .d-flex.justify-content-end.gap-2 .btn {
    width: 100%;
  }

  /* Suggestion items larger for touch */
  .suggestion-item {
    padding: 12px 15px;
    font-size: 1rem;
  }
}

/* Team avatar */
.team-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  user-select: none;
}

img.team-avatar {
  object-fit: cover;
}

/* Extra small devices optimization */
@media (max-width: 380px) {
  .sidebar-logo {
    height: 32px;
  }

  .kpi-label {
    font-size: 0.65rem;
  }
}
