/* ═══════════════════════════════════════════════════════════════════
   CION CRM — Comprehensive Responsive Design
   Ensures ALL pages adapt to ALL screen sizes with attractive
   symmetry and full-width utilisation.
   ═══════════════════════════════════════════════════════════════════ */

/* ────────────────────── 0. FLUID FOUNDATIONS ────────────────────── */

/* Fluid content padding: scales from 12px (small) → 30px (large) */
.content-area {
  padding: clamp(12px, 2vw, 30px) 0 clamp(12px, 2vw, 30px) clamp(12px, 2vw, 30px);
}
.content-area > .section {
  padding-right: clamp(12px, 2vw, 30px);
}

/* Date filters baseline — flex row with consistent spacing */
.date-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: flex-end;
  padding: 14px 18px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  margin-bottom: 20px;
}
.date-filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
  font-size: var(--base-font-size);
  white-space: nowrap;
}
.date-filters input[type="date"],
.date-filters select {
  min-width: 140px;
  height: 38px;
  padding: 6px 10px;
  border-radius: 6px;
}
.date-filters .btn {
  align-self: flex-end;
}

/* Equal-width filter fields */
.df-field {
  flex: 1;
  min-width: 130px;
}
.df-field span {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5f6368;
  margin-bottom: 2px;
}
.df-field input[type="date"],
.df-field select {
  width: 100%;
  height: 38px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 13.5px;
  color: #3c4043;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.df-field input[type="date"]:focus,
.df-field select:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

/* Frosted glass oval "Clear Dates" button */
.btn-clear-dates {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 20px;
  border-radius: 999px;
  background: rgba(255,255,255,0.40);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.60);
  color: #3c4043;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.09), inset 0 1px 0 rgba(255,255,255,0.7);
  transition: background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  align-self: flex-end;
}
.btn-clear-dates:hover {
  background: rgba(255,255,255,0.62);
  box-shadow: 0 4px 14px rgba(0,0,0,0.13), inset 0 1px 0 rgba(255,255,255,0.8);
}
.btn-clear-dates:active {
  background: rgba(255,255,255,0.28);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Frosted glass round refresh button */
.btn-refresh-round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.40);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.60);
  color: #3c4043;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10), inset 0 1px 0 rgba(255,255,255,0.7);
  transition: background 0.2s, box-shadow 0.2s, transform 0.35s ease;
}
.btn-refresh-round:hover {
  background: rgba(255,255,255,0.62);
  box-shadow: 0 4px 14px rgba(0,0,0,0.13), inset 0 1px 0 rgba(255,255,255,0.8);
  transform: rotate(40deg);
}
.btn-refresh-round:active { transform: rotate(180deg); }

/* Section symmetry: uniform padding & spacing */
.section {
  width: 100%;
  max-width: none;
}

/*
 * ROOT CAUSE FIX: force every direct child of an active section to
 * fill the full available width regardless of its own content size.
 *
 * Why .section > * { width: 100% } alone is insufficient:
 *   In block layout a child only fills 100% of the parent's content box.
 *   If the child has no content (e.g. Clients with 0 records) the browser
 *   can still shrink-wrap it when the containing block width is ambiguous.
 *
 * CSS Grid with a single `minmax(0, 1fr)` column is layout-guaranteed:
 *   every grid item is stretched to exactly the column width — no content
 *   intrinsic size involved, no specificity conflict with other rules.
 *   This is the same pattern used by the result-row grids inside
 *   Candidates (which already worked).
 */
.section.active {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  row-gap: 0;
}

/* Grid items must not overflow their track */
.section.active > * {
  min-width: 0;
  width: 100%;
  max-width: none !important;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
}
.section-header {
  flex-wrap: wrap;
  gap: 10px;
}
.section-inner,
#userManagementContainer,
.user-management-wrapper,
.user-list-container,
.cal-toolbar,
.calendar-controls,
.calendar-navigation,
.calendar-grid-container,
.calendar-legend,
.maps-layout,
.settings-tabs,
.saved-type-nav,
.saved-searches-list,
#savedSearchesList,
.results-container,
.form-container,
.search-container-full {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}
.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Stat card values: fluid font sizing */
.stat-card .value {
  font-size: clamp(1rem, 1.2vw + 0.5rem, 1.8rem);
  word-break: break-word;
}
.stat-card .title {
  font-size: clamp(0.72rem, 0.8vw + 0.3rem, 0.92rem);
}

/* Search row items: minimum touch-friendly sizing */
.search-row input,
.search-row select {
  min-height: 38px;
}

/* Saved searches list: full-width stacked layout */
.saved-searches-list,
#savedSearchesList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.saved-search-item {
  width: 100%;
}

/* Profile modal: full width utilisation */
#profileModal .modal-content {
  width: clamp(320px, 96vw, 1400px);
  max-width: 96vw;
}

/* Timeline modal: responsive width */
#timelineModal .modal-content {
  width: clamp(320px, 96vw, 1300px);
  max-width: 96vw;
}

/* Results containers: full width */
.results-container {
  width: 100%;
  box-sizing: border-box;
}

/* ────────────────── 1. SMALL-MEDIUM (481–768px) ──────────────── */
/* Fills the gap between mobile and tablet */

@media (min-width: 481px) and (max-width: 768px) {
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
  }
  .search-row {
    gap: 8px;
  }
  .search-row input {
    min-width: 140px;
  }
}

/* ──────────────── 2. TABLET (769–1024px) ──────────────────────── */
/* Already has base rules in mobile.css; enhance here */

@media (min-width: 769px) and (max-width: 1024px) {
  .content-area {
    padding: 20px 0 20px 20px;
  }
  .content-area > .section {
    padding-right: 20px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 20px !important;
  }
  .form-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .stat-card {
    padding: 16px;
  }
  #profileModal .modal-content {
    max-width: 95vw;
  }
  /* Search row: ensure wrapping works well */
  .search-row {
    gap: 10px;
  }
  .search-row input {
    min-width: 180px;
    flex: 2;
  }
}

/* ──────────── 3. SMALL DESKTOP (1025–1279px) ───────────────── */

@media (min-width: 1025px) and (max-width: 1279px) {
  .content-area {
    padding: 24px 0 24px 24px;
  }
  .content-area > .section {
    padding-right: 24px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 26px !important;
  }
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat-card {
    padding: 18px;
  }
  .section-header {
    padding: 4px 0;
  }
}

/* ──────────── 4. STANDARD DESKTOP (1280–1439px) ──────────── */

@media (min-width: 1280px) and (max-width: 1439px) {
  .content-area {
    padding: 28px 0 28px 28px;
  }
  .content-area > .section {
    padding-right: 28px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 26px !important;
  }
  .form-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  #profileModal .modal-content {
    max-width: 1200px;
  }
}

/* ──────────── 5. LARGE DESKTOP (1440–1919px) ──────────── */

@media (min-width: 1440px) and (max-width: 1919px) {
  .content-area {
    padding: 32px 0 32px 36px;
  }
  .content-area > .section {
    padding-right: 36px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 26px !important;
  }
  .stat-card {
    padding: 22px;
  }
  .stat-card .value {
    font-size: 1.5rem;
  }
  .form-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 22px;
  }
  .search-row input {
    min-width: 280px;
  }
  #profileModal .modal-content {
    max-width: 1300px;
  }
}

/* ──────────── 6. ULTRA-WIDE (1920px+) ──────────────────── */

@media (min-width: 1920px) {
  .content-area {
    padding: 36px 0 36px 48px;
  }
  .content-area > .section {
    padding-right: 48px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 26px !important;
  }
  .stat-card {
    padding: 24px;
  }
  .stat-card .value {
    font-size: 1.65rem;
  }
  .stat-card .icon {
    width: 56px;
    height: 56px;
    font-size: 1.6rem;
  }
  .form-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }
  .search-row {
    gap: 16px;
  }
  .search-row input {
    min-width: 320px;
  }
  #profileModal .modal-content {
    max-width: 1400px;
  }
  /* Section title scales up */
  .section-title {
    font-size: clamp(var(--title-font-size), 1.4vw, 1.6rem);
  }
}

/* ──────────── 7. SUPER-WIDE (2560px+) ──────────────────── */

@media (min-width: 2560px) {
  .content-area {
    padding: 48px 0 48px 64px;
  }
  .content-area > .section {
    padding-right: 64px;
  }
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 26px !important;
  }
  .stat-card {
    padding: 28px;
  }
  .stat-card .value {
    font-size: 1.85rem;
  }
  .form-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 28px;
  }
  .section-title {
    font-size: 1.8rem;
  }
  #profileModal .modal-content {
    max-width: 1800px;
  }
}

/* ──────────── 8. DASHBOARD — FILL SCREEN VERTICALLY ──────────── */

/* Dashboard section expands to fill all available vertical space */
#dashboard.section.active {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  min-height: 0;
}

/* Cards grid takes all remaining height and rows share equal space */
#dashboard .dashboard-stats {
  flex: 1;
  min-height: 0;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  grid-auto-rows: 1fr;
  align-items: stretch;
  margin-bottom: 0;
}

/* Each stat card fills its grid cell fully */
#dashboard .stat-card {
  height: 100%;
  min-height: 120px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
}

/* Leaderboard inline band — hidden permanently, modal-only now */
#leaderboardTableContainer {
  display: none !important;
}

/* Leaderboard card is now clickable like all other cards */
#leaderboardWidget {
  cursor: pointer;
}

/* Dashboard filter row: column widths match the stat cards below */
#dashboard .date-filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 24px;
  align-items: end;
}

/* ──────────── 9. PROFILE MODAL RESPONSIVE ──────────── */

/* Profile two-column pair stacks on narrow modals */
@media (max-width: 900px) {
  [data-profile-type] .profile-two-col-pair {
    grid-template-columns: 1fr !important;
  }
  [data-profile-type] .profile-paired-row {
    grid-template-columns: 1fr !important;
  }
  [data-profile-type] .profile-layout-modern {
    flex-direction: column !important;
  }
  [data-profile-type] .profile-sidebar-area {
    width: 100% !important;
  }
  [data-profile-type] .profile-body {
    flex-direction: column !important;
  }
}

/* Profile scales up on very large screens */
@media (min-width: 1600px) {
  [data-profile-type] .candidate-profile,
  [data-profile-type] .profile-header,
  [data-profile-type] .profile-body,
  [data-profile-type] .profile-paired-row {
    max-width: 1200px;
  }
}
@media (min-width: 2000px) {
  [data-profile-type] .candidate-profile,
  [data-profile-type] .profile-header,
  [data-profile-type] .profile-body,
  [data-profile-type] .profile-paired-row {
    max-width: 1500px;
  }
}

/* ──────────── 10. SEARCH CONTAINERS ──────────────── */

/* Ensure search elements fill the row well */
.search-container-full {
  width: 100%;
  box-sizing: border-box;
}
.search-row {
  width: 100%;
}

/* On wider screens, give more breathing room to search items */
@media (min-width: 1280px) {
  .search-container-full {
    padding: 20px 24px;
  }
}

/* Stack search row vertically on very narrow screens */
@media (max-width: 600px) {
  .search-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-row input,
  .search-row select,
  .search-row .btn {
    width: 100% !important;
    min-width: unset !important;
  }
}

/* ──────────── 11. SAVED SEARCH TYPE NAVIGATION ──────────── */

.saved-type-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 600px) {
  .saved-type-nav {
    gap: 6px;
  }
  .saved-type-nav .btn {
    font-size: 12px !important;
    padding: 6px 10px !important;
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
    justify-content: center;
  }
}

/* ──────────── 12. MODALS RESPONSIVE ──────────────── */

/* Standard modals */
.modal-content {
  width: clamp(300px, 92vw, 900px);
  max-height: 92vh;
  overflow-y: auto;
}

/* Timeline/breakdown modal: near-full-screen so wide tables breathe */
#timelineModal .modal-content {
  width: 96vw !important;
  max-width: 96vw !important;
  min-width: 0 !important;
  max-height: 94vh !important;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 24px;
}

/* Days worked modal responsive */
@media (max-width: 900px) {
  #daysWorkedModal .modal-content {
    margin-left: 10px !important;
    margin-top: 60px !important;
    width: calc(100% - 20px) !important;
    max-width: 100% !important;
  }
}

/* ── Timeline table: display:table gives guaranteed column alignment ──
 *  Each .trow is display:table-row; each .tcell is display:table-cell.
 *  The browser calculates ONE shared column-width set across ALL rows,
 *  so header and data cells are always in perfect vertical alignment.
 *  This replaces the previous per-row CSS Grid approach which caused
 *  each row to independently size its columns (misalignment).
 */
.timeline-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
.timeline-grid {
  display: table;
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
.trow {
  display: table-row;
}
.trow.thead .tcell {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, rgba(30,39,73,0.85) 0%, rgba(67,97,238,0.7) 100%) !important;
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  z-index: 2;
  border-bottom: 2px solid rgba(255,255,255,0.2);
  white-space: nowrap;
}
.trow .tcell {
  display: table-cell;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(226,232,240,0.5);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
.trow:not(.thead):nth-child(even) .tcell {
  background: rgba(240,245,255,0.5);
}
.trow:not(.thead):hover .tcell {
  background: rgba(255,255,255,0.7);
}

/* ──────────── 13. TABLES & DATA GRIDS ──────────── */

/* Ensure tables scroll horizontally on small screens */
.table-container,
.results-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Data tables minimum width to prevent squishing */
table {
  min-width: 600px;
}


/* ──────────── 14. CALENDAR RESPONSIVE ──────────── */
/* Calendar always uses 7 equal columns - handled in calendar.css.
 * Only adjust cell heights at small sizes. */
@media (max-width: 600px) {
  .calendar-grid-container { overflow-x: hidden; }
}

/* ──────────── 15. MAPS LAYOUT RESPONSIVE ──────────── */

@media (min-width: 769px) {
  .maps-layout {
    display: flex;
    flex-direction: row;
  }
  #mapsSidebar {
    width: clamp(260px, 368px, 34vw);
    flex-shrink: 0;
    overflow-y: auto;
    max-height: calc(100vh - 120px);
  }
  .maps-mapwrap {
    flex: 1 1 0;
    min-width: 300px;
    min-height: 500px;
  }
}

@media (min-width: 1440px) {
  #mapsSidebar {
    width: clamp(340px, 437px, 34vw);
  }
}

/* ──────────── 16. INVOICE SECTIONS ──────────── */

/* Invoice form responsive */
@media (max-width: 768px) {
  .invoice-line-items .line-item-row {
    flex-direction: column;
    gap: 8px;
  }
  .invoice-line-items input {
    width: 100% !important;
  }
}

/* ──────────── 17. SETTINGS SECTION ──────────── */

/* Settings forms use full available width */
#settings .form-container {
  width: 100%;
  box-sizing: border-box;
}

/* ──────────── 18. USER MANAGEMENT RESPONSIVE ──────────── */

@media (max-width: 768px) {
  #users .list-entry {
    flex-direction: column !important;
    gap: 8px;
  }
}

#users .results-container {
  width: 100%;
  box-sizing: border-box;
}

/* ──────────── 19. GLOBAL SYMMETRY HELPERS ──────────── */

/* main-content must be overflow:visible so sticky top-bar works */
.main-content {
  overflow: visible;
}

/* All sections get consistent margin-bottom */
.section > .section-header {
  margin-bottom: clamp(14px, 2vw, 25px);
}

/* Form containers: responsive padding */
.form-container {
  padding: clamp(14px, 2vw, 25px);
}

/* Search results count: full width */
.search-results-count {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
}

/* Sort container: full width */
.sort-container {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
}

/* Ensure buttons don't overflow on narrow screens */
.section-actions .btn {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ──────────── 20. LANDSCAPE ORIENTATION ──────────── */

@media (orientation: landscape) and (max-height: 600px) {
  .content-area {
    padding: 8px 0 8px 16px;
  }
  .content-area > .section {
    padding-right: 16px;
  }
  .section-header {
    margin-bottom: 8px !important;
  }
  .dashboard-stats {
    gap: 8px;
  }
  .stat-card {
    padding: 10px;
  }
  .stat-card .icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    margin-bottom: 6px;
  }
  .stat-card .value {
    font-size: 1rem;
    margin-bottom: 4px;
  }
}

/* ──────────── 21. HIGH-DPI / RETINA ──────────── */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Thinner borders on high-DPI to prevent visual thickness */
  .stat-card,
  .form-container,
  .search-container-full,
  .saved-search-item,
  .list-entry {
    border-width: 0.5px;
  }
}

/* ──────────── 22. GLOBAL SEARCH RESULTS (DASHBOARD) ──────── */

#globalSearchResultsContainer {
  width: 100%;
  box-sizing: border-box;
}

/* ──────────── 23. SECTION-SPECIFIC RESULT CONTAINERS ──────── */

#candidatesResultsContainer,
#clientsResultsContainer,
#companiesResultsContainer,
#placementsResultsContainer,
#invoicesResultsContainer,
#groupPlacementsResultsContainer {
  width: 100%;
  box-sizing: border-box;
}

/* On large screens, result cards could use a grid */
@media (min-width: 1440px) {
  #candidateResults .list-entry,
  #clientResults .list-entry,
  #companyResults .list-entry {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
  }
}
