/* ============================================================
   ClinicFlow Pro — css/responsive.css
   All breakpoints + mobile UI fixes

   ISSUE 7 FIX: Mobile topbar was overcrowded/overflowing.
   Changes at max-width 768px:
   - "إضافة" button: icon-only (text hidden)
   - Page title: font-size reduced to 0.85rem
   - User name: truncated to ~3 chars, font 0.8rem
   ============================================================ */

/* ── 1200px ── */
@media (max-width: 1200px) {
  :root { --content-padding: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.wide { grid-column: 1; }
}

/* ── 992px ── */
@media (max-width: 992px) {
  :root { --sidebar-width: 220px; --content-padding: 16px; }
  .sidebar-logo .logo-text strong { font-size: 13px; }
  .sidebar-nav a { padding: 9px 10px; font-size: 13px; }
  #topbar { padding: 0 16px; }
  #page-title { font-size: var(--font-size-md); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
}

/* ════════════════════════════════════
   768px — MAJOR LAYOUT SWITCH
   ════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --topbar-height: 56px;
    --content-padding: 14px;
    --sidebar-width: 280px;
  }

  /* Sidebar → drawer */
  #sidebar {
    transform: translateX(100%);
    transition: transform var(--transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: -8px 0 32px rgba(0,0,0,0.25);
  }

  /* Topbar full width */
  #topbar { right: 0; padding: 0 10px; height: var(--topbar-height); }
  #menu-toggle { display: flex; }

  /* Content: no sidebar offset */
  #main-content {
    margin-right: 0;
    margin-top: var(--topbar-height);
    padding: var(--content-padding);
    padding-bottom: calc(var(--bottomnav-height) + 16px);
  }

  /* Bottom nav visible */
  #bottom-nav { display: flex; }

  /* ── ISSUE 7 FIX: Topbar elements compact on mobile ── */

  /* Page title: smaller font, limit width */
  #page-title {
    font-size: 0.85rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* "إضافة" button: hide text, show only + icon */
  #add-dropdown-toggle .btn-text {
    display: none;
  }
  #add-dropdown-toggle {
    padding: 6px 10px;
    min-width: 36px;
  }
  /* Hide text node inside button — keep only icon */
  #add-dropdown-toggle i + * {
    display: none;
  }

  /* User name in topbar: max 3 chars visible */
  #user-name {
    max-width: 2.4rem;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
    font-size: 0.8rem;
  }

  /* User dropdown toggle: compact */
  #user-dropdown-toggle {
    gap: 4px;
    padding: 6px 8px;
  }
  #user-dropdown-toggle .fa-chevron-down {
    display: none;
  }

  /* Topbar left: reduce gap */
  .topbar-left { gap: 4px; }
  .topbar-right { gap: 4px; }

  /* Notification bell: keep compact */
  #notifications-btn { padding: 6px; }

  /* Topbar title area min-width 0 to allow flex shrink */
  .topbar-right { min-width: 0; flex: 1; overflow: hidden; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-left { width: 100%; }

  /* Stat cards: 2 cols */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-card .stat-value { font-size: var(--font-size-xl); }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 20px; }

  /* Form rows: 1 col */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  /* Modals: bottom sheet */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    max-height: 92vh;
    max-width: 100%;
    width: 100%;
    animation: slideInUp 0.3s ease forwards;
  }
  .modal.modal-sm,
  .modal.modal-md,
  .modal.modal-lg,
  .modal.modal-xl { max-width: 100%; }

  @keyframes slideInUp {
    from { transform: translateY(100%); opacity: .5; }
    to   { transform: translateY(0);    opacity: 1;  }
  }

  /* Demo banner */
  #demo-banner { font-size: 12px; padding: 6px 12px; }
  body.has-demo-banner #topbar  { top: 34px; }
  body.has-demo-banner #sidebar { top: 34px; height: calc(100vh - 34px); }
  body.has-demo-banner #main-content { margin-top: calc(var(--topbar-height) + 34px); }

  /* Dashboard */
  .dashboard-grid { grid-template-columns: 1fr; gap: 14px; }

  /* Filter panel: 1 col */
  .filter-grid { grid-template-columns: 1fr; }

  /* Toast: above bottom nav */
  #toast-container {
    bottom: calc(var(--bottomnav-height) + 16px) !important;
    left: 14px;
    right: 14px;
    max-width: none;
  }

  /* Charts */
  .charts-grid { grid-template-columns: 1fr; gap: 14px; }
  .chart-card.wide { grid-column: 1; }

  /* ── MOBILE TABLE: 6-Column Compact ── */

  /* Disable the rotateX flip on mobile */
  .table-container {
    transform: none !important;
    -webkit-transform: none !important;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius);
  }
  .table-scroll {
    transform: none !important;
    -webkit-transform: none !important;
  }

  /* Compact table */
  .table { min-width: 520px; font-size: 0.78rem; }
  .table thead th { padding: 8px 6px; font-size: 0.72rem; white-space: nowrap; }
  .table tbody td { padding: 8px 6px; font-size: 0.78rem; }

  /* PATIENTS: show 6 cols — hide service(5), price(6), paid(7), debt(8), visits(9), date(10) */
  #patients-table th:nth-child(5),
  #patients-table td:nth-child(5),
  #patients-table th:nth-child(6),
  #patients-table td:nth-child(6),
  #patients-table th:nth-child(7),
  #patients-table td:nth-child(7),
  #patients-table th:nth-child(8),
  #patients-table td:nth-child(8),
  #patients-table th:nth-child(9),
  #patients-table td:nth-child(9),
  #patients-table th:nth-child(10),
  #patients-table td:nth-child(10) { display: none; }

  /* APPOINTMENTS: hide date(5), source(7) */
  #appointments-table th:nth-child(5),
  #appointments-table td:nth-child(5),
  #appointments-table th:nth-child(7),
  #appointments-table td:nth-child(7) { display: none; }

  /* DOCTORS: hide specialty(3), phone(4), patients(6) */
  #doctors-table th:nth-child(3),
  #doctors-table td:nth-child(3),
  #doctors-table th:nth-child(4),
  #doctors-table td:nth-child(4),
  #doctors-table th:nth-child(6),
  #doctors-table td:nth-child(6) { display: none; }

  /* Action buttons compact */
  .table-actions { display: flex; gap: 3px; flex-wrap: nowrap; }
  .table-actions .btn { padding: 4px 5px; font-size: 0.72rem; min-width: 26px; height: 26px; }
  .table-actions .btn i { margin: 0; font-size: 12px; }

  /* Badge compact */
  .badge { font-size: 0.68rem; padding: 2px 5px; }

  /* Avatar smaller */
  .avatar-sm { width: 26px; height: 26px; font-size: 10px; }

  /* Name cell: truncate */
  #patients-table td:nth-child(2),
  #appointments-table td:nth-child(2) {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Settings */
  .theme-selector { flex-direction: column; }
  .theme-option { flex-direction: row; min-width: unset; }
  .statement-card-header { flex-direction: column; align-items: flex-start; }
  .statement-summary { gap: 12px; }
  .month-selector span { min-width: 120px; font-size: var(--font-size-md); }
  .settings-card { padding: 16px; }
}

/* ── 576px ── */
@media (max-width: 576px) {
  :root { --content-padding: 12px; }

  .stats-grid { grid-template-columns: 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; gap: 12px; }

  #bottom-nav button { padding: 4px 8px; min-width: 50px; }
  #bottom-nav button .bnav-icon { font-size: 20px; }
  #bottom-nav button span { font-size: 9px; }

  .card-body { padding: 14px; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  .table { min-width: 440px; font-size: 0.72rem; }
  .table thead th,
  .table tbody td { padding: 6px 4px; }

  /* Extra tight topbar on very small screens */
  #page-title { max-width: 90px; font-size: 0.8rem; }
  #user-name  { max-width: 1.8rem; }
}

/* ── Touch targets ── */
@media (max-width: 768px) {
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .sidebar-nav a { min-height: 44px; }
  .form-input, .form-select, .form-textarea { min-height: 44px; }
  .dropdown-item { min-height: 44px; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #sidebar { transition: none !important; }
}

/* ── Landscape mobile ── */
@media (max-width: 768px) and (orientation: landscape) {
  #main-content { padding-bottom: calc(var(--bottomnav-height) + 10px); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { max-height: 96vh; }
}

/* ── Print ── */
@media print {
  #sidebar, #topbar, #bottom-nav, #demo-banner,
  #toast-container, .modal-overlay, .btn { display: none !important; }
  #main-content { margin: 0 !important; padding: 0 !important; }
  .page { display: block !important; }
  body { background: white !important; color: black !important; }
  .card, .table-container { box-shadow: none !important; border: 1px solid #ccc !important; }
}
