/* ══════════════════════════════════════════════════════════════
   TrainerHub — Modern Professional UI
   ══════════════════════════════════════════════════════════════ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --primary-50: #EEF2FF;
  --primary-100: #E0E7FF;
  --secondary: #0EA5E9;
  --secondary-light: #7DD3FC;
  --accent: #F59E0B;
  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --info: #3B82F6;
  --info-light: #DBEAFE;

  --bg-body: #F1F5F9;
  --bg-sidebar: #1E293B;
  --bg-sidebar-hover: #334155;
  --bg-sidebar-active: #4F46E5;
  --bg-card: #FFFFFF;
  --bg-header: #FFFFFF;

  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --text-sidebar: #CBD5E1;
  --text-sidebar-active: #FFFFFF;
  --text-white: #FFFFFF;

  --border-color: #E2E8F0;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);

  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --header-height: 68px;

  --transition: all 0.2s ease;
}

/* All elements respect container width */
*, *::before, *::after { box-sizing: border-box; }
img, video, canvas, svg { max-width: 100%; }
table { table-layout: fixed; }
.data-table { table-layout: auto; }
.card, .card-body, .card-body-flush { max-width: 100%; overflow-x: hidden; }

/* ── Reset & Base ─────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  direction: rtl;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

input, select, textarea, button {
  font-family: inherit;
  direction: rtl;
}

a { text-decoration: none; color: inherit; }

/* ── Layout Shell ─────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
}

.app-main {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  transition: var(--transition);
}

.app-content {
  flex: 1;
  padding: 24px 28px;
  max-width: 1400px;
  width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Spacing utility */
.space-y-4 > * + * { margin-top: 16px; }

/* Grid utilities */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
.dash-charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-bottom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  overflow-x: hidden;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-icon svg { width: 24px; height: 24px; color: white; }

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
}

.sidebar-logo-text h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-white);
  line-height: 1.2;
}

.sidebar-logo-text span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 14px 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--border-radius-sm);
  color: var(--text-sidebar);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}

.sidebar-link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-white);
}

.sidebar-link.active {
  background: var(--bg-sidebar-active);
  color: var(--text-white);
  font-weight: 600;
}

.sidebar-link svg, .sidebar-link i {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-link.active svg, .sidebar-link.active i {
  opacity: 1;
}

.sidebar-badge {
  margin-right: auto;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--border-radius-sm);
  transition: var(--transition);
}

.sidebar-user:hover { background: var(--bg-sidebar-hover); }

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  padding: 0 28px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-search {
  position: relative;
}

.header-search input {
  width: 280px;
  padding: 9px 38px 9px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 13px;
  background: var(--bg-body);
  color: var(--text-primary);
  transition: var(--transition);
}

.header-search input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-50);
  background: white;
}

.header-search input::placeholder { color: var(--text-muted); }

.header-search svg {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body { padding: 22px; }

.card-body-flush { padding: 0; }

/* ── Stat Cards ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 24px; height: 24px; }

.stat-icon.blue { background: var(--info-light); color: var(--info); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.amber { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.purple { background: #F3E8FF; color: #8B5CF6; }
.stat-icon.indigo { background: var(--primary-50); color: var(--primary); }

.stat-info { flex: 1; }

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.stat-change {
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* On mobile — tables that have mobile card alternatives: hide the table, show cards */
@media (max-width: 768px) {
  .cert-table-desktop .table-wrapper,
  .users-table-desktop .table-wrapper,
  .tmpl-table-desktop .table-wrapper { overflow-x: hidden; }
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

/* Trainers table column widths — trainers list only */
.trainers-table .data-table th:nth-child(1),
.trainers-table .data-table td:nth-child(1) { width: 40%; }
.trainers-table .data-table th:nth-child(2),
.trainers-table .data-table td:nth-child(2) { width: 15%; }
.trainers-table .data-table th:nth-child(3),
.trainers-table .data-table td:nth-child(3) { width: 12%; }
.trainers-table .data-table th:nth-child(4),
.trainers-table .data-table td:nth-child(4) { width: 13%; }
.trainers-table .data-table th:nth-child(5),
.trainers-table .data-table td:nth-child(5) { width: 12%; }
.trainers-table .data-table th:nth-child(6),
.trainers-table .data-table td:nth-child(6) { width: 8%; }

@media (max-width: 768px) {
  .col-hide-mobile,
  .trainers-table .data-table th:nth-child(2),
  .trainers-table .data-table td:nth-child(2),
  .trainers-table .data-table th:nth-child(3),
  .trainers-table .data-table td:nth-child(3),
  .trainers-table .data-table th:nth-child(4),
  .trainers-table .data-table td:nth-child(4),
  .trainers-table .data-table th:nth-child(5),
  .trainers-table .data-table td:nth-child(5) { display: none; }
  .trainers-table .data-table th:nth-child(1),
  .trainers-table .data-table td:nth-child(1) { width: 85%; }
  .trainers-table .data-table th:nth-child(6),
  .trainers-table .data-table td:nth-child(6) { width: 15%; }
  .data-table .btn-xs { padding: 6px 10px; min-width: 44px; justify-content: center; }
}

.data-table td { overflow: hidden; text-overflow: ellipsis; }

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table thead th {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: right;
  background: var(--bg-body);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: var(--primary-50);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--success-light); color: #065F46; }
.badge-danger { background: var(--danger-light); color: #991B1B; }
.badge-warning { background: var(--warning-light); color: #92400E; }
.badge-info { background: var(--info-light); color: #1E40AF; }
.badge-purple { background: #F3E8FF; color: #6B21A8; }
.badge-gray { background: #F1F5F9; color: #475569; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-secondary {
  background: var(--bg-body);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--border-color); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #059669; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #DC2626; }

.btn-warning {
  background: var(--warning);
  color: white;
}
.btn-warning:hover { background: #D97706; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
}
.btn-ghost:hover { background: var(--bg-body); color: var(--text-primary); }

/* Close button for modals — no border, no box */
.modal-close-btn {
  background: none;
  border: none;
  outline: none;
  box-shadow: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
}
.modal-close-btn:hover { color: var(--text-primary); background: var(--bg-body); }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--border-radius-sm);
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  background: white;
  transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-50);
}

.form-input::placeholder { color: var(--text-muted); }

.form-textarea { resize: vertical; min-height: 80px; }

.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-body);
  padding: 4px;
  border-radius: var(--border-radius-sm);
  margin-bottom: 20px;
  width: fit-content;
}

.tab {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab:hover { color: var(--text-primary); }

.tab.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.tab-count {
  background: var(--bg-body);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
}

.tab.active .tab-count {
  background: var(--primary-50);
  color: var(--primary);
}

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 0;
}

.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: var(--border-radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
}

.pagination a:hover { background: var(--bg-body); color: var(--primary); }
.pagination .active { background: var(--primary); color: white; font-weight: 700; }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* ── Flash Messages ───────────────────────────────────────── */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  animation: slideDown 0.3s ease;
}

.flash-success {
  background: var(--success-light);
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.flash-error {
  background: var(--danger-light);
  color: #991B1B;
  border: 1px solid #FECACA;
}

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

/* ── Star Rating ──────────────────────────────────────────── */
.star-rating {
  direction: rtl;
  display: flex;
  justify-content: flex-start;
  gap: 4px;
  padding: 8px 4px;
}

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 28px;
  padding: 4px;
  transition: all 0.25s ease;
  color: #E2E8F0;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.05));
}

.star-btn.filled { color: #FBBF24; filter: drop-shadow(0 1px 2px rgba(251,191,36,0.4)); }
.star-btn:hover { color: #F59E0B; transform: scale(1.2); filter: drop-shadow(0 2px 4px rgba(245,158,11,0.4)); }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  font-weight: 500;
}

/* ── Alert Box ────────────────────────────────────────────── */
.alert-box,
.alert-warning,
.alert-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--border-radius);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.7;
}

.alert-warning {
  background: linear-gradient(135deg, #FFFBEB, #FEF3C7);
  color: #92400E;
  border: 1px solid #FDE68A;
}

.alert-info {
  background: linear-gradient(135deg, #EFF6FF, #DBEAFE);
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

.alert-warning svg,
.alert-info svg {
  flex-shrink: 0;
  margin-top: 2px;
}

.alert-warning code,
.alert-info code {
  display: inline-block;
  background: rgba(0,0,0,0.06);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  margin: 2px 3px;
  direction: ltr;
}

/* ── Chart Container ──────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 280px;
  padding: 16px;
}

/* ── Notes ─────────────────────────────────────────────────── */
.note-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.note-item:last-child { border-bottom: none; }

.note-body {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.note-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Profile Header ───────────────────────────────────────── */
.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.profile-info { display: flex; align-items: center; gap: 16px; }

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  font-weight: 700;
}

.profile-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.profile-id {
  font-size: 13px;
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 2px;
}

/* ── Info Grid (legacy, kept for compatibility) ─────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.info-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.info-item:last-child { border-bottom: none; }
.info-item:nth-last-child(-n+2) { border-bottom: 1px solid var(--border-color); }

.info-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.info-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
}

/* ── Info List (full-width, label right / value left) ────────── */
.info-list {}
.info-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}
.info-list-item:last-child { border-bottom: none; }
.info-list-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}
.info-list-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
}

/* ── Profile Card (gradient header) ─────────────────────────── */
.profile-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--border-radius);
  padding: 24px;
  margin-bottom: 20px;
  color: white;
  box-shadow: var(--shadow-md);
}
.profile-card-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.profile-card-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}
.profile-card-avatar {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.3);
}
.profile-card-name {
  font-size: 22px;
  font-weight: 700;
  color: white;
  line-height: 1.2;
}
.profile-card-id {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  font-family: monospace;
  margin-top: 4px;
}
.profile-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.profile-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.btn-white {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  backdrop-filter: blur(4px);
}
.btn-white:hover {
  background: rgba(255,255,255,0.25);
  color: white;
  transform: translateY(-1px);
}
.btn-white-danger {
  background: rgba(239,68,68,0.2);
  color: #FEE2E2;
  border: 1px solid rgba(239,68,68,0.4);
}
.btn-white-danger:hover {
  background: rgba(239,68,68,0.35);
  color: white;
}

/* ── Login Page ────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.login-logo-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.login-logo h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
}

.login-logo p {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Approval Cards ───────────────────────────────────────── */
.approval-card {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 18px;
  margin-bottom: 12px;
  background: white;
  transition: var(--transition);
}

.approval-card:hover { box-shadow: var(--shadow-md); }

.approval-card.faded { opacity: 0.55; }

.approval-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.approval-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(110%);
    box-shadow: none;
    z-index: 200;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: -8px 0 32px rgba(0,0,0,0.2);
  }
  .app-main { margin-right: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-4 { grid-template-columns: 1fr 1fr; }
  .sidebar-toggle-btn { display: flex !important; }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 768px) {
  .app-header { padding: 0 16px; }
  .app-content { padding: 16px; }

  /* Grids collapse to 1 column */
  .grid-2,
  .dash-charts-grid,
  .dash-bottom-grid { grid-template-columns: 1fr; }

  /* Detail grid: flex column with order support */
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid > * { grid-column: 1 !important; grid-row: auto !important; }
  .star-rating { justify-content: center; padding: 12px 4px; }
  .star-btn { font-size: 36px; padding: 6px; }

  .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; flex-shrink: 0; padding: 10px 14px; }
  .card-header { flex-wrap: wrap; gap: 10px; }
  .data-table thead th,
  .data-table tbody td { padding: 10px 12px; font-size: 13px; }
  .profile-card-inner { flex-direction: column; gap: 16px; }
  .profile-card-actions { width: 100%; }
  .profile-card-actions .btn { flex: 1; justify-content: center; }

  /* Search bar stack vertically */
  .trainers-search-bar { flex-direction: column; align-items: stretch; }
  .trainers-search-bar select { min-width: unset; width: 100%; }
  .trainers-search-bar .btn { width: 100%; justify-content: center; }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 17px; }
  .btn { padding: 9px 14px; font-size: 13px; }
  .btn-sm { padding: 7px 12px; font-size: 12px; }
  .stat-value { font-size: 22px; }
  .login-card { padding: 28px 20px; }
  .profile-card { padding: 16px; }
  .profile-card-name { font-size: 18px; }
  .profile-card-avatar { width: 56px; height: 56px; font-size: 22px; border-radius: 14px; }
}

/* ── Accessibility ────────────────────────────────────────── */

/* Skip to main content link for keyboard/screen reader users */
.skip-link {
  position: absolute;
  top: -999px;
  left: -999px;
  background: var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: 0 0 8px 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 0; left: 0; }

/* Visible focus ring for keyboard navigation */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove outline only for mouse clicks, keep for keyboard */
:focus:not(:focus-visible) { outline: none; }

/* Buttons always have min touch target 44px */
.btn, .tab, .sidebar-link, .pagination a {
  min-height: 44px;
}
.btn-xs { min-height: 32px; }
.btn-sm { min-height: 36px; }

/* High contrast for muted text — ensure 4.5:1 ratio */
.text-muted, .info-label, .stat-label,
.sidebar-section-label, .sidebar-user-role,
.note-time { color: #64748B; }

/* Ensure form labels are always visible */
.form-label { font-size: 14px; font-weight: 600; color: #374151; }

/* Error/success messages have icon + text for color-blind users */
.flash svg { flex-shrink: 0; }

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.trainers-search-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.trainers-filters-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}
.trainers-filters-row select { flex: 1; min-width: 0; }
.btn-text-hide { display: inline; }
.btn-text-show { display: none; }
@media (min-width: 769px) {
  .trainers-search-bar { flex-direction: row; align-items: center; }
  .trainers-filters-row { flex: 1; flex-wrap: nowrap; }
}
@media (max-width: 480px) {
  .btn-text-hide { display: none; }
  .btn-text-show { display: inline; }
}
.trainers-table-desktop { display: block; }
.trainers-list-mobile { display: none; }
.trainer-mobile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}
.trainer-mobile-card:active { background: var(--primary-50); }
.trainer-mobile-card:last-child { border-bottom: none; }

/* Users / Templates mobile show/hide — defaults (desktop) */
.users-table-desktop  { display: block; }
.users-list-mobile    { display: none; }
.tmpl-table-desktop   { display: block; }
.tmpl-list-mobile     { display: none; }
.cert-table-desktop   { display: block; }
.cert-list-mobile     { display: none; }
.trainers-table-desktop { display: block; }
.trainers-list-mobile   { display: none; }

/* Switch to cards on mobile — must come AFTER the defaults above */
@media (max-width: 768px) {
  .users-table-desktop    { display: none; }
  .users-list-mobile      { display: block; }
  .tmpl-table-desktop     { display: none; }
  .tmpl-list-mobile       { display: block; }
  .cert-table-desktop     { display: none; }
  .cert-list-mobile       { display: block; }
  .trainers-table-desktop { display: none; }
  .trainers-list-mobile   { display: block; }
}
.sidebar-overlay {
  display: none;
}

/* Sidebar toggle button — hidden on desktop, shown on mobile */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  color: var(--text-primary);
  transition: var(--transition);
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-toggle-btn svg { width: 20px; height: 20px; display: block; pointer-events: none; }
  cursor: pointer;
  color: var(--text-primary);
  transition: var(--transition);
  flex-shrink: 0;
  touch-action: manipulation;
}
}
.sidebar-toggle-btn:hover { background: var(--bg-body); }
.sidebar-toggle-btn svg { width: 20px; height: 20px; display: block; }

/* ── Utility ──────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.text-primary-color { color: var(--primary); }
.font-mono { font-family: 'Courier New', monospace; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.hidden { display: none !important; }
.inline { display: inline; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-xs { font-size: 12px; }
/* Screen reader only — visible to screen readers, hidden visually */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
/* Certificates: show table on desktop, cards on mobile */
.text-sm { font-size: 14px; }
.line-through { text-decoration: line-through; }
.link { color: var(--primary); }
.link:hover { text-decoration: underline; }
.opacity-muted { opacity: 0.55; }

/* ── Schedule Calendar ────────────────────────────────────── */
.sch-desktop { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
@media (max-width: 1200px) { .sch-desktop { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 900px)  { .sch-desktop { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px)  { .sch-desktop { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
@media (max-width: 400px)  { .sch-desktop { grid-template-columns: 1fr; } }

/* Desktop day card */
.schedule-day { background:var(--bg-card); border:1px solid var(--border-color); border-radius:var(--border-radius); overflow:hidden; transition:box-shadow 0.2s; }
.schedule-day:hover { box-shadow: var(--shadow-md); }
.schedule-has-trainer { border-top: 3px solid var(--success); }
.schedule-has-session { border-top: 3px solid var(--primary); }
.schedule-holiday     { border-top: 3px solid var(--warning); background:#FFFBEB; }
.schedule-empty       { background:var(--bg-body); opacity:0.75; }
.schedule-day-header  { display:flex; justify-content:space-between; align-items:center; padding:8px 12px; border-bottom:1px solid var(--border-color); background:rgba(0,0,0,0.02); }
.schedule-day-name    { font-size:11px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.5px; }
.schedule-day-num     { font-size:20px; font-weight:800; color:var(--text-primary); line-height:1; }
.schedule-day-body    { padding:12px; }

/* Mobile list */
.sch-row { display:flex; border-bottom:1px solid var(--border-color); background:var(--bg-card); }
.sch-row:first-child { border-top:1px solid var(--border-color); border-radius:12px 12px 0 0; }
.sch-row:last-child  { border-radius:0 0 12px 12px; }
.sch-trainer { border-right:4px solid var(--success); }
.sch-pending  { border-right:4px solid var(--primary); }
.sch-holiday  { border-right:4px solid var(--warning); background:#FFFBEB; }
.sch-empty    { background:var(--bg-body); opacity:0.8; }
.sch-date {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-width:56px; width:56px; padding:16px 8px; flex-shrink:0;
  border-left:1px solid var(--border-color); background:rgba(0,0,0,0.025);
}
.sch-dnum  { font-size:24px; font-weight:800; color:var(--text-primary); line-height:1; }
.sch-dname { font-size:10px; font-weight:600; color:var(--text-muted); text-transform:uppercase; margin-top:3px; }
.sch-content { flex:1; min-width:0; padding:14px 14px; }
.sch-title   { font-size:14px; font-weight:700; color:var(--text-primary); margin-bottom:5px; line-height:1.4; }
.sch-time    { display:inline-flex; align-items:center; gap:4px; font-size:11px; font-weight:600; color:var(--primary); background:rgba(79,70,229,0.08); padding:2px 8px; border-radius:4px; margin-bottom:5px; }
.sch-trainer-name, .sch-trainer { font-size:13px; font-weight:600; color:var(--success); margin-bottom:3px; }
.sch-notrainer { font-size:12px; color:var(--warning); font-style:italic; margin-bottom:3px; }
.sch-coord   { font-size:11px; color:var(--text-muted); margin-bottom:3px; }
.sch-notes   { font-size:11px; color:var(--text-secondary); background:var(--bg-body); padding:4px 8px; border-radius:6px; margin-bottom:6px; }
.sch-actions { display:flex; flex-wrap:wrap; gap:6px; margin-top:10px; padding-top:10px; border-top:1px solid var(--border-color); }

/* Schedule modals — completely isolated from .hidden system */
.sch-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}
/* opening handled entirely by JS setProperty — no CSS selector needed */
.sch-modal-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 24px;
  animation: schModalIn 0.2s ease;
}
@keyframes schModalIn {
  from { opacity:0; transform:scale(0.95) translateY(-12px); }
  to   { opacity:1; transform:scale(1) translateY(0); }
}
.sch-modal-header {
  display:flex; align-items:center; justify-content:space-between; margin-bottom:20px;
}
.sch-modal-header h3 { font-size:16px; font-weight:700; color:var(--text-primary); margin:0; }
.sch-modal-close {
  background:none; border:none; cursor:pointer; font-size:18px; color:var(--text-muted);
  width:32px; height:32px; border-radius:8px; display:flex; align-items:center; justify-content:center;
  transition:background 0.15s;
}
.sch-modal-close:hover { background:var(--bg-body); color:var(--text-primary); }
@media (max-width: 480px) { .sch-modal-box { padding:16px; border-radius:12px; } }

/* Trainer search dropdown */
.sch-search-results {
  display: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  margin-top: 4px;
  z-index: 10;
  position: relative;
}
.sch-search-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
  transition: background 0.1s;
}
.sch-search-item:last-child { border-bottom: none; }
.sch-search-item:hover { background: var(--primary-50); }
.sch-selected-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 8px 12px;
  background: #D1FAE5;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #065F46;
}
.sch-selected-badge button {
  background: none; border: none; cursor: pointer; color: #065F46;
  font-size: 16px; padding: 0 4px; line-height: 1;
}


/* ── Modals ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}
/* .hidden class (display:none !important) handles hiding — no override needed here */
.modal-box {
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }

@media (max-width: 480px) {
  .modal-box { padding: 16px; }
}

/* ── Sidebar Logout Button ────────────────────────────────── */
.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  border-radius: var(--border-radius-sm);
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(239,68,68,0.1);
  color: #FCA5A5;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-logout-btn:hover {
  background: rgba(239,68,68,0.2);
  color: #FEE2E2;
  border-color: rgba(239,68,68,0.3);
}

.sidebar-logout-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
