/* iCOACH Mobile-First Responsive Enhancements */

/* ── DataTables theme overrides ── */
.dataTables_wrapper { font-family: inherit; font-size: 13px; }
.dataTables_wrapper .dataTables_length select { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line, #dfe5ec); }
.dataTables_wrapper .dataTables_filter input { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line, #dfe5ec); outline: none; }
.dataTables_wrapper .dataTables_filter input:focus { border-color: var(--orange, #c96b2c); box-shadow: 0 0 0 3px rgba(201,107,44,0.1); }
.dataTables_wrapper .dataTables_paginate .paginate_button { border-radius: 8px !important; border: 1px solid var(--line, #dfe5ec) !important; margin: 0 2px; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--orange, #c96b2c) !important; color: #fff !important; border-color: var(--orange, #c96b2c) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { background: #f4f6f9 !important; color: var(--text, #1f2937) !important; }
.dataTables_wrapper .dataTables_info { color: var(--muted, #6b7280); font-size: 12px; }
.dt-top, .dt-bottom { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; flex-wrap: wrap; gap: 8px; }
table.dataTable thead th { border-bottom: 2px solid var(--line, #dfe5ec) !important; }
table.dataTable.no-footer { border-bottom: 1px solid var(--line, #dfe5ec) !important; }

/* ── Hamburger menu toggle (hidden on desktop) ── */
.mobile-menu-toggle {
  display: none;
  border: 0;
  background: none;
  font-size: 26px;
  cursor: pointer;
  padding: 8px;
  color: var(--cdb-text, #0f1b3d);
  line-height: 1;
}

/* ── Toast notifications ── */
.flash {
  position: relative;
  animation: flashSlideIn 0.3s ease-out;
}
.flash.flash-dismiss {
  animation: flashSlideOut 0.4s ease-in forwards;
}
@keyframes flashSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes flashSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); height: 0; padding: 0; margin: 0; overflow: hidden; }
}
.flash .flash-close {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  padding: 4px 8px;
}
.flash .flash-close:hover { opacity: 1; }

/* ── Loading overlay for forms ── */
.form-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}
.form-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--line, #dfe5ec);
  border-top-color: var(--orange, #c96b2c);
  border-radius: 50%;
  animation: formSpin 0.6s linear infinite;
  z-index: 10;
}
@keyframes formSpin {
  to { transform: rotate(360deg); }
}

/* ── Confirm dialog ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  z-index: 10000;
  animation: confirmFadeIn 0.15s ease-out;
}
@keyframes confirmFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.confirm-dialog {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  text-align: center;
}
.confirm-dialog h3 {
  margin: 0 0 8px;
  font-size: 17px;
  color: #1f2937;
}
.confirm-dialog p {
  margin: 0 0 20px;
  color: #6b7280;
  font-size: 14px;
  line-height: 1.5;
}
.confirm-dialog .confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-dialog .btn { min-width: 100px; }

/* ── Validation error styling ── */
.field-error .input,
.field-error textarea,
.field-error select {
  border-color: #e73842 !important;
  box-shadow: 0 0 0 3px rgba(231, 56, 66, 0.1);
}
.field-error-msg {
  color: #e73842;
  font-size: 12px;
  margin-top: 4px;
  font-weight: 600;
}

/* ── Scrollable tables on mobile ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ══════════════════════════════════════════════════
   TABLET (≤ 1024px)
   ══════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .cdb-topbar-inner {
    grid-template-columns: auto 1fr auto !important;
    padding: 12px 16px !important;
    min-height: 64px !important;
    gap: 12px !important;
  }
  .cdb-welcome-mini { display: none !important; }
  .cdb-profile-block { display: none !important; }
  .cdb-logo { height: 38px !important; }
  .cdb-logo-wrap {
    border-right: 0 !important;
    padding-right: 0 !important;
    height: auto !important;
  }

  .page { padding: 14px 16px !important; }
  .tabs { padding: 12px 16px 0 !important; }

  .auth-wrap { grid-template-columns: 1fr !important; max-width: 480px !important; }
  .auth-wrap .hero { display: none; }

  .filters {
    grid-template-columns: repeat(4, minmax(120px, 1fr)) !important;
    gap: 10px !important;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px !important;
  }

  .detail-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .edit-panel .grid-form,
  .edit-panel > form > div:first-of-type {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ══════════════════════════════════════════════════
   MOBILE (≤ 768px)
   ══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .mobile-menu-toggle { display: block; }

  .cdb-topbar-inner {
    grid-template-columns: auto 1fr auto !important;
    min-height: 56px !important;
  }

  .tabs {
    display: none !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    padding: 8px 12px !important;
    gap: 4px !important;
    background: #fff !important;
    border-bottom: 1px solid var(--cdb-line, #dfe6f0) !important;
  }
  .tabs.mobile-open {
    display: flex !important;
  }
  .tabs a {
    flex: 1 1 auto !important;
    justify-content: center !important;
    font-size: 12px !important;
    padding: 10px 12px !important;
    min-width: 0 !important;
    border-radius: 8px !important;
    border: 1px solid #e2e8f0 !important;
    margin-bottom: 0 !important;
  }
  .tabs a.active {
    border-bottom: 1px solid var(--cdb-blue, #2563d9) !important;
    margin-bottom: 0 !important;
  }

  .subtabs {
    flex-direction: column !important;
    padding: 8px 16px !important;
    gap: 4px !important;
  }
  .subtabs a {
    font-size: 12px !important;
    padding: 8px 14px !important;
  }

  .page { padding: 12px !important; }

  .filters {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .stat-card { padding: 12px !important; }

  .card-header.split {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .detail-grid { grid-template-columns: 1fr !important; }

  .edit-panel .grid-form,
  .edit-panel > form > div:first-of-type {
    grid-template-columns: 1fr !important;
  }

  .table .actions { white-space: nowrap; }

  .form-actions {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .form-actions .btn { width: 100% !important; }

  .timeline-horizontal {
    flex-direction: column !important;
    align-items: flex-start !important;
  }
  .timeline-connector {
    width: 2px !important;
    height: 20px !important;
    margin: 0 0 0 14px !important;
  }

  .cdb-bell-dropdown {
    position: fixed !important;
    right: 8px !important;
    left: 8px !important;
    top: 60px !important;
    width: auto !important;
    max-height: 70vh;
    overflow-y: auto;
  }

  .charts-grid {
    grid-template-columns: 1fr !important;
  }

  .analytics-download-bar {
    flex-direction: column !important;
    gap: 8px !important;
  }
}

/* ══════════════════════════════════════════════════
   SMALL PHONE (≤ 480px)
   ══════════════════════════════════════════════════ */
@media (max-width: 480px) {
  body { font-size: 13px; }

  .filters {
    grid-template-columns: 1fr !important;
  }

  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .table th, .table td {
    padding: 8px 6px !important;
    font-size: 11px !important;
  }

  .btn { font-size: 12px !important; padding: 8px 12px !important; }

  .cdb-hero-card h1 { font-size: 20px !important; }
  .cdb-stats-row { grid-template-columns: 1fr !important; }

  .confirm-dialog { padding: 20px; }
}
