/* Shared responsive rules for every TaskFlow page. */
@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }
  html, body { min-width: 320px; max-width: 100%; }
  body { overflow-x: hidden; }
  img, canvas, svg, video, iframe { max-width: 100%; }
  .tf-wrapper { display: block; min-height: 100dvh; }
  .tf-sidebar {
    position: fixed; inset: auto 0 0; width: 100%; height: auto; min-height: 70px;
    z-index: 1030; padding: 7px max(10px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.16);
  }
  .tf-sidebar .logo { display: none; }
  .sidebar-menu { display: flex; justify-content: space-around; align-items: stretch; gap: 6px; padding: 0; margin: 0; }
  .sidebar-menu li { flex: 1 1 0; min-width: 0; height: 54px; margin: 0; padding: 4px 2px; border-radius: 14px; justify-content: center; }
  .sidebar-menu li:hover { transform: none; }
  .sidebar-menu li a { flex-direction: column; justify-content: center; gap: 5px; font-size: 9px; font-weight: 500; line-height: 1.1; text-align: center; }
  .sidebar-menu li a span { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: normal; }
  .sidebar-menu i { width: auto; font-size: 18px; }
  .sidebar-menu li.active { box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28); }
  .tf-main { width: 100%; min-width: 0; margin: 0; padding: 18px 16px calc(94px + env(safe-area-inset-bottom)); }
  .tf-main > * { min-width: 0; }
  .tf-topbar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
    min-height: 64px; height: auto; padding: 13px 16px; border-radius: 18px; gap: 12px;
  }
  .tf-topbar .page-title { grid-column: 1; grid-row: 1; min-width: 0; font-size: 20px; line-height: 1.25; text-align: left; }
  .tf-topbar .top-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; gap: 8px; flex-wrap: nowrap; }
  .tf-topbar .search-box { grid-column: 1 / -1; grid-row: 2; width: 100%; max-width: none; }
  .search-box input { min-height: 46px; font-size: 16px; }
  .top-actions > * { min-width: 0; }
  .top-actions .btn, .top-actions button { min-width: 42px; min-height: 42px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; gap: 16px; }
  .dashboard-grid > *, .table-card, .focus-card, .activity-card { grid-column: 1 / -1; grid-row: auto; min-width: 0; }
  .tf-card { min-width: 0; padding: 20px; border-radius: 18px; }
  .tf-card:hover, .project-card:hover, .task-item-card:hover { transform: none; }
  .task-item-card { min-width: 0; }
  .task-body { min-width: 0; }
  .task-header { flex-wrap: wrap; }
  .task-footer { flex-wrap: wrap; }
  .recent-task { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 16px; }
  .top-stats, .quick-stats { flex-wrap: wrap; justify-content: flex-start; gap: 10px; margin: 0; }
  .quick-stat, .top-stat { min-width: 0; }
  .notification-dropdown { width: min(calc(100vw - 24px), 380px); max-width: calc(100vw - 24px); }
  .dropdown-menu { max-width: calc(100vw - 24px); }
  .modal-dialog { width: auto; max-width: none; margin: 12px; }
  .modal-content { max-height: calc(100dvh - 24px); overflow-y: auto; border-radius: 18px; }
  .modal-body { padding: 20px; }
  .custom-modal-space { width: 100%; max-width: 100%; height: calc(100dvh - 24px); margin: 12px auto; }
  #taskCalendar { min-height: 410px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 10px; }
  .fc .fc-toolbar-title { font-size: 18px; }
  .fc .fc-button { min-height: 38px; padding: .4em .65em; font-size: .88em; }
  .calendar-project-card { width: 100%; }
  .project-list { gap: 16px; margin-top: 20px; }
  .project-card, .task-card { min-width: 0; }
  .task-card, .activity-card, .table-card { min-height: 0; }
  .focus-card { min-height: 300px; }
  .stats-grid-card { min-height: 340px; }
  .project-card .card-body, .task-item-card { padding: 18px; }
  .card, .table-responsive, .dt-container { min-width: 0; }
  .table-responsive, div.dt-container { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  input, select, textarea { min-height: 46px; font-size: 16px !important; scroll-margin-bottom: 100px; }
  button, .btn { min-height: 42px; }
}

@media (max-width: 420px) {
  .tf-main { padding: 14px 12px calc(92px + env(safe-area-inset-bottom)); }
  .tf-topbar { padding: 12px 14px; }
  .tf-topbar .page-title { font-size: 18px; }
  .tf-card { padding: 17px; }
  .sidebar-menu { gap: 4px; }
  .sidebar-menu li { border-radius: 12px; }
  .sidebar-menu li a { font-size: 8.5px; }
  .stats-item h2 { font-size: 32px; }
  .fc .fc-toolbar-chunk { display: flex; justify-content: center; flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .tf-main { padding-left: 10px; padding-right: 10px; }
  .tf-topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .tf-topbar .page-title { font-size: 17px; }
  .tf-sidebar { min-height: 116px; padding-top: 6px; }
  .sidebar-menu { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, 44px); gap: 4px 8px; }
  .sidebar-menu li { height: 44px; }
  .sidebar-menu li a { gap: 3px; font-size: 9px; }
  .sidebar-menu li a span { display: block; }
  .sidebar-menu i { font-size: 16px; }
  .tf-main { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }
}

/* Task and project screens: keep every control inside the mobile viewport. */
@media (max-width: 768px) {
  .tf-topbar > .top-stats:has(.quick-stats) {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 100%;
    min-width: 0;
    margin: 0;
  }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat {
    justify-content: center;
    gap: 6px;
    padding: 10px 6px;
    border-radius: 14px;
    text-align: center;
  }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat i { font-size: 16px; }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat span { font-size: 18px; }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat small { display: block; font-size: 10px; line-height: 1.2; }
  .tf-topbar > .top-stats:has(.quick-stats) .top-actions { justify-content: flex-end; }

  .tf-topbar > .top-stats:has(#newProjects) {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    min-width: 0;
    margin: 0;
  }
  #newProjects { min-height: 44px; padding-inline: 16px; }

  .task-card { min-height: 0 !important; }
  .task-card > .card-body { padding: 18px 16px; }
  .task-card .card-body > .d-flex.justify-content-between.align-items-center.mb-4 {
    align-items: stretch !important;
    gap: 12px;
    margin-bottom: 18px !important;
  }
  .task-card .card-body > .d-flex h3 { font-size: 20px; }
  #newTask { width: 100%; min-height: 46px; }
  #taskTable_wrapper, #taskTable_wrapper .dt-layout-row,
  #taskTable_wrapper .dt-layout-cell { width: 100%; min-width: 0; max-width: 100%; }
  #taskTable_wrapper .dt-layout-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
  #taskTable_wrapper .dt-layout-cell { display: flex; justify-content: flex-start; }
  #taskTable_wrapper .dt-search { display: flex; align-items: center; gap: 8px; width: 100%; }
  #taskTable_wrapper .dt-search input { width: min(100%, 240px); margin-left: auto; }
  #taskTable_wrapper .dt-length { max-width: 100%; }
  #taskTable_wrapper .dt-paging { max-width: 100%; overflow-x: auto; }
  #taskTable { display: block; width: 100% !important; min-width: 0 !important; border: 0; }
  #taskTable thead { display: none; }
  #taskTable tbody { display: grid; gap: 12px; width: 100%; }
  #taskTable tbody tr {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    width: 100%;
    padding: 14px;
    border: 1px solid var(--tf-border);
    border-radius: 15px;
    background: var(--tf-card);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
  }
  #taskTable.table-striped > tbody > tr:nth-of-type(odd) > *,
  #taskTable tbody > tr > * { --bs-table-bg: transparent; background: transparent !important; box-shadow: none !important; }
  #taskTable tbody td {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 0;
    padding: 4px 2px !important;
    border: 0 !important;
    overflow-wrap: anywhere;
    white-space: normal !important;
  }
  #taskTable tbody td::before {
    content: attr(data-label);
    margin-bottom: 4px;
    color: var(--tf-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .03em;
    line-height: 1.2;
    text-transform: uppercase;
  }
  #taskTable tbody td:first-child { grid-column: 1 / -1; font-weight: 600; font-size: 15px; }
  #taskTable tbody td:last-child {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    gap: 6px;
  }
  #taskTable tbody td:last-child::before { flex: 0 0 100%; margin-bottom: 0; }
  #taskTable tbody td:last-child .btn { min-width: 40px; min-height: 40px; margin: 0 5px 0 0 !important; }
  #taskTable tbody td.dataTables_empty,
  #taskTable tbody td.dt-empty { grid-column: 1 / -1; align-items: center; text-align: center; }
  #taskTable tbody td.dataTables_empty::before,
  #taskTable tbody td.dt-empty::before { content: none; }

  #projectList { flex: 0 0 100%; width: 100%; max-width: 100%; min-width: 0; margin-inline: 0; }
  .project-list { display: flex; flex-direction: column; gap: 14px; }
  .project-card { width: 100%; min-width: 0; margin: 0 !important; border-radius: 17px; }
  .project-card .card-body { min-width: 0; padding: 18px 16px; }
  .project-card .card-body > .d-flex.justify-content-between.align-items-start {
    flex-wrap: wrap;
    align-items: flex-start !important;
    gap: 10px;
  }
  .project-card .card-body > .d-flex.justify-content-between.align-items-start > div { flex: 1 1 100%; min-width: 0; }
  .project-card h4 { font-size: 18px; line-height: 1.35; overflow-wrap: anywhere; }
  .project-card p { overflow-wrap: anywhere; line-height: 1.5; }
  .project-card .badge { display: inline-block; max-width: 100%; margin-bottom: 4px; white-space: normal; overflow-wrap: anywhere; }
  .project-card .row.text-center { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-inline: 0; gap: 4px; }
  .project-card .row.text-center > .col { min-width: 0; padding: 4px 2px; }
  .project-card .row.text-center h5 { font-size: 18px; }
  .project-card .row.text-center small { display: block; font-size: 10px; line-height: 1.25; overflow-wrap: anywhere; }
  .project-card .card-body > .d-flex.justify-content-between.align-items-center { align-items: flex-start !important; flex-wrap: wrap; gap: 12px; }
  .project-card .card-body > .d-flex.justify-content-between.align-items-center > small { min-width: 0; overflow-wrap: anywhere; }
  .project-card .card-body > .d-flex.justify-content-between.align-items-center .d-flex { gap: 8px !important; }
  .project-card .card-body > .d-flex.justify-content-between.align-items-center .btn { min-width: 42px; min-height: 42px; }
  #myProjectsModal .modal-dialog { width: auto; max-width: none; margin: 12px; }
  #myProjectsModal .modal-content { width: 100%; max-width: 100%; max-height: calc(100dvh - 24px); }
  #myProjectsModal .modal-body { max-width: 100%; padding: 18px; overflow-x: hidden; overflow-y: auto; }
  #projectTaskList, #projectTaskList > * { max-width: 100%; min-width: 0; }
}

@media (max-width: 420px) {
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat { flex-direction: column; }
  .tf-topbar > .top-stats:has(.quick-stats) .quick-stat small { max-width: 100%; }
  #taskTable tbody tr { padding: 12px; gap: 7px 10px; }
  .project-card .card-body { padding: 16px 14px; }
  .project-card .row.text-center small { font-size: 9px; }
}
