/* ================================================================
   SHIFAJO Compatibility Layer
   Maps ah-* CSS variables and classes to rg-* design system
   ================================================================ */

/* ── ah-* CSS Variable Aliases ── */
:root {
  --ah-primary: var(--rg-primary);
  --ah-primary-hover: var(--rg-primary-hover);
  --ah-primary-light: var(--rg-primary-light);
  --ah-primary-subtle: var(--rg-primary-subtle);
  --ah-secondary: var(--rg-secondary);
  --ah-secondary-hover: var(--rg-secondary-hover);
  --ah-secondary-light: var(--rg-secondary-light);
  --ah-danger: var(--rg-danger);
  --ah-danger-light: var(--rg-danger-light);
  --ah-warning: var(--rg-warning);
  --ah-warning-light: var(--rg-warning-light);
  --ah-success: var(--rg-success);
  --ah-success-light: var(--rg-success-light);
  --ah-info: var(--rg-info);
  --ah-info-light: var(--rg-info-light);
  --ah-dark: var(--rg-dark);
  --ah-gray-900: var(--rg-gray-900);
  --ah-gray-800: var(--rg-gray-800);
  --ah-gray-700: var(--rg-gray-700);
  --ah-gray-600: var(--rg-gray-600);
  --ah-gray-500: var(--rg-gray-500);
  --ah-gray-400: var(--rg-gray-400);
  --ah-gray-300: var(--rg-gray-300);
  --ah-gray-200: var(--rg-gray-200);
  --ah-gray-100: var(--rg-gray-100);
  --ah-gray-50: var(--rg-gray-50);
  --ah-white: var(--rg-white);
  --ah-surface: var(--rg-surface);
  --ah-card: var(--rg-card);
  --ah-border: var(--rg-border);
  --ah-text: var(--rg-text);
  --ah-text-secondary: var(--rg-text-secondary);
  --ah-muted: var(--rg-text-muted);
  --ah-font: var(--rg-font);
  --ah-font-dari: var(--rg-font-dari);
  --ah-font-mono: var(--rg-font-mono);
  --ah-radius-xs: var(--rg-radius-xs);
  --ah-radius-sm: var(--rg-radius-sm);
  --ah-radius: var(--rg-radius-xl);
  --ah-radius-lg: var(--rg-radius-2xl);
  --ah-radius-xl: var(--rg-radius-2xl);
  --ah-radius-full: var(--rg-radius-full);
  --ah-shadow-xs: var(--rg-shadow-xs);
  --ah-shadow-sm: var(--rg-shadow-sm);
  --ah-shadow: var(--rg-shadow);
  --ah-shadow-md: var(--rg-shadow-md);
  --ah-shadow-lg: var(--rg-shadow-lg);
  --ah-shadow-xl: var(--rg-shadow-xl);
  --ah-primary-dark: var(--rg-primary-hover);
  --ah-light: var(--rg-gray-100);
  --ah-text-muted: var(--rg-text-muted);
  --ah-transition: var(--rg-transition);
  --ah-transition-slow: var(--rg-transition-slow);
  --ah-sidebar-w: var(--rg-sidebar-w);
  --ah-sidebar-collapsed-w: var(--rg-sidebar-collapsed-w);
  --ah-header-h: var(--rg-header-h);
  --ah-mobile-nav-h: var(--rg-mobile-nav-h);
}

/* Layout — JS queries .ah-sidebar for toggle */
.ah-content { padding: 20px; flex: 1; }
.ah-content-wide { max-width: 1120px; margin: 0 auto; width: 100%; }
.brand-logo { width: 100%; height: 100%; object-fit: cover; }
.brand-name { font-size: 14px; font-weight: 700; color: var(--rg-gray-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sidebar collapsed (JS toggles ah-sidebar-collapsed on body) */
body.ah-sidebar-collapsed .rg-sidebar { width: var(--rg-sidebar-collapsed-w); }
body.ah-sidebar-collapsed .rg-sidebar .brand-name,
body.ah-sidebar-collapsed .rg-sidebar .rg-nav-section,
body.ah-sidebar-collapsed .rg-sidebar .rg-nav-item span,
body.ah-sidebar-collapsed .rg-sidebar .user-name,
body.ah-sidebar-collapsed .rg-sidebar .user-role { display: none; }
body.ah-sidebar-collapsed .rg-main { margin-inline-start: var(--rg-sidebar-collapsed-w); }
body.ah-sidebar-collapsed .rg-sidebar .rg-nav-item { justify-content: center; padding: 8px; }
body.ah-sidebar-collapsed .rg-sidebar .rg-nav-item i { font-size: 18px; width: auto; }

/* Cards */
.ah-card {
  background: var(--rg-card);
  border-radius: var(--rg-radius-2xl);
  border: 1px solid var(--rg-border);
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
  padding: 16px;
  margin-block-end: 12px;
  transition: box-shadow .15s ease;
}

.ah-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,.05); }

.ah-card-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-block-end: 12px;
  padding-block-end: 10px;
  border-block-end: 1px solid var(--rg-gray-100);
  gap: 10px;
}

.ah-card-title { font-size: 14px; font-weight: 700; color: var(--rg-gray-900); }
.ah-card-subtitle { font-size: 11.5px; color: var(--rg-text-secondary); margin-block-start: 2px; }

/* Stat cards */
.stat-card, .ah-stat-card {
  background: var(--rg-card);
  border-radius: var(--rg-radius-2xl);
  border: 1px solid var(--rg-border);
  border-inline-start: 3px solid var(--rg-gray-300);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
  transition: box-shadow .15s ease;
}

.stat-card:hover, .ah-stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.05); }

.stat-card.primary, .ah-stat-card.primary { border-inline-start-color: var(--rg-primary); }
.stat-card.success, .ah-stat-card.success { border-inline-start-color: var(--rg-success); }
.stat-card.warning, .ah-stat-card.warning { border-inline-start-color: var(--rg-warning); }
.stat-card.danger, .ah-stat-card.danger { border-inline-start-color: var(--rg-danger); }
.stat-card.info, .ah-stat-card.info { border-inline-start-color: var(--rg-info); }

.stat-card::before { display: none; }

.stat-card .stat-icon, .ah-stat-card .stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--rg-radius);
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}

.stat-card .stat-icon.primary { background: var(--rg-primary-light); color: var(--rg-primary); }
.stat-card .stat-icon.success { background: var(--rg-success-light); color: var(--rg-success); }
.stat-card .stat-icon.warning { background: var(--rg-warning-light); color: var(--rg-secondary-hover); }
.stat-card .stat-icon.danger { background: var(--rg-danger-light); color: var(--rg-danger); }
.stat-card .stat-icon.info { background: var(--rg-info-light); color: var(--rg-info); }

.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--rg-gray-900); line-height: 1; }
.stat-card .stat-label { font-size: 11.5px; color: var(--rg-text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-block-end: 16px;
}

/* Grids */
.ah-grid { display: grid; gap: 12px; }
.ah-grid.cards-2 { grid-template-columns: repeat(2, 1fr); }
.ah-grid.cards-3 { grid-template-columns: repeat(3, 1fr); }
.ah-grid.cards-4 { grid-template-columns: repeat(4, 1fr); }
.ah-grid.cards-6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 768px) {
  .ah-grid.cards-2, .ah-grid.cards-3 { grid-template-columns: 1fr; }
  .ah-grid.cards-4, .ah-grid.cards-6 { grid-template-columns: 1fr 1fr; }

  .ah-table-mobile-cards table tbody td.actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .ah-table-mobile-cards table tbody td.actions::before {
    display: none;
  }

  .ah-table-mobile-cards table tbody td.actions .btn {
    width: 100%;
    justify-content: center;
  }

  .ah-desktop-only-action {
    display: none !important;
  }

  .ah-table-mobile-cards table tbody tr.ah-mobile-row-link {
    cursor: pointer;
    position: relative;
  }
}

/* Meta list */
.ah-meta-list { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.ah-meta-list dt, .ah-meta-list .label { font-weight: 600; color: var(--rg-gray-500); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.ah-meta-list dd, .ah-meta-list .value { color: var(--rg-text); }

/* Info note */
.ah-info-note {
  background: var(--rg-gray-50);
  border: 1px solid var(--rg-gray-200);
  border-radius: var(--rg-radius);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--rg-text-secondary);
}

/* Print styles */
.ah-print-body { background: #fff; padding: 0; margin: 0; }
.ah-print-force-desktop { min-width: auto; }
.ah-print-report { max-width: 800px; margin: 0 auto; padding: 20px; }
.ah-print-top-actions { display: flex; gap: 8px; margin-block-end: 16px; }
.ah-print-header { text-align: center; margin-block-end: 20px; border-block-end: 1px solid var(--rg-border); padding-block-end: 12px; }
.ah-print-org-name { font-size: 18px; font-weight: 700; }
.ah-print-title { font-size: 14px; color: var(--rg-text-secondary); margin-block-start: 4px; }
.ah-print-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-block-end: 16px; font-size: 13px; }
.ah-print-section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--rg-gray-500); margin-block-end: 8px; }
.ah-print-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ah-print-table th { background: var(--rg-gray-50); padding: 6px 10px; text-align: start; font-size: 11px; font-weight: 600; color: var(--rg-gray-500); text-transform: uppercase; letter-spacing: .04em; border: 1px solid var(--rg-border); }
.ah-print-table td { padding: 6px 10px; border: 1px solid var(--rg-gray-200); }
.ah-print-signature { margin-block-start: 32px; text-align: end; }
.ah-print-signature-line { border-top: 1px solid var(--rg-gray-400); display: inline-block; padding-top: 4px; font-size: 12px; color: var(--rg-text-secondary); min-width: 200px; }

@media print {
  .ah-print-top-actions { display: none !important; }
}

/* Rx code */
.ah-rx-code { font-family: var(--rg-font-mono); font-size: 13px; background: var(--rg-gray-100); padding: 2px 8px; border-radius: var(--rg-radius-xs); display: inline-block; }

/* Icon box */
.ah-icon-box { display: flex; align-items: center; gap: 8px; }

/* Alert inline actions */
.ah-alert-inline-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ah-alert-inline-copy { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }

/* Patient layout compat */
.patient-app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; max-width: 960px; margin: 0 auto; width: 100%; }
.patient-app-content { flex: 1; padding: 16px; }

.patient-webview-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  margin: 12px 16px 0;
  background: var(--rg-white);
  border: 1px solid var(--rg-border);
  border-radius: var(--rg-radius-lg);
  position: sticky;
  top: 6px;
  z-index: 100;
}

.patient-webview-nav-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--rg-radius);
  color: var(--rg-gray-500);
  font-weight: 500;
  font-size: 12.5px;
  transition: all var(--rg-transition);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

.patient-webview-nav-item:hover { color: var(--rg-gray-900); background: var(--rg-gray-100); }
.patient-webview-nav-item.active { color: var(--rg-primary); background: var(--rg-primary-light); }

.patient-webview-nav-trigger { position: relative; }
.patient-webview-profile-menu { min-width: 160px; }

.patient-mobile-nav { z-index: 1100; }

@media (max-width: 768px) {
  .patient-webview-nav { display: none; }
}

/* Sidebar user chip (old layout compat) */
.ah-user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--rg-radius);
  cursor: pointer;
}

.ah-user-chip:hover { background: var(--rg-gray-100); }
.ah-user-chip .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--rg-primary-light); color: var(--rg-primary); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; overflow: hidden; }
.ah-user-chip .avatar img { width: 100%; height: 100%; object-fit: cover; }
.ah-user-chip .info strong { display: block; font-size: 12.5px; font-weight: 600; color: var(--rg-gray-900); }
.ah-user-chip .info small { display: block; font-size: 11px; color: var(--rg-text-muted); }

/* Avatar media compat */
.ah-avatar-media { width: 30px; height: 30px; border-radius: 50%; background: var(--rg-primary-light); color: var(--rg-primary); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; overflow: hidden; }
.ah-avatar-photo { width: 100%; height: 100%; object-fit: cover; }

/* Header actions compat */
.ah-header-actions { display: flex; align-items: center; gap: 4px; }

/* Misc legacy */
.ah-card-body { padding: 0; }
.ah-content-wide-full { max-width: 100%; width: 100%; }
.ah-flex-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.ah-value-lg { font-size: 22px; font-weight: 700; color: var(--rg-gray-900); }
.ah-text-xxs { font-size: 10px; }
.ah-grid-col-full { grid-column: 1 / -1; }
.ah-grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.page-title { margin: 0; }

/* Flash toast animation */
.ah-flash-toast {
  animation: flashSlideIn .3s ease;
}

@keyframes flashSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Lab usage progress compat */
.lab-usage-progress { height: 6px; background: var(--rg-gray-200); border-radius: var(--rg-radius-full); overflow: hidden; }
.lab-usage-progress .bar { height: 100%; border-radius: var(--rg-radius-full); transition: width .3s ease; }
.lab-usage-progress .bar.success { background: var(--rg-success); }
.lab-usage-progress .bar.warning { background: var(--rg-warning); }
.lab-usage-progress .bar.danger { background: var(--rg-danger); }

/* Notif dot compat */
.notif-dot { position: absolute; top: 5px; inset-inline-end: 5px; width: 7px; height: 7px; background: var(--rg-danger); border-radius: 50%; border: 1.5px solid var(--rg-white); }

/* Quick action grids for dashboards */
.quick-action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid var(--rg-border);
  border-radius: var(--rg-radius-lg);
  background: var(--rg-white);
  color: var(--rg-gray-700);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--rg-transition);
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}
.quick-action-btn:hover { border-color: var(--rg-primary); color: var(--rg-primary); background: var(--rg-primary-light); }
.quick-action-btn i { font-size: 20px; }

/* Toast container */
.ah-toast-container { position: fixed; top: 12px; inset-inline-end: 12px; z-index: 10000; display: flex; flex-direction: column; gap: 6px; max-width: 360px; }
.ah-toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--rg-radius-lg); font-size: 13px; line-height: 1.5; border: 1px solid transparent; animation: flashSlideIn .3s ease; }
.ah-toast.success { background: var(--rg-success-light); color: #065F46; border-color: #A7F3D0; }
.ah-toast.error { background: var(--rg-danger-light); color: #991B1B; border-color: #FECACA; }
.ah-toast.warning { background: var(--rg-warning-light); color: #92400E; border-color: #FDE68A; }
.ah-toast.info { background: var(--rg-info-light); color: #1E40AF; border-color: #BFDBFE; }

/* Jalali date input */
.ah-jalali-date-input { cursor: pointer; }
.ah-jalali-hidden-date { position: absolute; opacity: 0; pointer-events: none; }

/* Usage widget */
.ah-usage-widget .ah-progress-bar { height: 100%; border-radius: var(--rg-radius-full); transition: width .3s ease; }

/* Badge inactive */
.ah-badge-inactive { background: var(--rg-gray-100); color: var(--rg-gray-500); }

/* Loading spinner */
.loading-spinner { display: inline-block; width: 20px; height: 20px; border: 2.5px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Legal pages */
.site-legal-page .site-legal-wrap { padding-top: 96px; padding-bottom: 44px; }
.site-legal-page .site-legal-card { width: min(920px, 100%); margin: 0 auto; padding: clamp(20px, 4vw, 40px); border-radius: 22px; background: #fff; border: 1px solid rgba(18,42,76,.08); box-shadow: 0 16px 40px rgba(12,34,62,.12); }
.site-legal-page .site-legal-title { margin: 8px 0 10px; }
.site-legal-page .site-legal-block { margin-top: 16px; padding: 14px 16px; border-radius: 14px; border: 1px solid #e3ebf5; background: #fbfdff; }
.site-legal-page .site-legal-block h3 { margin: 0 0 6px; font-size: 16px; }
.site-legal-page .site-legal-block p { margin: 0; color: #33465f; line-height: 1.6; }
.site-legal-page .site-legal-actions { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 10px; }
@media (max-width: 900px) { .site-legal-page .site-legal-wrap { padding-top: 84px; } }

/* Registration type selector */
.type-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.type-btn { border: 2px solid var(--rg-border, #cbd5e1); border-radius: 4px; padding: 16px 12px; text-align: center; cursor: pointer; transition: all .2s; background: #fff; }
.type-btn:hover, .type-btn.selected { border-color: var(--rg-primary, #0066ff); background: var(--rg-primary-light, rgba(0,102,255,0.08)); }
.type-btn i { font-size: 28px; display: block; margin-bottom: 8px; }
.type-btn strong { font-size: 14px; display: block; }
.type-btn small { color: var(--rg-text-secondary, #52525B); font-size: 12px; }
.reg-actions { display: flex; }
@media (max-width: 420px) {
  .type-grid { grid-template-columns: 1fr; }
}
@media (max-width: 580px) {
  .reg-actions { flex-direction: column; }
  .reg-actions .btn { width: 100%; }
}

/* Utility classes used in auth pages */
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-3 { margin-bottom: 12px; }
.mt-3 { margin-top: 12px; }
.flex-grow-1 { flex-grow: 1; }
.rg-auth-field-heading { font-size: 1.1rem; font-weight: 700; color: var(--rg-gray-900, #18181B); margin-bottom: 4px; }

/* Workspace hero card — gradient override for rg-card */
.rg-card.site-workspace-hero-card { background: linear-gradient(135deg, var(--rg-primary-hover), var(--rg-primary)); color: #fff; border: none; }
.site-workspace-hero-title { color: #fff; }

/* Table scroll */
.ah-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
