/* ============================================
   Irfan Healthcare Solutions — Consolidated Responsive System
   Mobile-first design system shared across the WHOLE
   platform. Loaded LAST so it layers over both
   style.css / dashboard.css / messages.css / articles.css.
   ============================================ */

/* --- Global overflow & base guards (no horizontal scroll) --- */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}
body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
img, video, canvas, svg, iframe, embed, object {
  max-width: 100%;
  height: auto;
}
table { max-width: 100%; }

/* --- Breakpoint tokens via clamp where helpful --- */
:root {
  --tap: 44px;            /* minimum touch target */
  --tap-sm: 40px;
  --header-h: 64px;
}

/* --- Consistent touch-friendly buttons --- */
.btn {
  min-height: var(--tap);
  padding: 0.7rem 1.25rem;
}
.btn--sm {
  min-height: var(--tap-sm);
  padding: 0.5rem 1rem;
}
.btn--lg {
  min-height: 52px;
  padding: 0.9rem 1.5rem;
  font-size: 1.05rem;
}
.btn--full { width: 100%; }

/* --- Header / logo sizing --- */
.header__inner { min-height: var(--header-h); }
.logo__img { width: 38px; height: 38px; }
.logo__text { font-size: 1.05rem; }

/* ============================================
   MOBILE NAV DRAWER (shared across all pages)
   ============================================ */
.nav__toggle {
  display: inline-flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  width: var(--tap);
  height: var(--tap);
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 120;
}
.nav__toggle span {
  width: 24px;
  height: 2.5px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.nav__toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
.nav__toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav__toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

@media (max-width: 640px) {
  .nav--main {
    flex-direction: column;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 1rem;
    display: none;
    align-items: stretch;
    gap: 0.5rem;
    z-index: 110;
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto;
    margin: 0;
  }
  .nav--main.is-open { display: flex; }
  .nav--main .nav__link,
  .nav--main .btn {
    width: 100%;
    justify-content: center;
    text-align: center;
    min-height: var(--tap);
  }
  .nav--main .nav__user { display: block; text-align: center; padding: 0.35rem 0; }
  .notif-bell { align-self: center; }
  .notif-panel {
    position: fixed;
    top: calc(var(--header-h) + 8px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(92vw, 360px);
  }
}

/* ============================================
   TYPOGRAPHY — clamp() scaling
   ============================================ */
h1, .hero__title, .article-detail__title { overflow-wrap: break-word; }
.hero__title { font-size: clamp(1.9rem, 6vw, 3.6rem) !important; letter-spacing: -0.02em !important; }
.hero__subtitle { font-size: clamp(0.95rem, 2.6vw, 1.15rem) !important; }
.section-title { font-size: clamp(1.4rem, 4vw, 2rem); }
.pd-name, .md-name, .ah-welcome__name { font-size: clamp(1.15rem, 4vw, 1.5rem); }
.form-card__title, .auth-card__title { font-size: clamp(1.3rem, 4vw, 1.6rem); }
.dashboard__title { font-size: clamp(1.25rem, 4vw, 1.5rem); }

/* ============================================
   CONTAINER / FORMS — single column on mobile
   ============================================ */
.container { padding-left: 1rem; padding-right: 1rem; }

/* Forms: full-width, stacked, generous spacing */
.form { gap: 1rem; }
.form__row { flex-direction: column; gap: 1rem; }
.form__input, .form__textarea, select.form__input,
.filter-bar__input, .filter-bar__select {
  min-height: var(--tap);
  font-size: 1rem;
}
.form__label { font-size: 0.9rem; }

/* Filter bar stacks vertically on phones */
.filter-bar, .articles-toolbar {
  flex-direction: column;
  align-items: stretch;
}
.filter-bar__group, .filter-bar__group--wide { min-width: 0 !important; flex: 1 1 auto; }
.filter-bar__actions { flex-direction: column; width: 100%; min-width: 0 !important; }
.filter-bar__actions .btn { width: 100%; }

/* ============================================
   CARD GRIDS — responsive multi-column
   ============================================ */
.medic-grid, .article-grid, .services__grid,
.home-articles__grid, .testimonials__grid, .benefits, .steps {
  grid-template-columns: 1fr;
}
@media (min-width: 480px) {
  .medic-grid { grid-template-columns: repeat(2, 1fr); }
  .services__grid, .home-articles__grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .medic-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================
   TABLES → CARDS on mobile (shared pattern)
   ============================================ */
@media (max-width: 640px) {
  .admin-table-wrap,
  .pd-table-wrap,
  .md-table-wrap { overflow-x: visible; }

  /* Generic admin-table card conversion */
  .admin-table thead { display: none; }
  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td { display: block; width: 100%; }
  .admin-table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: #fff;
  }
  .admin-table td {
    border: none;
    padding: 0.4rem 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
  }
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-light);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    min-width: 90px;
  }
  .admin-table .actions-cell { flex-direction: column; align-items: stretch; }
  .admin-table .actions-cell form { width: 100%; }
  .admin-table .actions-cell .btn { width: 100%; }
  .admin-table .bio-cell { white-space: normal; }
  .admin-table td[data-label=""]::before { content: none; }
}

/* ============================================
   MODALS — fit phone screens
   ============================================ */
.cc-modal { padding: 0.75rem; }
.cc-modal__dialog {
  max-width: 640px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}
.cc-modal__footer { flex-wrap: wrap; }
.cc-modal__footer .btn { flex: 1; min-width: 120px; }
.editor-media-modal__box { max-width: 92vw; }

/* ============================================
   ADMIN — stack filters, keep KPI cards responsive
   ============================================ */
@media (max-width: 640px) {
  .admin-tabs { flex-direction: column; align-items: stretch; }
  .admin-tab { text-align: center; }
  .ah-cards { grid-template-columns: repeat(2, 1fr); }
  .ah-welcome { flex-direction: column; align-items: flex-start; }
  .ah-welcome__right { width: 100%; }
  .community-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   BOOKING / PAYMENT / CONFIRMATION
   ============================================ */
.form-card { padding: 1.25rem; }

/* ============================================
   PAYMENT PAGE (KES 100 service fee / M-Pesa)
   ============================================ */
.pay-page { background: var(--bg); }
.pay-card { max-width: 560px; }
.pay-header { text-align: center; margin-bottom: 1.25rem; }
.pay-header__icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 0.75rem;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 8px 24px rgba(26,122,122,0.3);
}
.pay-header .form-card__title { margin-bottom: 0.35rem; }
.pay-header .form-card__subtitle { margin-bottom: 0; }

.pay-summary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.pay-summary__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: var(--primary-dark);
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.15rem;
}
.pay-summary__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-light);
}
.pay-summary__row strong { color: var(--text); }

.pay-fee {
  text-align: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  margin-bottom: 1.25rem;
}
.pay-fee__label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.95;
  margin-bottom: 0.25rem;
}
.pay-fee__amount { font-size: clamp(1.8rem, 8vw, 2.4rem); font-weight: 800; line-height: 1.1; }
.pay-fee__note { font-size: 0.8rem; opacity: 0.9; margin-top: 0.35rem; }

.pay-btn { min-height: 56px; font-size: 1.1rem; }

.pay-payment-note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: #fff8e1;
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.5;
  margin-top: 0.75rem;
}

.pay-status {
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0.75rem;
  text-align: center;
}
.pay-status--info { background: #e3f2fd; color: #1565c0; }
.pay-status--success { background: #e8f5e9; color: #2e7d32; }
.pay-status--error { background: #fbe9e7; color: #c62828; }

.sim-box { margin-top: 1rem; }
.pay-sim-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.pay-sim-actions .btn { width: 100%; }

/* Booking detail actions stack */
.profile-card__actions > div,
.profile-card__actions form { display: flex; flex-direction: column; gap: 0.6rem; }
.profile-card__actions .btn { width: 100%; }

/* ============================================
   MESSAGING (layers over messages.css)
   ============================================ */
.msg-bubble__row { max-width: 82%; min-width: 0; }
.msg-bubble__bubble { word-wrap: break-word; overflow-wrap: break-word; }
.msg-bubble__text { white-space: pre-wrap; word-break: break-word; }
.msg-attach { max-width: 100%; }
.msg-attach img { width: 100%; height: auto; }
.msg-composer { position: sticky; bottom: 0; z-index: 20; }
.msg-conv__body { min-width: 0; }

@media (max-width: 820px) {
  .messenger { position: relative; height: calc(100vh - var(--header-h)); }
  .msg-sidebar { width: 100%; max-width: 100%; }
  .msg-chat { width: 100%; min-width: 0; }
  .msg-chat__header { padding: 0.5rem 0.6rem; gap: 0.4rem; }
  .msg-chat__header .msg-chat__back { display: inline-flex; }
  .msg-composer { padding: 0.5rem; gap: 0.3rem; }
  .msg-composer textarea { font-size: 1rem; }
}

/* ============================================
   ARTICLES / COMMUNITY — comfortable reading
   ============================================ */
.article-detail-container { padding-left: 1rem; padding-right: 1rem; }
.article-body { font-size: 1.02rem; line-height: 1.8; }
.article-body img { border-radius: 10px; }
.comment { flex-wrap: nowrap; }
.comment__body { min-width: 0; }
.comment__actions { gap: 0.25rem; }
.comment__action { min-height: 36px; }
.reactions-bar { padding: 0.85rem; }
.reactions-bar__buttons { flex-wrap: wrap; }

/* ============================================
   ACCESSIBILITY — focus & touch
   ============================================ */
a, button, input, select, textarea, [tabindex] { touch-action: manipulation; }
.btn, .nav__link, .admin-tab, .reaction-btn, .comment__action,
.msg-icon-btn, .msg-composer__send, .msg-composer__emoji-btn,
.msg-composer__attach-btn, .pd-quick-card, .md-quick-card {
  min-height: var(--tap-sm);
}
.btn, .nav__toggle, .nav__link, .admin-tab, .reaction-btn,
.cc-modal__close, .msg-icon-btn, .msg-composer__send {
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================
   SMALL PHONES (320–414px) refinements
   ============================================ */
@media (max-width: 414px) {
  .btn { padding: 0.7rem 1rem; }
  .form-card { padding: 1.1rem; }
  .pd-welcome, .md-welcome { padding: 1.25rem; }
  .pd-completion__ring, .md-completion__ring { width: 62px; height: 62px; }
  .hero { padding-left: 1rem; padding-right: 1rem; }
  .hero__cta { font-size: 0.95rem; }
  .services__grid, .home-articles__grid { grid-template-columns: 1fr; }
  .pd-quick, .md-quick { grid-template-columns: repeat(2, 1fr); }
  .ah-cards { grid-template-columns: 1fr; }
  .profile-card__details { padding: 1rem; }
  .profile-card__row { flex-direction: column; gap: 0.2rem; }
  .profile-card__label { min-width: 0; }
  .msg-quick-chips, .msg-quick-replies { flex-wrap: wrap; }
}

/* ============================================
   TABLET (768px) — optimize mid-size
   ============================================ */
@media (min-width: 641px) and (max-width: 1024px) {
  .pd-cards, .md-cards { grid-template-columns: repeat(3, 1fr); }
  .ah-cards { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================
   DESKTOP (1024px+) — restore horizontal layouts
   ============================================ */
@media (min-width: 641px) {
  .nav__toggle { display: none; }
  .nav--main { flex-direction: row; }
  .form__row { flex-direction: row; }
  .filter-bar, .community-toolbar, .articles-toolbar { flex-direction: row; }
  .filter-bar__actions { flex-direction: row; }
  .filter-bar__actions .btn { width: auto; }
}
