/* ============================================================
   Patients Responsive Styles
   ──────────────────────────────────────────────────────────
   On screens ≤ 1024px (mobile & tablet): the patients table
   transforms into record cards. Each card lists all of the
   record's details as label → value rows. Labels come from
   data-label attributes auto-assigned by mobile-table-labels.js
   from the corresponding <th> text.
   Desktop (>1024px): original table layout unchanged.
   Follows the same pattern as appointments-responsive.css.
   ============================================================ */

/* ─── Base responsive layer (touch & a11y minimums) ─────── */
.pt-container { min-width: 0; overflow-x: clip; }
.pt-container * { min-width: 0; }
.pt-container img, .pt-container svg { max-width: 100%; }
.pt-container button, .pt-container a { touch-action: manipulation; }
.pt-container .page-header { gap: 16px; flex-wrap: wrap; }
.pt-container .header-actions { flex-wrap: wrap; }
.pt-container .header-actions > button,
.pt-container .header-actions > .user-profile { min-height: 44px; }
.pt-container .filters-section { flex-wrap: wrap; }
.pt-container .search-box { min-width: 200px; }
.pt-container .filter-select,
.pt-container .add-btn { min-height: 44px; }
.pt-container .action-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
.pt-container .form-input,
.pt-container select,
.pt-container textarea { min-height: 44px; max-width: 100%; }
.pt-container .btn { min-height: 44px; }
.pt-container .modal-footer { flex-wrap: wrap; }
.pt-container .modal-footer > * { min-width: 120px; }
.pt-container .tabs-row { overflow-x: auto; scrollbar-width: thin; }
.pt-container .tab-btn { min-height: 48px; white-space: nowrap; }
.pt-container :focus-visible { outline: 3px solid rgba(88, 86, 214, 0.35); outline-offset: 3px; }

/* ═══════════════════════════════════════════════════════════
   CARD VIEW — MOBILE & TABLET (≤ 1024px)
   ──────────────────────────────────────────────────────────
   The data table transforms into cards. Each <tr> becomes an
   independent card whose cells render as label → value rows.
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  /* ─── Page-level tablet adjustments ─────────────────── */
  .pt-container { padding: 20px 16px !important; margin: -24px -16px !important; }
  .pt-container > .page-header { align-items: flex-start; }
  .pt-container > div[style*="repeat(4"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .pt-container .filters-section { align-items: stretch; }
  .pt-container .search-box { flex: 1 1 100%; }

  /* ─── Modals on touch screens ───────────────────────── */
  .pt-container .modal-overlay { padding: 12px; align-items: flex-start; }
  .pt-container .modal-content { max-height: calc(100dvh - 24px); }

  /* ─── Table → Card Transformation ─────────────────── */

  /* Hide table header — labels live inside each card */
  .pt-container .pt-table thead {
      display: none !important;
  }

  /* Reset table display */
  .pt-container .pt-table,
  .pt-container .pt-table tbody,
  .pt-container .pt-table tr,
  .pt-container .pt-table td {
      display: block;
      width: 100%;
  }

  /* The horizontal scroll wrapper no longer scrolls */
  .pt-container div[style*="overflow-x: auto"],
  .pt-container div[style*="overflow-x:auto"] {
      overflow-x: visible !important;
  }

  /* Each record becomes a card */
  .pt-container .pt-table tbody tr {
      background: var(--bg-surface, #ffffff);
      border: 1px solid var(--border, #e5e5e7);
      border-radius: 14px;
      margin-bottom: 14px;
      padding: 18px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
      transition: box-shadow 0.2s ease, transform 0.2s ease;
      position: relative;
      overflow: hidden;
  }

  .pt-container .pt-table tbody tr:hover {
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
      transform: translateY(-1px);
  }

  /* ─── Each cell becomes a label → value row ───────── */
  .pt-container .pt-table tbody td {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid var(--border-light, #f0f0f2);
      text-align: right;
      gap: 12px;
      min-height: 40px;
  }

  .pt-container .pt-table tbody td:last-of-type {
      border-bottom: none;
  }

  /* ─── Label from data-label attribute ─────────────── */
  .pt-container .pt-table tbody td::before {
      content: attr(data-label);
      font-size: 12px;
      font-weight: 700;
      color: var(--text-muted, #86868b);
      flex-shrink: 0;
      min-width: 84px;
      line-height: 1.4;
  }

  /* ─── Value side wraps correctly ──────────────────── */
  .pt-container .pt-table tbody td > * {
      flex: 1;
      text-align: right;
  }

  /* ─── Patient identity cell stays a row ───────────── */
  .pt-container .patient-cell {
      flex-direction: row;
      align-items: center;
      gap: 10px;
  }

  .pt-container .patient-avatar {
      width: 36px;
      height: 36px;
      font-size: 14px;
  }

  /* ─── Actions row: horizontal wrap at card bottom ─── */
  .pt-container .pt-table tbody td:last-child {
      flex-direction: column;
      align-items: stretch;
      padding-top: 14px;
      margin-top: 6px;
      border-top: 2px solid var(--border, #e5e5e7);
      border-bottom: none;
      gap: 10px;
  }

  .pt-container .pt-table tbody td:last-child::before {
      display: none;
  }

  .pt-container .pt-table tbody td:last-child > div {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      padding: 0;
  }

  .pt-container .pt-table .action-btn {
      flex: 0 0 auto;
      width: 48px;
      height: 48px;
      border-radius: 12px;
      background: var(--bg-subtle, #f5f5f7);
      border: 1px solid var(--border, #e5e5e7);
      transition: all 0.2s;
  }

  .pt-container .pt-table .action-btn:hover {
      background: var(--accent-soft, #f0f0ff);
      border-color: #5856d6;
  }

  /* ─── Status badge in card ─────────────────────────── */
  .pt-container .status-badge {
      font-size: 11px;
      padding: 4px 10px;
  }
}

/* ═══════════════════════════════════════════════════════════
   TABLET CARD GRID (768px – 1024px)
   ──────────────────────────────────────────────────────────
   Tablets have enough width for two record cards per row.
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) {
    .pt-container .pt-table tbody {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }

    .pt-container .pt-table tbody tr {
        margin-bottom: 0;
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE PAGE ADJUSTMENTS (< 768px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    .pt-container { padding: 16px 12px !important; margin: -16px -12px !important; }
    .pt-container .page-header { flex-direction: column; align-items: stretch; margin-bottom: 20px; }
    .pt-container .header-actions { width: 100%; }
    .pt-container .header-actions > .add-btn { flex: 1; justify-content: center; }
    .pt-container .user-profile { flex: 1; }
    .pt-container > div[style*="repeat(4"] { gap: 12px !important; }
    .pt-container .stat-card { padding: 16px !important; }
    .pt-container .filters-section { padding: 14px !important; }
    .pt-container .search-box,
    .pt-container .filter-select,
    .pt-container .filters-section > .add-btn { width: 100%; }
    .pt-container .modal-footer { flex-direction: column-reverse; }
    .pt-container .modal-footer > * { width: 100%; }
    .pt-container .modal-content { border-radius: 14px; }
    /* اطلاعات شخصی در مودال جزئیات: تک‌ستونه */
    .pt-container .modal-body div[style*="grid-template-columns: 1fr 1fr"],
    .pt-container .modal-body div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
    .pt-container .modal-body div[style*="span 2"] { grid-column: auto !important; }
}

/* ═══════════════════════════════════════════════════════════
   SMALL MOBILE (< 480px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 479px) {
    .pt-container { padding-inline: 8px !important; margin-inline: -8px !important; }
    .pt-container .page-title { font-size: 24px; }
    .pt-container .header-actions { flex-direction: column; }
    .pt-container .header-actions > * { width: 100%; }

    /* ─── Cards on very small screens ─────────────────── */
    .pt-container .pt-table tbody tr {
        padding: 14px;
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .pt-container .pt-table tbody td {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 8px 0;
    }

    .pt-container .pt-table tbody td::before {
        font-size: 11px;
        min-width: auto;
    }

    .pt-container .pt-table tbody td > * {
        width: 100%;
        text-align: right;
    }

    /* Patient cell stays row on small screens */
    .pt-container .patient-cell {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .pt-container .pt-table .action-btn {
        width: 44px;
        height: 44px;
    }
}

/* ═══════════════════════════════════════════════════════════
   DARK MODE OVERRIDES (Mobile & Tablet Cards)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    [data-theme="dark"] .pt-container .pt-table tbody tr {
        background: var(--bg-surface, #1e1e2e);
        border-color: var(--border, #3a3a4a);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    [data-theme="dark"] .pt-container .pt-table tbody td {
        border-bottom-color: var(--border-light, #2a2a3a);
    }

    [data-theme="dark"] .pt-container .pt-table tbody td:last-child {
        border-top-color: var(--border, #3a3a4a);
    }

    [data-theme="dark"] .pt-container .pt-table tbody td::before {
        color: var(--text-muted, #9ca3af);
    }

    [data-theme="dark"] .pt-container .pt-table .action-btn {
        background: var(--bg-subtle, #2a2a3a);
        border-color: var(--border, #3a3a4a);
    }
}

/* ═══════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .pt-container *,
  .pt-container *::before,
  .pt-container *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
