/* =====================================================================
   نظام إدارة الجيم - التصميم العام (Mobile-first, RTL)
   ===================================================================== */

:root {
    --color-primary: #2f6690;
    --color-primary-dark: #204a6e;
    --color-primary-light: #e8f0f7;
    --color-green: #1f9d55;
    --color-green-bg: #e5f7ec;
    --color-red: #d3455b;
    --color-red-bg: #fbe8ea;
    --color-orange: #d98324;
    --color-orange-bg: #fdf1e0;
    --color-gray: #6b7280;
    --color-gray-bg: #eef0f2;
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --sidebar-width: 250px;
    --topbar-height: 58px;
    --bottom-nav-height: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-body);
    color: var(--text-main);
    font-family: 'Cairo', Tahoma, Arial, sans-serif;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body { direction: rtl; }

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4 { margin: 0 0 .5rem; }
p { margin: 0 0 .5rem; }

.nav-icon { width: 20px; height: 20px; flex: none; }

/* ---------------------------------------------------------------------
   Layout shell
   --------------------------------------------------------------------- */
.app-shell { min-height: 100vh; }
.app-content {
    min-height: 100vh;
    padding-bottom: calc(var(--bottom-nav-height) + 12px);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
}
.topbar-title { font-size: 1.05rem; font-weight: 700; margin: 0; }
.topbar-spacer { flex: 1; }

.hamburger-btn {
    width: 40px; height: 40px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 5px; background: none; border: none; cursor: pointer; border-radius: 8px;
}
.hamburger-btn span { display: block; width: 20px; height: 2px; background: var(--text-main); border-radius: 2px; }
.hamburger-btn:active { background: var(--color-gray-bg); }

.page-main { padding: 14px; max-width: 1100px; margin: 0 auto; }

/* ---------------------------------------------------------------------
   Sidebar (desktop) / slide-in drawer (mobile)
   --------------------------------------------------------------------- */
.sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-primary-dark);
    color: #fff;
    z-index: 40;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    transform: translateX(100%);
    transition: transform .25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px 18px;
    font-weight: 800; font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 12px;
}
.brand-icon { font-size: 1.4rem; }
.sidebar-brand .brand-name { flex: 1; }

.sidebar-close-btn {
    width: 36px; height: 36px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.08); border: none; border-radius: 8px;
    color: #fff; cursor: pointer;
}
.sidebar-close-btn:active { background: rgba(255,255,255,.16); }
.sidebar-close-btn svg { width: 18px; height: 18px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.sidebar .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.85); font-weight: 600; font-size: .95rem;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.08); }
.sidebar .nav-link.active { background: #fff; color: var(--color-primary-dark); }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; margin-top: 8px; }
.sidebar-user { padding: 6px 12px 10px; font-size: .85rem; color: rgba(255,255,255,.65); }
.logout-link { color: #ffb4b4 !important; }

.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.5);
    z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

/* ---------------------------------------------------------------------
   Bottom navigation (mobile only)
   --------------------------------------------------------------------- */
.bottom-nav {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
    height: var(--bottom-nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    box-shadow: 0 -2px 8px rgba(16,24,40,.05);
}
.bottom-nav-link {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: .68rem; color: var(--text-muted); font-weight: 600;
}
.bottom-nav-link.active { color: var(--color-primary); }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 18px; border-radius: var(--radius-sm); border: none;
    font-family: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
    min-height: 46px; text-align: center; transition: filter .15s ease, transform .05s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--color-gray-bg); color: var(--text-main); }
.btn-success { background: var(--color-green); color: #fff; }
.btn-danger { background: var(--color-red); color: #fff; }
.btn-outline { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-sm { padding: 8px 12px; min-height: 36px; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { padding: 10px; min-width: 46px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------- */
.card {
    background: var(--bg-card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-title { font-size: 1rem; font-weight: 800; margin: 0; }

/* Stat cards grid */
.stats-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px;
}
.stat-card {
    background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px; display: flex; flex-direction: column; gap: 4px;
    border-inline-start: 4px solid var(--color-primary);
}
.stat-card .stat-label { font-size: .78rem; color: var(--text-muted); font-weight: 600; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; }
.stat-card.accent-green { border-inline-start-color: var(--color-green); }
.stat-card.accent-red { border-inline-start-color: var(--color-red); }
.stat-card.accent-orange { border-inline-start-color: var(--color-orange); }

/* Quick actions */
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.quick-action {
    background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
    font-weight: 700; font-size: .85rem; color: var(--color-primary-dark);
}
.quick-action .qa-icon {
    width: 44px; height: 44px; border-radius: 50%; background: var(--color-primary-light);
    display: flex; align-items: center; justify-content: center; color: var(--color-primary);
}
.quick-action .qa-icon svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px;
    font-size: .75rem; font-weight: 700;
}
.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-orange { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-gray { background: var(--color-gray-bg); color: var(--color-gray); }

/* ---------------------------------------------------------------------
   Alerts / flash messages
   --------------------------------------------------------------------- */
.flash-stack { margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: .9rem; }
.alert-success { background: var(--color-green-bg); color: var(--color-green); }
.alert-error { background: var(--color-red-bg); color: var(--color-red); }
.alert-warning { background: var(--color-orange-bg); color: var(--color-orange); }
.alert-info { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-weight: 700; font-size: .88rem; margin-bottom: 6px; }
.form-control {
    width: 100%; padding: 12px 14px; border: 1.5px solid var(--border-color); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .95rem; background: #fff; color: var(--text-main);
}
.form-control:focus { outline: none; border-color: var(--color-primary); }
.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: .8rem; color: var(--color-red); margin-top: 4px; font-weight: 600; }
.form-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; padding-left: 32px; }

/* ---------------------------------------------------------------------
   Tables -> stacked cards on mobile
   --------------------------------------------------------------------- */
.table-wrap { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 14px; text-align: start; font-size: .9rem; }
.data-table thead { display: none; }
.data-table tbody tr {
    display: block; border-bottom: 1px solid var(--border-color); padding: 10px 4px;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: none; padding: 6px 10px; text-align: end; }
.data-table td::before { content: attr(data-label); font-weight: 700; color: var(--text-muted); font-size: .78rem; text-align: start; }
.data-table td.cell-actions { justify-content: flex-end; }
.data-table td.cell-actions::before { content: ''; }

@media (min-width: 768px) {
    .data-table thead { display: table-header-group; }
    .data-table thead th { background: var(--color-primary-light); color: var(--color-primary-dark); font-size: .8rem; }
    .data-table tbody tr { display: table-row; border-bottom: 1px solid var(--border-color); padding: 0; }
    .data-table td { display: table-cell; text-align: start; padding: 12px 14px; }
    .data-table td::before { display: none; }
    .data-table td.cell-actions { justify-content: flex-start; }
    .table-scroll { overflow-x: auto; }
}

/* ---------------------------------------------------------------------
   Misc utility
   --------------------------------------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 10px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap-2 { gap: 8px; }
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar .form-control { flex: 1; min-width: 160px; }
.search-bar .search-select { flex: 1; min-width: 160px; }

/* ---------------------------------------------------------------------
   Searchable dropdown (combobox with the search box inside the list),
   used for trainee/member pickers.
   --------------------------------------------------------------------- */
.search-select { position: relative; }
.search-select-panel {
    position: absolute; top: calc(100% + 4px); inset-inline: 0;
    background: var(--bg-card); border: 1.5px solid var(--border-color); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); max-height: 260px; overflow-y: auto;
    z-index: 50; display: none;
}
.search-select-panel.open { display: block; }
.search-select-option { padding: 10px 14px; font-size: .9rem; cursor: pointer; border-bottom: 1px solid var(--border-color); }
.search-select-option:last-child { border-bottom: none; }
.search-select-option:hover, .search-select-option.active { background: var(--color-primary-light); }
.search-select-empty { padding: 12px 14px; font-size: .85rem; color: var(--text-muted); text-align: center; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.filter-tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.filter-tab {
    padding: 8px 16px; border-radius: 999px; background: var(--bg-card); border: 1.5px solid var(--border-color);
    font-weight: 700; font-size: .82rem; white-space: nowrap; color: var(--text-muted);
}
.filter-tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.detail-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border-color); font-size: .9rem; }
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text-muted); font-weight: 600; }
.detail-row .value { font-weight: 700; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, var(--color-primary-dark), var(--color-primary)); }
.login-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 28px 24px; width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .brand-icon { font-size: 2.4rem; display: block; margin-bottom: 8px; }
.login-brand h1 { font-size: 1.15rem; font-weight: 800; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 60; display: none; align-items: flex-end; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; padding: 20px; max-height: 85vh; overflow-y: auto; }
@media (min-width: 768px) {
    .modal-backdrop { align-items: center; }
    .modal-box { border-radius: var(--radius); }
}

/* ---------------------------------------------------------------------
   Desktop layout
   --------------------------------------------------------------------- */
@media (min-width: 992px) {
    .app-content { margin-inline-start: var(--sidebar-width); padding-bottom: 20px; }
    .sidebar { transform: translateX(0); position: fixed; }
    .sidebar-overlay { display: none; }
    .hamburger-btn { display: none; }
    .sidebar-close-btn { display: none; }
    .bottom-nav { display: none; }
    .page-main { padding: 24px 28px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .quick-actions { grid-template-columns: repeat(5, 1fr); }
    .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
    .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
    .topbar { padding: 0 24px; }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .quick-actions { grid-template-columns: repeat(4, 1fr); }
}
