/* Ajustări mobile punctuale; desktopul și datele rămân neschimbate. */
.mobile-header-logo { display: none; }

@media (max-width: 768px) {
  /* Tema light: gri mai închis pentru navigare, alb pentru secțiunea activă. */
  html body:not(.dark-mode) #sidebar .sidebar-nav .nav-item {
    color: #738481 !important;
  }

  html body:not(.dark-mode) #sidebar .sidebar-nav .nav-item.active,
  html body:not(.dark-mode) #sidebar .sidebar-nav .nav-item.mobile-profile-active {
    color: #ffffff !important;
  }

  html body .top-header { gap: 8px !important; }

  html body .top-header > div:first-child {
    flex: 1 1 auto;
    max-width: calc(100% - 44px);
  }

  html body .top-header .mobile-header-logo {
    display: inline-flex;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  html body .top-header .mobile-header-logo img {
    display: block;
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0);
  }

  html body.dark-mode .top-header .mobile-header-logo img {
    filter: none;
  }

  /* Antetul secțiunii: lizibil și accentuat, inclusiv pentru titlurile lungi. */
  html body .top-header #pageTitle {
    max-width: calc(100vw - 24px);
    overflow: visible;
    font-size: clamp(19px, 4.7vw, 22px) !important;
    font-weight: 800;
    line-height: 1.15 !important;
    letter-spacing: -0.025em;
    white-space: normal;
    text-overflow: clip;
    text-shadow: 0 0 15px color-mix(in srgb, var(--accent) 30%, transparent);
  }

  html body .top-header .header-title::after {
    display: block;
    width: 42px;
    height: 2px;
    margin-top: 5px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), transparent);
    content: "";
  }

  /* Selecturile sunt mai scunde, păstrând suficient loc pentru text. */
  html body .page-section select.form-select,
  html body .page-section .task-filter-group > select.form-select,
  html body #dashboard select.dashboard-responsabil-filter {
    box-sizing: border-box;
    height: 40px !important;
    min-height: 40px !important;
    padding: 6px 28px 6px 10px !important;
    line-height: 24px !important;
    text-overflow: ellipsis;
  }

  /* Titlu și metadate pe toată lățimea; termenele, statusul și acțiunile jos. */
  html body .task-card:not(.task-list-card) {
    align-items: flex-start !important;
    gap: 6px 7px !important;
  }

  html body .task-card:not(.task-list-card) > .task-checkbox,
  html body .task-card:not(.task-list-card) > .auto-task-icon {
    order: 0 !important;
  }

  html body .task-card:not(.task-list-card) > .task-content {
    flex: 1 1 calc(100% - 27px) !important;
    width: calc(100% - 27px) !important;
    order: 1 !important;
  }

  html body .task-card:not(.task-list-card) > .task-content .task-title {
    line-height: 1.25 !important;
  }

  html body .task-card:not(.task-list-card) > .task-content .task-meta {
    margin-top: 3px !important;
    line-height: 1.3 !important;
  }

  html body .task-card:not(.task-list-card)::before,
  html body .task-card:not(.task-list-card)::after {
    display: block;
    flex: 0 0 100%;
    width: 100%;
    height: 0;
    content: "";
  }

  html body .task-card:not(.task-list-card)::before { order: 2 !important; }
  html body .task-card:not(.task-list-card)::after { order: 4 !important; }

  html body .task-card:not(.task-list-card) > .task-overdue,
  html body .task-card:not(.task-list-card) > .study-deadline,
  html body .task-card:not(.task-list-card) > .task-priority,
  html body #studiiList .task-card:not(.task-list-card) > .study-deadline,
  html body #studiiList .task-card:not(.task-list-card) > .task-priority {
    flex: 0 1 auto !important;
    width: auto !important;
    max-width: 100% !important;
    margin: 0 !important;
    order: 3 !important;
  }

  html body .task-card:not(.task-list-card) > .btn {
    order: 5 !important;
    margin: 0 !important;
  }

  html body .task-card:not(.task-list-card) > .task-email-btn {
    margin-left: auto !important;
  }

  /* Acțiunile cu pictograme au aceeași casetă și același desen. */
  html body .page-section .data-table tbody td.mobile-actions-cell .table-row-actions > button,
  html body .page-section .data-table tbody td.mobile-actions-cell .table-row-actions > button.contact-email-button,
  html body .page-section .data-table tbody td.mobile-actions-cell button:not(.status-select),
  html body .task-card > .btn,
  html body .task-list-actions > .btn {
    display: inline-flex !important;
    flex: 0 0 36px !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 9px !important;
  }

  html body .page-section .data-table tbody td.mobile-actions-cell .table-row-actions > button i,
  html body .page-section .data-table tbody td.mobile-actions-cell button:not(.status-select) i,
  html body .task-card > .btn i,
  html body .task-list-actions > .btn i {
    width: 16px;
    font-size: 16px !important;
    line-height: 1;
    text-align: center;
  }

  /* În aceste trei liste, emailul nu mai păstrează excepția veche de 44px. */
  html body #clienti .data-table tbody td.mobile-actions-cell > button.btn,
  html body #colaboratori .data-table tbody td.mobile-actions-cell > button.btn,
  html body #echipa .data-table tbody td.mobile-actions-cell > button.btn {
    flex: 0 0 36px !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
  }

  html body #clienti .data-table tbody td.mobile-actions-cell > button.btn i,
  html body #colaboratori .data-table tbody td.mobile-actions-cell > button.btn i,
  html body #echipa .data-table tbody td.mobile-actions-cell > button.btn i {
    width: 16px;
    font-size: 16px !important;
    line-height: 1;
    text-align: center;
  }

  /* Bifa evenimentului este în colțul din dreapta, independent de rânduri. */
  html body #tabelEvenimente tbody tr { position: relative; }
  html body #tabelEvenimente .event-title-cell { display: block !important; }
  html body #tabelEvenimente .event-title-cell .task-checkbox {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 20px !important;
    min-width: 20px !important;
    height: 20px !important;
    min-height: 20px !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 5px !important;
  }

  html body #tabelEvenimente tbody td:first-child { padding-right: 28px !important; }

  /* Rezumat financiar cu toate cele cinci valori, fără pictograme decorative. */
  html body #financiar .finance-stats-grid .stat-card {
    min-height: 68px !important;
    padding: 8px 10px !important;
  }

  html body #financiar .finance-stats-grid .stat-header { margin-bottom: 5px !important; }
  html body #financiar .finance-stats-grid .stat-icon { display: none !important; }
  html body #financiar .finance-stats-grid .stat-value { line-height: 1.1 !important; }

  /* Pe mobil, statusurile din rapoarte devin șase rânduri compacte. */
  html body #rapoarte .status-chart-container,
  html body #rapoarte #statusChart.status-donut-chart {
    height: auto !important;
    min-height: 0 !important;
  }

  html body #rapoarte #statusChart.status-donut-chart {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 7px !important;
    padding: 4px 0 !important;
  }

  html body #rapoarte #statusChart .status-donut-item {
    display: flex !important;
    min-height: 48px !important;
    padding: 7px 8px !important;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--donut-color);
    border-radius: 8px;
    flex-direction: row-reverse !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 5px !important;
    background: color-mix(in srgb, var(--donut-color) 8%, var(--bg-card));
    text-align: left !important;
  }

  html body #rapoarte #statusChart .status-donut-svg { display: none !important; }
  html body #rapoarte #statusChart .status-donut-visual {
    position: static !important;
    flex: 0 0 auto;
    width: auto !important;
    height: auto !important;
  }

  html body #rapoarte #statusChart .status-donut-center {
    position: static !important;
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  html body #rapoarte #statusChart .status-donut-count {
    color: var(--donut-color);
    font-size: 17px !important;
  }

  html body #rapoarte #statusChart .status-donut-label {
    display: block !important;
    min-height: 0 !important;
    overflow: visible !important;
    line-height: 1.15 !important;
    -webkit-line-clamp: unset !important;
  }

  /* Proiecte: procentul rămâne; sortarea rămâne implicită; termenul depășit rămâne. */
  html body #tabelProiecte .project-progress-inline {
    min-width: 0 !important;
  }

  html body #tabelProiecte .project-progress-range { display: none !important; }
  html body #tabelProiecte .project-progress-percent { width: auto !important; }

  /* KPI-urile secundare din centrul proiectului nu se afișează pe mobil. */
  html body #projectCenter .project-center-kpis { display: none !important; }

  /* Cele două opțiuni Lună/An sunt centrate în caseta lor. */
  html body #calendar .calendar-period-switch {
    flex: 1 0 100% !important;
    justify-content: center !important;
    text-align: center !important;
  }

  /* Dimensiuni compacte pentru cele trei casete, cu efectele comune desktopului. */
  html body #dashboard #dashboardProjectOverview .dashboard-overview-legend {
    width: 100% !important;
    max-width: none !important;
    gap: 6px !important;
  }

  html body #dashboard #dashboardProjectOverview .dashboard-overview-legend-item {
    min-height: 76px !important;
    padding: 10px 5px !important;
    gap: 3px !important;
  }

  html body.animations-disabled #dashboard #dashboardProjectOverview .dashboard-overview-legend-item::after {
    display: none !important;
  }

  html body #dashboard #dashboardProjectOverview .dashboard-overview-legend-value {
    font-size: 17px !important;
  }

  html body #dashboard #dashboardProjectOverview .dashboard-overview-legend-label {
    max-width: none !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    -webkit-line-clamp: 2;
  }

  /* Agenda: bife compacte și avertizare pe rândul titlului, detalii dedesubt. */
  html body #dashboard #upcomingDeadlines .agenda-item {
    height: auto !important;
    min-height: 58px;
    align-items: flex-start;
    gap: 8px;
  }

  html body #dashboard #upcomingDeadlines .agenda-item > .task-checkbox,
  html body #dashboard #upcomingDeadlines .agenda-item > .task-sync-state {
    flex: 0 0 18px;
    width: 18px !important;
    min-width: 18px !important;
    height: 18px !important;
    min-height: 18px !important;
    margin-top: 3px;
    padding: 0;
    border-radius: 5px;
  }

  html body #dashboard #upcomingDeadlines .agenda-item > .task-checkbox i,
  html body #dashboard #upcomingDeadlines .agenda-item > .task-sync-state i {
    font-size: 10px !important;
  }

  html body #dashboard #upcomingDeadlines .dashboard-deadline-link {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: start;
    gap: 3px 6px;
    margin: 0;
    padding: 0;
  }

  html body #dashboard #upcomingDeadlines .deadline-info { display: contents; }

  html body #dashboard #upcomingDeadlines .agenda-item-icon {
    grid-column: 1;
    grid-row: 1 / -1;
    width: 22px;
    height: 22px;
  }

  html body #dashboard #upcomingDeadlines .deadline-task-title {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    min-width: 0;
    margin: 0;
    line-height: 1.3;
  }

  html body #dashboard #upcomingDeadlines .deadline-countdown {
    grid-column: 3;
    grid-row: 1;
    position: static;
    align-self: start;
    min-width: 0;
    margin: 0;
    padding: 2px 6px;
    line-height: 1.3;
  }

  html body.dark-mode #dashboard #upcomingDeadlines .deadline-countdown.overdue {
    color: #ff6b6b;
  }

  html body #dashboard #upcomingDeadlines .deadline-meta {
    display: block;
    grid-column: 2 / -1;
    grid-row: 2;
    min-width: 0;
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
    line-height: 1.3;
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  html body #dashboard #dashboardProjectOverview .dashboard-overview-legend-item::after {
    display: none !important;
  }
}
