/* ============================================
   Al Boukhari — نظام إدارة الدفعات
   تصميم احترافي v3 — green + gold (هوية البخاري)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Cairo:wght@400;500;600;700&display=swap');

:root {
    /* Backgrounds & neutrals — brand ivory */
    --color-bg: #fbfaf7;          /* brand-ivory */
    --color-surface: #ffffff;
    --color-surface-alt: #f6f3eb; /* brand-sand soft */
    --color-surface-3: #faf8f1;
    --color-border: #e8e1d2;
    --color-border-strong: #d8ccb4;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-text-soft: #94a3b8;

    /* Brand — green + gold (Al-Boukhari logo) */
    --color-primary: #277245;     /* brand-green */
    --color-primary-hover: #206d3d;
    --color-primary-deep: #1b5733;
    --color-primary-soft: #e8f1ec;
    --color-primary-text: #1b5733;
    --color-primary-glow: rgba(39, 114, 69, 0.18);

    --color-accent: #b48e63;      /* brand-gold */
    --color-accent-hover: #9c7a52;
    --color-accent-soft: #f5ede1;
    --color-accent-glow: rgba(180, 142, 99, 0.22);

    --color-success: #2f7a3f;     /* tuned to brand-green hue */
    --color-success-soft: #e1efe5;
    --color-warning: #b88641;     /* gold-tinted */
    --color-warning-soft: #f6ead6;
    --color-danger: #b91c1c;
    --color-danger-soft: #fde0e0;
    --color-info: #0e7490;
    --color-info-soft: #def0f3;

    --brand-gradient: linear-gradient(135deg, #277245 0%, #1b5733 100%);
    --gold-gradient: linear-gradient(135deg, #c9a57f 0%, #b48e63 100%);
    --noise-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");

    /* المسافات */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 12px 24px -6px rgba(15, 23, 42, 0.12), 0 4px 8px -4px rgba(15, 23, 42, 0.08);
    --shadow-xl: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

html { font-family: 'Inter', 'Cairo', system-ui, -apple-system, sans-serif; }
html[lang="ar"] { font-family: 'Cairo', 'Inter', system-ui, sans-serif; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: inherit; }

/* ============================================
   Topbar
   ============================================ */
.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 60px;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar .brand {
    font-weight: 800;
    font-size: 16px;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    margin-inline-end: 8px;
    border-inline-end: 1px solid var(--color-border);
    height: 60px;
    line-height: 60px;
}

.topbar .brand .logo-mark {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
}

.topbar .nav-link {
    padding: 8px 14px;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 13px;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.topbar .nav-link:hover {
    color: var(--color-text);
    background: var(--color-surface-alt);
}
.topbar .nav-link.active {
    color: var(--color-primary-text);
    background: var(--color-primary-soft);
    font-weight: 600;
}

.topbar-spacer { flex: 1; }

.topbar .search-global {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 7px 14px 7px 36px;
    width: 320px;
    font-size: 13px;
    transition: all 0.15s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}
html[dir="rtl"] .topbar .search-global {
    padding: 7px 36px 7px 14px;
    background-position: calc(100% - 12px) center;
}
.topbar .search-global:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    background-color: white;
}

.lang-switcher {
    display: inline-flex;
    align-items: center;
    background: var(--color-surface-alt);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}
.lang-switcher a {
    padding: 4px 9px;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.15s;
}
.lang-switcher a:hover { color: var(--color-text); }
.lang-switcher a.active {
    background: white;
    color: var(--color-primary);
    box-shadow: var(--shadow-xs);
}

/* ============================================
   Main container
   ============================================ */
.main {
    padding: 20px 24px;
    max-width: 100%;
}

.page-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.page-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border-strong);
    background: white;
    color: var(--color-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
    text-decoration: none;
    user-select: none;
    white-space: nowrap;
}
.btn:hover:not(:disabled) {
    background: var(--color-surface-alt);
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; gap: 4px; }
.btn-lg { padding: 10px 22px; font-size: 15px; }
.btn-icon { padding: 6px; }

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-success { background: var(--color-success); color: white; border-color: var(--color-success); }
.btn-success:hover:not(:disabled) { background: #047857; border-color: #047857; }

.btn-warning { background: var(--color-warning); color: white; border-color: var(--color-warning); }
.btn-warning:hover:not(:disabled) { background: #b45309; border-color: #b45309; }

.btn-danger { background: var(--color-danger); color: white; border-color: var(--color-danger); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }

.btn-soft-primary { background: var(--color-primary-soft); color: var(--color-primary-text); border-color: transparent; }
.btn-soft-success { background: var(--color-success-soft); color: #065f46; border-color: transparent; }
.btn-soft-danger { background: var(--color-danger-soft); color: #991b1b; border-color: transparent; }
.btn-soft-warning { background: var(--color-warning-soft); color: #92400e; border-color: transparent; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { color: var(--color-text); background: var(--color-surface-alt); }

/* ============================================
   Form Controls
   ============================================ */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 12px;
    color: var(--color-text);
    letter-spacing: 0.01em;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border-strong);
    font-size: 13px;
    font-family: inherit;
    color: var(--color-text);
    background: white;
    transition: all 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.form-textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

.form-row { display: grid; gap: 12px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; } }

/* Method toggle */
.method-toggle { display: flex; gap: 8px; }
.method-toggle button {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius);
    border: 2px solid var(--color-border);
    background: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.method-toggle button:hover { transform: translateY(-1px); }
.method-toggle button.cash.active {
    background: var(--color-warning-soft);
    border-color: var(--color-warning);
    color: #78350f;
}
.method-toggle button.bank.active {
    background: var(--color-info-soft);
    border-color: var(--color-info);
    color: #075985;
}

/* ============================================
   Stats / KPI cards
   ============================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-xs);
    transition: all 0.15s;
}
.kpi:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.kpi .label { font-size: 11px; color: var(--color-text-muted); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.kpi .value { font-size: 28px; font-weight: 800; color: var(--color-text); margin-top: 4px; line-height: 1.1; }
.kpi .meta { font-size: 11px; color: var(--color-text-muted); margin-top: 4px; }
.kpi.success { background: linear-gradient(135deg, #ecfdf5, white); border-color: #a7f3d0; }
.kpi.success .value { color: #065f46; }
.kpi.warning { background: linear-gradient(135deg, #fffbeb, white); border-color: #fde68a; }
.kpi.warning .value { color: #92400e; }
.kpi.danger { background: linear-gradient(135deg, #fef2f2, white); border-color: #fecaca; }
.kpi.danger .value { color: #991b1b; }
.kpi.info { background: linear-gradient(135deg, #eef2ff, white); border-color: #c7d2fe; }
.kpi.info .value { color: #3730a3; }

/* ============================================
   Filters bar
   ============================================ */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    box-shadow: var(--shadow-xs);
}
.filters-bar input, .filters-bar select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--color-border-strong);
    font-size: 13px;
    font-family: inherit;
    background: white;
}
.filters-bar input:focus, .filters-bar select:focus { outline: none; border-color: var(--color-primary); }
.filters-bar input.search { min-width: 280px; }
.filter-divider { width: 1px; background: var(--color-border); height: 24px; margin: 0 4px; }

/* Actions bar */
.actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    box-shadow: var(--shadow-xs);
}
.actions-group { display: flex; gap: 6px; align-items: center; }
.actions-group::after {
    content: '';
    width: 1px;
    background: var(--color-border);
    height: 24px;
    margin: 0 4px;
}
.actions-group:last-child::after { display: none; }

/* ============================================
   Selection / Bulk Action Bar
   ============================================ */
.bulk-bar {
    position: sticky;
    top: 60px;
    z-index: 20;
    background: var(--color-primary);
    color: white;
    padding: 10px 16px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-md);
}
.bulk-bar .btn { background: rgba(255,255,255,0.15); color: white; border-color: rgba(255,255,255,0.3); }
.bulk-bar .btn:hover { background: rgba(255,255,255,0.25); }
.bulk-bar .btn-danger { background: rgba(220, 38, 38, 0.9); border-color: rgba(220, 38, 38, 1); }

/* ============================================
   Table — students grid
   ============================================ */
.grid-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    overflow: auto;
    max-height: calc(100vh - 280px);
    position: relative;
}
.students-grid {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 13px;
}
.students-grid thead th {
    position: sticky;
    top: 0;
    background: var(--color-surface-alt);
    color: var(--color-text);
    padding: 9px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.students-grid thead th:hover { background: var(--color-border); }
.students-grid thead th .sort-icon { opacity: 0.4; margin-inline-start: 4px; font-size: 10px; }
.students-grid thead th.sorted .sort-icon { opacity: 1; color: var(--color-primary); }

.students-grid tbody td {
    padding: 8px;
    border-bottom: 1px solid var(--color-border);
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}
.students-grid tbody tr { transition: background 0.1s; }
.students-grid tbody tr:hover { background: var(--color-surface-alt); }
.students-grid tbody tr.selected { background: var(--color-primary-soft) !important; }

/* Sticky columns */
.students-grid th.sticky-col, .students-grid td.sticky-col {
    position: sticky;
    background: inherit;
    z-index: 5;
}
.students-grid th.sticky-col.col-checkbox, .students-grid td.sticky-col.col-checkbox {
    inset-inline-start: 0; width: 36px; min-width: 36px; background: var(--color-surface-alt); z-index: 11;
}
.students-grid tbody td.sticky-col.col-checkbox { background: white; }
.students-grid tbody tr:hover td.sticky-col.col-checkbox { background: var(--color-surface-alt); }
.students-grid tbody tr.selected td.sticky-col.col-checkbox { background: var(--color-primary-soft); }

.students-grid th.sticky-col.col-id, .students-grid td.sticky-col.col-id {
    /* min/max pin the width: the name column is offset by exactly 36 + 50px,
       so a shrinking ID column left a gap that showed cells scrolling under. */
    inset-inline-start: 36px; width: 50px; min-width: 50px; max-width: 50px; background: var(--color-surface-alt); z-index: 11;
}
.students-grid tbody td.sticky-col.col-id { background: white; color: var(--color-text-muted); font-size: 11px; }
.students-grid tbody tr:hover td.sticky-col.col-id { background: var(--color-surface-alt); }
.students-grid tbody tr.selected td.sticky-col.col-id { background: var(--color-primary-soft); }

.students-grid th.sticky-col.col-name, .students-grid td.sticky-col.col-name {
    inset-inline-start: 86px; min-width: 180px; text-align: start; padding-inline-start: 12px; z-index: 11;
    background: var(--color-surface-alt);
}
.students-grid tbody td.sticky-col.col-name { background: white; font-weight: 600; text-align: start; }
.students-grid tbody tr:hover td.sticky-col.col-name { background: var(--color-surface-alt); }
.students-grid tbody tr.selected td.sticky-col.col-name { background: var(--color-primary-soft); }

.row-link {
    color: var(--color-text);
    text-decoration: none;
    transition: color 0.1s;
    cursor: pointer;
}
.row-link:hover { color: var(--color-primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.row-link.row-link-busy {
    color: var(--color-primary);
    animation: pulse 0.9s ease-in-out infinite;
}

/* Month cells with gradient */
.cell-month {
    min-width: 56px;
    cursor: pointer;
    user-select: none;
    transition: outline 0.12s, background 0.12s;
    position: relative;
}
.cell-month:hover {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    z-index: 2;
}
.cell-month:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    z-index: 2;
}
.cell-content { display: flex; flex-direction: column; align-items: center; line-height: 1.1; gap: 2px; position: relative; }
.cell-content .amount { font-weight: 700; font-size: 12px; }
.cell-content .method-icon { font-size: 10px; opacity: 0.7; }
.cell-content .cell-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    opacity: 0;
    transition: opacity 0.12s;
    pointer-events: none;
}
.cell-month:hover .cell-hint { opacity: 0.55; }
.cell-month:hover .amount, .cell-month:hover .method-icon { opacity: 0.25; transition: opacity 0.12s; }
.cell-paid { background: linear-gradient(135deg, #ecfdf5, #d1fae5); color: #065f46; }
.cell-paid-advance {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #064e3b;
    font-weight: 700;
    position: relative;
}
.cell-paid-advance::before {
    content: '⏭';
    position: absolute;
    top: 2px;
    inset-inline-end: 3px;
    font-size: 9px;
    opacity: 0.6;
}
.cell-partial { background: linear-gradient(135deg, #fffbeb, #fef3c7); color: #92400e; }
.cell-unpaid { background: #fef2f2; color: #991b1b; }
.cell-late { background: linear-gradient(135deg, #fee2e2, #fecaca); color: #7f1d1d; font-weight: 700; }
.cell-legacy-zero { background: linear-gradient(135deg, #e0f2fe, #bae6fd); color: #075985; }
.cell-notdue { background: var(--color-surface-alt); color: var(--color-text-soft); }
.cell-not-enrolled {
    background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 4px, #f1f5f9 4px, #f1f5f9 8px);
    color: #94a3b8;
    font-style: italic;
}

/* Global Livewire progress indicator (top of page) */
.livewire-progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    z-index: 9999;
    background: rgba(79, 70, 229, 0.1);
    overflow: hidden;
    pointer-events: none;
}
.livewire-progress-bar {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--color-primary), #7c3aed);
    box-shadow: 0 0 8px rgba(79, 70, 229, 0.5);
    animation: livewire-progress-slide 1.1s ease-in-out infinite;
}
@keyframes livewire-progress-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* Sibling badge */
.sibling-badge {
    background: var(--color-success);
    color: white;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: background 0.15s, transform 0.15s;
}
.sibling-badge:hover { background: #047857; transform: scale(1.05); }

.sibling-badge-solo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--color-surface-alt);
    color: var(--color-text-soft);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    border: 1px solid var(--color-border);
}
.sibling-badge-solo:hover { background: var(--color-primary-soft); color: var(--color-primary); transform: scale(1.08); border-color: var(--color-primary); }

.status-badge { font-size: 14px; opacity: 0.7; }

/* ============================================
   Side panel
   ============================================ */
.side-panel-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 100;
}
.side-panel {
    position: fixed;
    top: 0;
    inset-inline-end: 0;
    height: 100vh;
    width: 520px;
    max-width: 94vw;
    background: white;
    box-shadow: var(--shadow-xl);
    z-index: 101;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.side-panel-header {
    padding: 16px 20px;
    background: var(--color-surface-alt);
    border-bottom: 1px solid var(--color-border);
    position: sticky; top: 0;
    display: flex; justify-content: space-between; align-items: center;
    z-index: 5;
}
.side-panel-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.side-panel-body { padding: 18px 20px; flex: 1; }
.side-panel-section { margin-bottom: 22px; }
.side-panel-section h3 {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.summary-item {
    background: var(--color-surface-alt);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 12px;
}
.summary-item .label { color: var(--color-text-muted); font-size: 10px; }
.summary-item .value { font-weight: 700; font-size: 14px; margin-top: 2px; }

/* Sibling chips */
.siblings-strip {
    background: var(--color-surface-alt);
    padding: 10px 12px;
    border-radius: var(--radius);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.sibling-chip {
    background: white;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--color-border);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
    font-weight: 500;
}
.sibling-chip:hover { background: var(--color-primary); color: white; border-color: var(--color-primary); }

/* Tabs */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 16px;
}
.tabs button {
    background: transparent;
    border: none;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 500;
    transition: all 0.15s;
}
.tabs button:hover { color: var(--color-text); }
.tabs button.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 700; }

/* ============================================
   Modals
   ============================================ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-box {
    background: white;
    border-radius: var(--radius-xl);
    width: 480px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--color-surface-alt);
}
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    display: flex; gap: 8px; justify-content: flex-end;
    background: var(--color-surface-alt);
}

/* ============================================
   Family modal
   ============================================ */
.family-modal-box { width: 620px; }
.family-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--color-surface-alt);
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 13px;
}
.family-summary .family-balance { font-weight: 600; }
.family-members {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 60vh;
    overflow-y: auto;
}
.family-member {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 11px 13px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: background 0.12s, border-color 0.12s, transform 0.08s, box-shadow 0.12s;
    position: relative;
}
.family-member:hover { background: var(--color-surface-alt); border-color: var(--color-border-strong); }
.family-member.is-self { border-color: var(--color-primary); background: var(--color-primary-soft); }

/* Whole row clickable — clear affordance */
.family-member-clickable {
    cursor: pointer;
    user-select: none;
}
.family-member-clickable:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    box-shadow: 0 2px 8px -2px rgba(79, 70, 229, 0.15);
    transform: translateY(-1px);
}
.family-member-clickable:hover .member-name-text { color: var(--color-primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.family-member-clickable:active { transform: translateY(0); }
.family-member-clickable:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
.family-member-clickable.member-busy {
    animation: pulse 0.9s ease-in-out infinite;
    pointer-events: none;
}
.member-name-text { transition: color 0.12s; }
.family-member .member-main { min-width: 0; }
.family-member .member-name { display: flex; gap: 6px; align-items: center; font-size: 14px; margin-bottom: 4px; flex-wrap: wrap; }
.family-member .member-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 11px;
    color: var(--color-text-muted);
}
.family-member .member-meta span { display: inline-flex; align-items: center; gap: 3px; }
.family-member .member-meta .meta-phone { font-family: ui-monospace, monospace; }
.family-member .member-balance {
    font-weight: 800;
    font-size: 18px;
    text-align: end;
    min-width: 70px;
}
.family-member .member-actions { display: flex; gap: 4px; }

@media (max-width: 640px) {
    .family-member { grid-template-columns: 1fr auto; }
    .family-member .member-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* Family window as a family payment form (v7.5): month / method / date bar,
   then one amount field per child, prefilled with what is still owed. */
.family-modal-box { width: 780px; max-width: calc(100vw - 32px); }
.family-paybar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 14px;
    padding: 10px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.family-paybar .fp-field { display: flex; flex-direction: column; gap: 4px; }
.family-paybar .fp-label { font-size: 11px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
html[dir="rtl"] .family-paybar .fp-label { text-transform: none; letter-spacing: 0; }
.family-paybar .fp-month { min-width: 160px; }
.family-paybar .fp-method { flex: 1 1 220px; }
.family-paybar .fp-date { width: 150px; }
.family-member { grid-template-columns: minmax(0, 1fr) auto auto auto; }
.family-member .member-month { text-align: center; min-width: 110px; }
.family-member .member-month-sub { font-size: 11px; color: var(--color-text-muted); margin-top: 4px; white-space: nowrap; }
.family-member .member-pay { display: flex; align-items: center; gap: 4px; }
.family-member .member-amount { width: 92px; font-size: 17px; font-weight: 700; text-align: center; padding: 8px 6px; }
.family-member .member-amount-cur { font-weight: 700; color: var(--color-text-muted); }
.family-member .meta-balance.is-owed { color: var(--color-danger); font-weight: 700; }
.family-member .meta-balance.is-clear { color: var(--color-success); font-weight: 700; }
.modal-footer .fp-hint { margin-inline-end: auto; }
@media (max-width: 640px) {
    .family-member { grid-template-columns: 1fr auto; }
    .family-member .member-month { text-align: start; }
    .modal-footer .fp-hint { display: none; }
}

/* Family window v2 (v7.6): the year's payments table on top, the month form below. */
.family-modal-box { width: 1000px; }
.family-summary { gap: 10px 16px; flex-wrap: wrap; }
.family-summary .btn { margin-inline-start: auto; }
.family-summary .fam-owed { color: var(--color-danger); }
.family-summary .fam-clear { color: var(--color-success); }
.family-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-bottom: 10px; }
.family-controls .fp-field { display: flex; flex-direction: column; gap: 4px; }
.family-controls .fp-label { font-size: 11px; font-weight: 600; color: var(--color-text-muted); }
.family-controls .fp-year { min-width: 110px; }
.family-controls .fp-month { min-width: 150px; }
.family-table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 16px; }
.family-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.family-table th, .family-table td { padding: 7px 5px; text-align: center; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.family-table thead th { background: var(--color-surface-alt); color: var(--color-text-muted); font-size: 11px; font-weight: 700; }
.family-table tbody tr:last-child td { border-bottom: none; }
.family-table .fam-name { text-align: start; min-width: 140px; position: sticky; inset-inline-start: 0; z-index: 1; background: var(--color-surface); font-weight: 600; }
.family-table thead .fam-name, .family-table tfoot .fam-name { background: var(--color-surface-alt); }
.family-table .fam-name-link { background: none; border: 0; padding: 0; font: inherit; color: var(--color-text); cursor: pointer; text-align: start; }
.family-table .fam-name-link:hover { color: var(--color-primary); text-decoration: underline; }
.family-table tr.is-self .fam-name-link { color: var(--color-primary-text); }
.family-table th.fam-month, .family-table td.fam-cell { cursor: pointer; min-width: 42px; }
.family-table th.fam-month:hover { color: var(--color-text); }
.family-table td.fam-cell { font-weight: 700; }
.family-table td.fam-cell:hover { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.family-table .is-selected-month { box-shadow: inset 0 0 0 2px var(--color-primary); }
.family-table thead th.is-selected-month { color: var(--color-primary-text); background: var(--color-primary-soft); }
.family-table .fam-total { font-weight: 700; }
.family-table .fam-owed { color: var(--color-danger); font-weight: 800; }
.family-table .fam-clear { color: var(--color-success); font-weight: 800; }
.family-table tfoot td { background: var(--color-surface-alt); font-weight: 800; border-top: 2px solid var(--color-border-strong); border-bottom: none; }
.family-pay-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 8px; }
.family-pay-head h4 { margin: 0; font-size: 14px; }
.family-member { grid-template-columns: minmax(0, 1fr) auto auto 76px auto; }
.family-member.is-adding { border-color: var(--color-success); }
.family-member.is-reducing { border-color: var(--color-danger); }
.family-member .member-diff { font-size: 12.5px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.family-member .member-diff.is-adding { color: var(--color-success); }
.family-member .member-diff.is-reducing { color: var(--color-danger); }
.family-member .fp-fill { padding: 4px 8px; font-size: 11px; min-height: 0; }
@media (max-width: 640px) {
    .family-member { grid-template-columns: 1fr auto; }
    .family-member .member-diff { text-align: start; }
}

/* Enrolment month (payment modal + family window) */
.enroll-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 8px 12px;
    margin-bottom: 14px;
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius);
    font-size: 12.5px;
    color: var(--color-text-muted);
}
.enroll-bar strong { color: var(--color-text); }
.enroll-bar > .btn:first-of-type { margin-inline-start: auto; }
.enroll-bar.is-before { border-color: var(--color-warning); background: var(--color-warning-soft); }
.family-table .fam-enrolled { font-size: 10.5px; font-weight: 500; color: var(--color-text-muted); margin-top: 2px; }
.family-member .fp-enroll-row { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 5px; }
.family-member .fp-enroll { padding: 3px 8px; font-size: 11px; min-height: 0; }

/* Template placeholders: click-to-insert chips (templates editor + send page) */
.tpl-vars { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 10px; }
.tpl-vars__title { font-size: 11px; font-weight: 600; color: var(--color-text-muted); }
.tpl-vars__list { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.tpl-vars__group { font-size: 11px; color: var(--color-text-muted); margin-inline-end: 2px; }
.tpl-var {
    direction: ltr;
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    color: var(--color-primary-text);
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.tpl-var:hover { border-color: var(--color-primary); background: var(--color-primary-soft); }

/* A rendered message: one paragraph per language, each in its own direction. */
.tpl-message {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-text);
}
.tpl-message p { margin: 0; white-space: pre-wrap; }
.tpl-message p + p { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--color-border-strong); }
.tpl-preview { margin-top: 6px; }
/* A template's Arabic translation: for staff only, never sent — so it reads
   as a note beside the message, not as part of it. */
.tpl-translation {
    margin-top: 10px;
    padding: 9px 12px;
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius);
    font-size: 12.5px;
}
.tpl-translation__label { display: block; font-size: 11px; font-weight: 700; color: var(--color-text-muted); margin-bottom: 3px; }
.tpl-translation p { margin: 0; white-space: pre-wrap; line-height: 1.7; color: var(--color-text); }
.tpl-preview__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; margin-bottom: 8px; }
.send-unknown { display: block; padding: 8px 12px; margin-top: 8px; white-space: normal; }
.tpl-table .tpl-cell-body {
    font-size: 12px;
    color: var(--color-text-muted);
    max-width: 480px;
    margin-top: 6px;
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.tpl-table .tpl-cell-body.is-ar { margin-top: 4px; }
.tpl-table tr.tpl-section td { text-align: start; padding: 10px 16px; font-weight: 700; background: var(--color-surface-alt); color: var(--color-text-muted); }
/* The students grid never wraps cells; template text must, or the table grows
   wider than its card and spills over the editor beside it. */
.tpl-table tbody td { white-space: normal; }
.tpl-table tbody td:last-child { white-space: nowrap; }

/* Send page: the preview rebuilds itself; it dims while it does. */
.send-preview { transition: opacity 0.15s; }
.send-preview.is-refreshing { opacity: 0.55; }
.send-preview__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.send-preview__head h3 { margin: 0; }
.send-preview__live { font-size: 11.5px; font-weight: 600; color: var(--color-success); }
.send-preview__busy { font-size: 11.5px; color: var(--color-text-muted); }
.send-preview__sample-title { margin: 14px 0 8px; }
.send-preview .sk {
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: skShimmer 1.1s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .send-preview .sk { animation: none; } }

/* Student form (add / edit) */
.student-form-box { width: 720px; max-width: calc(100vw - 32px); }
.student-form-family { display: block; padding: 8px 12px; margin: -4px 0 14px; font-size: 12.5px; white-space: normal; }
.student-form-check { display: inline-flex; align-items: center; gap: 8px; margin: 2px 0 14px; font-size: 13px; cursor: pointer; }

/* ============================================
   Toast notifications
   ============================================ */
.toast-stack {
    position: fixed;
    bottom: 20px;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}
html[dir="rtl"] .toast-stack { transform: translateX(50%); }

.toast {
    background: var(--color-text);
    color: white;
    padding: 11px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    font-weight: 500;
    pointer-events: auto;
    max-width: 460px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.warning { background: var(--color-warning); }
.toast.info { background: var(--color-info); }

/* ============================================
   Status pills
   ============================================ */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.pill-success { background: var(--color-success-soft); color: #065f46; }
.pill-warning { background: var(--color-warning-soft); color: #92400e; }
.pill-danger { background: var(--color-danger-soft); color: #991b1b; }
.pill-info { background: var(--color-info-soft); color: #075985; }
.pill-muted { background: var(--color-surface-alt); color: var(--color-text-muted); }

/* ============================================
   Dropdowns
   ============================================ */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline-end: 0;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    padding: 4px;
    z-index: 30;
}
.dropdown-menu a, .dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--color-text);
    text-decoration: none;
    font-size: 13px;
    text-align: start;
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    font-family: inherit;
    transition: background 0.1s;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--color-surface-alt); }
.dropdown-menu .divider { border-top: 1px solid var(--color-border); margin: 4px 0; }
.dropdown-menu .danger { color: var(--color-danger); }

.icon-btn {
    background: transparent;
    border: none;
    padding: 5px 8px;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.5;
    border-radius: 6px;
    transition: all 0.15s;
}
.icon-btn:hover { opacity: 1; background: var(--color-surface-alt); }

/* ============================================
   Utility
   ============================================ */
.text-muted { color: var(--color-text-muted); }
.text-soft { color: var(--color-text-soft); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.fw-700 { font-weight: 700; }
.fw-600 { font-weight: 600; }
.fs-xs { font-size: 11px; }
.fs-sm { font-size: 12px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 18px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-top: 12px;
    box-shadow: var(--shadow-xs);
}
.pagination-info {
    font-size: 12px;
    color: var(--color-text-muted);
}
.pagination-controls {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--color-surface-alt);
    border-radius: var(--radius);
    padding: 3px;
}
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 9px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.page-btn:hover:not(.disabled):not(.active) {
    background: white;
    color: var(--color-text);
    box-shadow: var(--shadow-xs);
}
.page-btn.active {
    background: var(--color-primary);
    color: white;
    cursor: default;
    box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3);
}
.page-btn.disabled {
    color: var(--color-text-soft);
    cursor: not-allowed;
    opacity: 0.5;
}

/* ============================================
   Tabs (settings page style)
   ============================================ */
.settings-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 8px;
    box-shadow: var(--shadow-xs);
    position: sticky;
    top: 76px;
}
.settings-tabs button {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-align: start;
    width: 100%;
}
.settings-tabs button:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
}
.settings-tabs button.active {
    background: var(--color-primary-soft);
    color: var(--color-primary-text);
    font-weight: 700;
}
.settings-tabs button .icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.script-banner {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-help {
    color: var(--color-text-muted);
    font-size: 11px;
    margin-top: 4px;
    line-height: 1.5;
}

.field-script-default {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    padding: 2px 7px;
    background: var(--color-info-soft);
    color: #075985;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-inline-start: 6px;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-inline-end: 6px;
}
.status-dot.ok { background: var(--color-success); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.2); }
.status-dot.warn { background: var(--color-warning); }
.status-dot.off { background: var(--color-text-soft); }

/* Animation */
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes scaleOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.95); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes spin { to { transform: rotate(360deg); } }

.side-panel { animation: slideInRight 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
html[dir="rtl"] .side-panel { animation: slideInLeft 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
.side-panel-backdrop, .modal-backdrop { animation: fadeIn 0.15s ease-out; will-change: opacity; }
.modal-box { animation: scaleIn 0.18s cubic-bezier(0.16, 1, 0.3, 1); will-change: transform, opacity; }

/* Instant Alpine-driven close (overrides entrance animation) */
.modal-backdrop.modal-closing { animation: fadeOut 0.14s ease-in forwards; }
.modal-backdrop.modal-closing .modal-box { animation: scaleOut 0.14s ease-in forwards; }

/* Side-panel smooth close */
@keyframes slideOutRight { from { transform: translateX(0); } to { transform: translateX(100%); } }
@keyframes slideOutLeft  { from { transform: translateX(0); } to { transform: translateX(-100%); } }
.side-panel.panel-closing { animation: slideOutRight 0.18s cubic-bezier(0.7, 0, 0.84, 0) forwards; }
html[dir="rtl"] .side-panel.panel-closing { animation: slideOutLeft 0.18s cubic-bezier(0.7, 0, 0.84, 0) forwards; }
.side-panel-backdrop.panel-closing { animation: fadeOut 0.18s ease-in forwards; }

/* Spinner used inside buttons that have wire:loading */
.spinner-sm {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: -2px;
    margin-inline-end: 2px;
}

/* Cell click visual feedback while server processes */
.cell-month:active { transform: scale(0.95); transition: transform 0.06s ease-out; }
.cell-month.cell-busy {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background: var(--color-primary-soft) !important;
    animation: pulse 0.9s ease-in-out infinite;
}
.cell-month.cell-busy .amount, .cell-month.cell-busy .method-icon { opacity: 0.2; }

/* Sibling badge "busy" state */
.sibling-badge.badge-busy, .sibling-badge-solo.badge-busy {
    animation: pulse 0.9s ease-in-out infinite;
    transform: scale(0.96);
}

/* Buttons disabled while loading look slightly muted, no jump */
.btn[disabled], .btn:disabled { opacity: 0.6; cursor: progress; }

/* Modal body scroll if too tall */
.modal-body { max-height: calc(85vh - 120px); }

/* RTL adjustments */
html[dir="rtl"] body { font-family: 'Cairo', system-ui, sans-serif; }

/* ============================================
   Responsive — mobile-first refinements
   Breakpoints: 480 (phones), 768 (tablets), 1024 (small laptops)
   ============================================ */

/* Hamburger toggle button — hidden on desktop */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border: 1px solid var(--color-border-strong);
    background: white;
    color: var(--color-text);
    border-radius: var(--radius);
    cursor: pointer;
    margin-inline-end: 6px;
}
.nav-toggle:hover { background: var(--color-surface-alt); }

/* Nav-links wrapper — plain flex on desktop, drawer on mobile */
.nav-links {
    display: contents;
}

/* Prevent x-overflow on any page */
html, body { max-width: 100vw; overflow-x: hidden; }
.main { min-width: 0; }

/* Tablet (<= 1024) — shorten nav labels, drop search width */
@media (max-width: 1024px) {
    .topbar { padding: 0 12px; gap: 3px; }
    .topbar .nav-link { padding: 7px 10px; font-size: 12.5px; }
    .topbar .search-global { width: 200px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet / small laptop (<= 900) — hide labels, show icons only on nav */
@media (max-width: 900px) {
    .topbar .nav-link { padding: 8px 10px; }
    .topbar .nav-link svg { flex-shrink: 0; }
}

/* Phone (<= 768) — hamburger drawer for nav */
@media (max-width: 768px) {
    .topbar {
        padding: 0 10px;
        gap: 4px;
        flex-wrap: wrap;
        height: auto;
        min-height: 56px;
    }
    .topbar .brand { padding: 0 4px; margin-inline-end: 4px; border-inline-end: none; height: 56px; line-height: 56px; }
    .brand-logo { width: 34px; height: 34px; }
    .d-none-mobile { display: none !important; }

    .nav-toggle { display: inline-flex; }

    /* Nav becomes a slide-down drawer */
    .nav-links {
        display: none;
        flex-direction: column;
        gap: 2px;
        flex-basis: 100%;
        order: 10;
        padding: 8px 4px;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        margin: 0 -10px;
    }
    .nav-links.is-open { display: flex; }
    .topbar .nav-link {
        display: flex;
        padding: 12px 14px;
        font-size: 14px;
        border-radius: var(--radius);
    }

    /* Right cluster stays inline on the topbar row */
    .topbar-spacer { flex: 1; min-width: 0; }
    .lang-switcher { margin-inline-start: auto; }

    .main { padding: 12px; }
    .page-header h1 { font-size: 18px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .kpi { padding: 12px; }
    .kpi .value { font-size: 20px; }

    /* Modals — full-screen on phones */
    .modal-backdrop { padding: 0; align-items: stretch; }
    .modal-box {
        width: 100%; max-width: 100%;
        max-height: 100vh; height: 100vh;
        border-radius: 0;
    }
    .modal-header { padding: 12px 14px; }
    .modal-header h3 { font-size: 15px; }
    .modal-body { padding: 14px; }
    .modal-footer { padding: 12px 14px; flex-wrap: wrap; gap: 6px; }
    .modal-footer .btn { flex: 1 1 auto; min-width: 42%; }

    /* Side panel becomes fullscreen slide-in */
    .side-panel { width: 100vw !important; max-width: 100vw !important; }

    /* Toolbars — tighter, better wrapping */
    .actions-bar, .filters-bar { padding: 10px; gap: 6px; }
    .actions-group { flex-wrap: wrap; }
    .actions-group::after { display: none; }
    .filters-bar input.search { min-width: 100%; flex-basis: 100%; }
    .filters-bar select { flex: 1 1 auto; min-width: 45%; }

    /* Bigger tap targets on primary controls */
    .btn { padding: 9px 14px; font-size: 13px; min-height: 40px; }
    .btn-sm { padding: 6px 10px; font-size: 12px; min-height: 34px; }

    /* Settings tabs sidebar collapses above the panel */
    .settings-tabs { display: flex; flex-direction: row; overflow-x: auto; }
    .settings-tabs button { flex: 0 0 auto; }

    /* Reports and dashboards — 1 col */
    .dash-stats, .grid-2, .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
}

/* Small phone (<= 480) — reduce everything a touch more */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .brand-name { display: none; }
    .lang-switcher a { padding: 4px 6px; font-size: 10.5px; }
    .user-menu .user-avatar { width: 28px; height: 28px; font-size: 12px; }
    .page-card { padding: 14px; }
    .students-grid { font-size: 12px; }
    .students-grid tbody td, .students-grid thead th { padding: 6px 4px; }

    /* Grid: reduce sticky-col widths */
    .students-grid th.sticky-col.col-id, .students-grid td.sticky-col.col-id { width: 32px; min-width: 32px; max-width: 32px; }
    .students-grid th.sticky-col.col-name, .students-grid td.sticky-col.col-name { min-width: 90px; inset-inline-start: 68px; /* 36 + 32 */ }
}

/* Print — sensible defaults */
@media print {
    .topbar, .actions-bar, .filters-bar, .bulk-bar, .side-panel, .modal-backdrop, .toast-stack { display: none !important; }
    .main { padding: 0; }
    .grid-wrap { max-height: none; overflow: visible; }
}

/* ============================================
   Brand logo (topbar)
   ============================================ */
.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    background: white;
    padding: 3px;
    box-shadow: 0 1px 3px rgba(15,23,42,0.10), 0 0 0 1px var(--color-border);
}
.brand-name {
    margin-inline-start: 10px;
    color: var(--color-primary-deep);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.2px;
}

/* ============================================
   Auth (login)  — refined
   ============================================ */
.auth-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(70% 60% at 20% 10%, rgba(39, 114, 69, 0.14) 0%, transparent 65%),
        radial-gradient(55% 45% at 80% 90%, rgba(180, 142, 99, 0.18) 0%, transparent 60%),
        linear-gradient(180deg, #fbfaf7 0%, #f1e9d8 100%);
    padding: 24px;
    position: relative;
    overflow: hidden;
}
.auth-body::before {
    content: "";
    position: absolute; inset: 0;
    background-image: var(--noise-img);
    background-size: 180px 180px;
    opacity: 0.35;
    mix-blend-mode: multiply;
    pointer-events: none;
}
.auth-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.auth-orb { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.55; }
.auth-orb-a { width: 320px; height: 320px; top: -80px; left: -80px; background: var(--color-primary); opacity: 0.18; }
.auth-orb-b { width: 280px; height: 280px; bottom: -100px; right: -60px; background: var(--color-accent); opacity: 0.22; }
.auth-orb-c { width: 220px; height: 220px; top: 40%; right: 20%; background: var(--color-primary); opacity: 0.10; }

.auth-shell {
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 1;
}
.auth-card {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: var(--radius-xl);
    padding: 36px 32px 28px;
    box-shadow:
        0 20px 50px -20px rgba(39, 114, 69, 0.30),
        0 8px 16px -8px rgba(15, 23, 42, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(180, 142, 99, 0.30);
    position: relative;
}
.auth-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    padding: 1px;
    background: linear-gradient(135deg, rgba(180, 142, 99, 0.5), transparent 40%, rgba(39, 114, 69, 0.4));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo-img {
    width: 96px; height: 96px;
    object-fit: cover;
    border-radius: 22px;
    background: white;
    padding: 6px;
    box-shadow:
        0 16px 32px -12px rgba(39, 114, 69, 0.30),
        0 0 0 1px rgba(180, 142, 99, 0.35);
}
.auth-title {
    font-size: 22px; margin: 14px 0 4px;
    color: var(--color-primary-deep);
    font-weight: 700;
    letter-spacing: 0.2px;
}
.auth-subtitle { color: var(--color-text-muted); margin: 0; font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-label {
    font-size: 11px; font-weight: 700;
    color: var(--color-primary-deep);
    text-transform: uppercase; letter-spacing: 0.6px;
}
.auth-input-wrap {
    position: relative;
    display: block;
}
.auth-input-icon {
    position: absolute;
    top: 50%;
    inset-inline-start: 12px;
    transform: translateY(-50%);
    color: var(--color-text-soft);
    pointer-events: none;
}
.auth-input {
    width: 100%;
    padding-inline-start: 36px !important;
    padding-inline-end: 12px !important;
    height: 42px;
    font-size: 14px;
    border: 1px solid var(--color-border);
    background: white;
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}
.auth-toggle {
    position: absolute;
    top: 50%;
    inset-inline-end: 8px;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-text-soft);
    display: inline-flex;
}
.auth-toggle:hover { color: var(--color-primary); background: var(--color-primary-soft); }
.auth-remember {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--color-text-muted);
    user-select: none; cursor: pointer;
}
.auth-remember input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}
.auth-error {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid rgba(185, 28, 28, 0.25);
    font-size: 13px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.auth-error svg { flex-shrink: 0; margin-top: 1px; }
.auth-submit {
    width: 100%;
    height: 44px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius);
    background: var(--brand-gradient) !important;
    border: 0 !important;
    color: white !important;
    box-shadow:
        0 8px 16px -6px rgba(39, 114, 69, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.20);
    transition: transform 0.12s, box-shadow 0.15s;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.auth-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px -6px rgba(39, 114, 69, 0.55);
}
.auth-submit:active { transform: translateY(0); }
.auth-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.auth-copy { color: var(--color-text-soft); font-size: 11px; }

/* ============================================
   User menu (topbar dropdown)
   ============================================ */
.user-menu { position: relative; margin-inline-start: 10px; }
.user-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 5px 10px 5px 5px;
    border-radius: 999px;
    color: var(--color-text);
    font-size: 13px;
    transition: background 0.15s, border-color 0.15s;
}
.user-trigger:hover {
    background: var(--color-primary-soft);
    border-color: rgba(39, 114, 69, 0.18);
}
.user-avatar {
    width: 32px; height: 32px;
    background: var(--brand-gradient);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 2px 6px -1px rgba(39, 114, 69, 0.45);
}
.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-end: 0;
    min-width: 240px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 40px -12px rgba(15, 23, 42, 0.18), 0 4px 12px -4px rgba(15, 23, 42, 0.08);
    z-index: 100;
    padding: 6px;
    overflow: hidden;
}
.user-info {
    padding: 14px 14px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--color-primary-soft) 0%, transparent 100%);
    border-radius: var(--radius);
}
.user-name { font-weight: 700; font-size: 14px; color: var(--color-primary-deep); }
.user-email { color: var(--color-text-muted); font-size: 12px; word-break: break-all; }
.user-role {
    display: inline-block;
    background: var(--color-primary);
    color: white;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-top: 6px;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: start;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: var(--color-text);
    text-decoration: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.12s, color 0.12s;
}
.dropdown-item:hover { background: var(--color-primary-soft); color: var(--color-primary-deep); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-soft); }
.logout-form { margin: 0; padding: 0; }
.caret { color: var(--color-text-muted); font-size: 10px; }
[x-cloak] { display: none !important; }

/* ============================================
   Page / common helpers
   ============================================ */
.page { padding: 8px 4px; }
.page-head {
    margin-bottom: 18px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.page-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    color: var(--color-primary-deep);
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.page-title .title-icon {
    width: 34px; height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-radius: 10px;
}
.page-sub { color: var(--color-text-muted); font-size: 13px; margin: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 24px; }
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card h3 {
    margin: 0;
    padding: 14px 18px;
    font-size: 14px;
    font-weight: 700;
    color: var(--color-primary-deep);
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(135deg, var(--color-primary-soft) 0%, transparent 100%);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }
.lbl { display: block; font-size: 11px; font-weight: 700; color: var(--color-primary-deep); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.check-row { display: flex; align-items: center; gap: 8px; align-self: end; }
.form-actions { margin-top: 16px; display: flex; gap: 8px; }
.text-danger { color: var(--color-danger); font-size: 12px; margin-top: 4px; display: block; }
.muted { color: var(--color-text-muted); }
.empty {
    color: var(--color-text-muted);
    text-align: center;
    padding: 40px 24px;
    font-size: 13px;
}
.empty .empty-icon {
    display: block;
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    color: var(--color-text-soft);
    opacity: 0.6;
}

.data-table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
.data-table th, .data-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); text-align: start; font-size: 13px; vertical-align: middle; }
.data-table th { background: var(--color-surface-alt); font-weight: 700; color: var(--color-primary-deep); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.data-table tbody tr:hover { background: var(--color-primary-soft); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.table-wrap { border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.btn-xs { padding: 4px 10px; font-size: 11px; border-radius: 6px; }
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.badge.ok { background: var(--color-success-soft); color: var(--color-success); }
.badge.muted { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge.role-admin { background: var(--color-primary); color: white; }
.badge.role-staff { background: var(--color-accent-soft); color: var(--color-accent-hover); border: 1px solid rgba(180,142,99,0.30); }
.badge.role-viewer { background: var(--color-surface-alt); color: var(--color-text-muted); }
.dot { display:inline-block; width:6px; height:6px; border-radius:50%; background: currentColor; margin-inline-end: 2px; }

/* ============================================
   Dashboard — refined
   ============================================ */
.dash-hero {
    background:
        radial-gradient(80% 100% at 0% 0%, rgba(180, 142, 99, 0.15) 0%, transparent 60%),
        var(--brand-gradient);
    color: white;
    border-radius: var(--radius-lg);
    padding: 18px 22px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    box-shadow: 0 12px 28px -10px rgba(39, 114, 69, 0.4);
    position: relative;
    overflow: hidden;
}
.dash-hero::after {
    content: "";
    position: absolute; inset: 0;
    background-image: var(--noise-img);
    background-size: 180px 180px;
    opacity: 0.25;
    mix-blend-mode: overlay;
    pointer-events: none;
}
.dash-hero h2 { margin: 0 0 4px; font-size: 18px; }
.dash-hero p { margin: 0; opacity: 0.85; font-size: 13px; }
.dash-hero .hero-actions { display: flex; gap: 8px; flex-wrap: wrap; position: relative; z-index: 1; }
.dash-hero .btn { background: rgba(255,255,255,0.18); color: white; border-color: rgba(255,255,255,0.3); }
.dash-hero .btn:hover:not(:disabled) { background: rgba(255,255,255,0.28); border-color: rgba(255,255,255,0.45); }
.dash-hero .btn.btn-primary { background: white; color: var(--color-primary-deep); border-color: white; }
.dash-hero .btn.btn-primary:hover:not(:disabled) { background: var(--color-accent-soft); }

.dash-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 992px) { .dash-stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .dash-stats { grid-template-columns: 1fr; } }
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px -16px rgba(39, 114, 69, 0.25), var(--shadow-md);
    border-color: var(--color-border-strong);
}
.stat-card::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 0; bottom: 0;
    width: 3px;
    background: var(--color-primary);
    opacity: 0.85;
}
.stat-card.indigo::before, .stat-card.green::before { background: var(--color-primary); }
.stat-card.gold::before { background: var(--color-accent); }
.stat-card.danger::before { background: var(--color-danger); }
.stat-card.sky::before { background: var(--color-info); }
.stat-card .stat-label { color: var(--color-text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; margin-top: 8px; line-height: 1.05; color: var(--color-text); }
.stat-card .stat-value small { font-size: 14px; color: var(--color-text-muted); font-weight: 600; margin-inline-start: 4px; }
.stat-card .stat-sub { color: var(--color-text-soft); font-size: 11px; margin-top: 6px; }
.stat-card .stat-icon {
    position: absolute;
    inset-inline-end: 14px;
    top: 16px;
    width: 40px; height: 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.stat-card.indigo .stat-icon, .stat-card.green .stat-icon { background: var(--color-primary-soft); color: var(--color-primary); }
.stat-card.gold .stat-icon { background: var(--color-accent-soft); color: var(--color-accent-hover); }
.stat-card.danger .stat-icon { background: var(--color-danger-soft); color: var(--color-danger); }
.stat-card.sky .stat-icon { background: var(--color-info-soft); color: var(--color-info); }

.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 1180px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.dash-panel-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(135deg, var(--color-primary-soft) 0%, transparent 100%);
    display: flex;
    align-items: center;
    gap: 8px;
}
.dash-panel-head h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-primary-deep);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.dash-panel-body { padding: 16px 18px; }
.dash-bar-row {
    display: grid;
    grid-template-columns: 110px 1fr 80px;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    font-size: 12px;
}
.dash-bar-row + .dash-bar-row { border-top: 1px dashed var(--color-border); }
.dash-bar {
    background: var(--color-surface-alt);
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}
.dash-bar > span {
    display: block;
    height: 100%;
    background: var(--brand-gradient);
    border-radius: 999px;
    transition: width 0.6s ease;
}
.dash-bar.success > span { background: var(--brand-gradient); }
.dash-bar.danger > span { background: linear-gradient(135deg, #d33636 0%, #b91c1c 100%); }
.dash-bar.gold > span { background: var(--gold-gradient); }
.dash-bar-row .dash-bar-amt { font-weight: 600; text-align: end; }

pre.json { background: var(--color-surface-alt); padding: 10px; border-radius: var(--radius-sm); font-size: 11px; max-width: 420px; overflow-x: auto; white-space: pre-wrap; border: 1px solid var(--color-border); }

/* ============================================
   Profile page — refined
   ============================================ */
.profile-page label { display: block; margin-bottom: 14px; }
.profile-page .form-control { transition: border-color 0.15s, box-shadow 0.15s; }
.profile-page .form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* ============================================
   Activity log — refined timeline-ish
   ============================================ */
.activity-cell { font-size: 13px; }
.activity-cell .when { font-weight: 600; color: var(--color-primary-deep); }
.activity-cell .when small { display: block; font-weight: 400; color: var(--color-text-soft); font-size: 11px; margin-top: 2px; }
.activity-actor {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.activity-actor .avatar-mini {
    width: 26px; height: 26px;
    background: var(--brand-gradient);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
}
.activity-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
}
.activity-tag.created { background: var(--color-success-soft); color: var(--color-success); }
.activity-tag.updated { background: var(--color-info-soft); color: var(--color-info); }
.activity-tag.deleted { background: var(--color-danger-soft); color: var(--color-danger); }

/* Form-control unified focus */
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* ============================================
   Grid: lean rows + in-place row patch (v7.3)
   Rows carry no per-cell Livewire/Alpine bindings — see partials/grid-row.
   ============================================ */
/* Phone numbers always read left-to-right — in Arabic the "+" jumped to the end. */
.students-grid td.col-phone { font-family: ui-monospace, monospace; font-size: 11px; color: var(--color-text-muted); direction: ltr; unicode-bidi: isolate; }
.students-grid td.col-balance { font-weight: 700; }
.students-grid td.col-balance.is-owed { color: var(--color-danger); }
.students-grid td.col-balance.is-clear { color: var(--color-success); }
.students-grid tbody tr.row-filtered { display: none; }
/* Always rendered (no per-cell @if → no Livewire morph markers); hidden when empty. */
.cell-content .method-icon:empty { display: none; }

/* Brief confirmation glow on a row that was just updated in place. */
.students-grid tbody tr.row-flash > td { animation: rowFlash 0.9s ease-out; }
/* A just-added student, scrolled into view: a longer glow so the eye finds it. */
.students-grid tbody tr.row-new > td { animation: rowFlash 2.4s ease-in; }
@keyframes rowFlash {
    from { box-shadow: inset 0 0 0 999px rgba(16, 185, 129, 0.25); }
    to   { box-shadow: inset 0 0 0 999px rgba(16, 185, 129, 0); }
}

/* The single shared row-actions menu (viewport-fixed, positioned from JS). */
.dropdown-menu.row-menu { position: fixed; inset: auto; z-index: 150; }

/* Payment modal: instant skeleton while the server fetches the numbers. */
.modal-skeleton .sk {
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: skShimmer 1.1s linear infinite;
}
@keyframes skShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.payment-row-editing td { background: var(--color-primary-soft); }

@media (prefers-reduced-motion: reduce) {
    .students-grid tbody tr.row-flash > td, .students-grid tbody tr.row-new > td, .modal-skeleton .sk { animation: none; }
}

/* Focus mode header: title on one side, add-student + exit on the other. */
.grid-focus-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--color-text-muted);
}
.grid-focus-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Delete window (App\Livewire\DeleteRecord) — the payments stay on record. */
/* Width only above phone size — below 768px every modal is a full-screen sheet. */
@media (min-width: 769px) { .delete-box { width: 580px; max-width: calc(100vw - 32px); } }
.delete-box .modal-header { background: var(--color-danger-soft); }
.delete-box .modal-header h3 { color: var(--color-danger); }
.delete-box .modal-body { display: flex; flex-direction: column; gap: 12px; }
.delete-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 15px; }
.delete-kept {
    display: flex; flex-direction: column; gap: 2px;
    padding: 10px 14px;
    border: 1px solid var(--color-success);
    border-radius: var(--radius);
    background: var(--color-success-soft);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.delete-kept strong { color: var(--color-success); }
.delete-people {
    list-style: none; margin: 0; padding: 0;
    border: 1px solid var(--color-border); border-radius: var(--radius);
    max-height: 260px; overflow-y: auto;
}
.delete-people li {
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px;
    padding: 10px 12px; font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.delete-people li + li { border-top: 1px solid var(--color-border); }
.delete-person { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.delete-last { font-size: 13px; }
.delete-last strong { color: var(--color-text); }
.delete-what { font-size: 13px; color: var(--color-text-muted); }
.delete-what ul { margin: 4px 0 0; padding-inline-start: 20px; }
.delete-what li { margin: 2px 0; }
/* A deleted student in the grid ("Deleted" filter): readable record, nothing clickable. */
.students-grid tbody tr.row-deleted .col-name .row-link { color: var(--color-text-muted); cursor: default; }
.students-grid tbody tr.row-deleted .cell-month,
.students-grid tbody tr.row-deleted [data-act="noop"] { cursor: default; }
.students-grid tbody tr.row-deleted .cell-hint { display: none; }
.modal-footer .student-form-delete { margin-inline-end: auto; }

/* Every row on the page hidden by the search or client filter. */
.grid-filtered-empty {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 28px 16px;
    text-align: center;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
}

/* ============================================
   Topbar: never wrap, never overflow (v7.4)
   Every item used to be allowed to shrink: at <=1440px the school name
   broke onto 3 lines of 60px (spilling out of the 60px bar), menu labels
   wrapped onto two lines and the user menu was pushed off-screen.
   Now nothing wraps; labels collapse to icons by priority as space runs
   out (the full name stays in each link's tooltip).
   ============================================ */
.topbar > *, .topbar .nav-link, .topbar .btn, .user-trigger { flex-shrink: 0; white-space: nowrap; }
.topbar-spacer { flex: 1 1 auto; min-width: 8px; }

.topbar .brand {
    height: 60px;
    line-height: normal;
    gap: 10px;
    padding-inline: 4px 16px;
    text-decoration: none;
}
.brand-logo { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; justify-content: center; }
.brand-name { margin-inline-start: 0; font-size: 14.5px; line-height: 1.2; white-space: nowrap; }
.brand-tagline {
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}
html[dir="rtl"] .brand-tagline { text-transform: none; letter-spacing: 0; font-size: 11px; }

/* 1) Secondary links go icon-only — even when active (it stays highlighted),
      so the bar is the same width on every page. Letting the active one keep
      its label overflowed Settings/Campaigns pages by up to 68px at ~1270px. */
@media (max-width: 1680px) {
    .topbar .nav-link--more { padding-inline: 10px; }
    .topbar .nav-link--more .nav-label { display: none; }
}
/* 2) Every link icon-only except the active one; compact halt button; no user
      name. (Step 1 needs ~1,285px in Dutch, the widest locale, with the theme
      toggle — measured; 1320 keeps a margin.) */
@media (max-width: 1320px) {
    .topbar .nav-link:not(.active) { padding-inline: 10px; }
    .topbar .nav-link:not(.active) .nav-label { display: none; }
    .topbar .halt-label, .topbar .user-name-label { display: none; }
}
/* 3) Logo only. */
@media (max-width: 1024px) {
    .brand-text { display: none; }
}
/* Phone drawer: labels are always shown inside the drawer. */
@media (max-width: 768px) {
    .topbar .nav-link, .topbar .nav-link:not(.active) { padding: 12px 14px; }
    .topbar .nav-link .nav-label, .topbar .nav-link:not(.active) .nav-label { display: inline; }
}

/* Theme toggle (dark / light). Colours come from tokens, so dark.css only
   has to redefine the tokens. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-inline-start: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--color-text); border-color: var(--color-border-strong); }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ============================================
   Send preview: KPI tiles + campaign cost panel (BulkGatePricing)
   ============================================ */
/* Form beside the preview on wide screens; one column below 900px (it used to stay two ~170px columns on a phone). */
.send-page { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; }
@media (max-width: 900px) { .send-page { grid-template-columns: minmax(0, 1fr); } }
.send-preview__kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 14px; }
@media (max-width: 480px) { .send-preview__kpis { grid-template-columns: 1fr; } }

.cost-panel {
    margin-top: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    overflow: hidden;
}
.cost-panel__head {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-alt);
}
.cost-panel__head h4 { margin: 0; font-size: 14px; }
.cost-panel__source { font-size: 12px; color: var(--color-text-muted); }
.cost-panel__refresh { margin-inline-start: auto; }

.cost-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cost-figure {
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px;
    min-width: 0;
    font-variant-numeric: tabular-nums;
}
.cost-figure + .cost-figure { border-inline-start: 1px solid var(--color-border); }
.cost-figure__label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; color: var(--color-text-muted); }
.cost-figure__credits { font-size: 22px; font-weight: 800; line-height: 1.15; color: var(--color-text); }
.cost-figure__credits small { font-size: 12px; font-weight: 600; color: var(--color-text-muted); }
.cost-figure__money { font-size: 13px; font-weight: 600; color: var(--color-text); }
.cost-figure__hint { font-size: 11.5px; color: var(--color-text-muted); }
.cost-figure--balance { background: var(--color-surface-alt); }
@media (max-width: 640px) {
    .cost-figures { grid-template-columns: 1fr; }
    .cost-figure + .cost-figure { border-inline-start: 0; border-top: 1px solid var(--color-border); }
}

.cost-verdict {
    margin: 0;
    padding: 10px 14px;
    font-size: 13px; font-weight: 600; line-height: 1.6;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    font-variant-numeric: tabular-nums;
}
.cost-panel--enough { border-color: var(--color-success); }
.cost-panel--enough .cost-verdict { background: var(--color-success-soft); color: var(--color-success); }
.cost-panel--tight { border-color: var(--color-warning); }
.cost-panel--tight .cost-verdict { background: var(--color-warning-soft); }
.cost-panel--short { border-color: var(--color-danger); }
.cost-panel--short .cost-verdict { background: var(--color-danger-soft); color: var(--color-danger); }

.cost-operators { border-top: 1px solid var(--color-border); }
.cost-operators summary { cursor: pointer; padding: 10px 14px; font-size: 13px; font-weight: 600; }
.cost-operators summary:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.cost-operators__scroll { overflow-x: auto; padding: 0 14px; }
.cost-operators table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.cost-operators th, .cost-operators td { padding: 7px 8px; text-align: start; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.cost-operators thead th { font-size: 11.5px; color: var(--color-text-muted); font-weight: 700; }
.cost-operators tbody th { font-weight: 600; }
.cost-note { margin: 8px 14px 12px; font-size: 12px; line-height: 1.6; color: var(--color-text-muted); }

.cost-panel__foot {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
    padding: 10px 14px;
    border-top: 1px solid var(--color-border);
    font-size: 12px; color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.cost-tier { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; max-width: 100%; min-width: 0; }
/* min-width 0: a flex item never shrinks below its longest option otherwise, and spilled out of the panel on a phone. */
.cost-tier .form-select { width: auto; max-width: 100%; min-width: 0; padding-block: 4px; font-size: 12px; }
.cost-stale { color: var(--color-warning); font-weight: 600; }

/* ============================================
   Navbar: last bank sync date (App\Livewire\BankSyncDate)
   A chip with the date; its popover holds the date picker.
   ============================================ */
.bank-sync { position: relative; margin-inline-start: 8px; }
.bank-sync__chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 34px; padding-inline: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-alt);
    color: var(--color-text);
    font-size: 12.5px; font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.bank-sync__chip:hover { border-color: var(--color-border-strong); }
.bank-sync__chip:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.bank-sync__label { color: var(--color-text-muted); font-weight: 600; }
.bank-sync__chip.is-unset { border-style: dashed; color: var(--color-text-muted); }

.bank-sync__pop {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-end: 0;
    z-index: 110;
    width: 300px;
    max-width: calc(100vw - 24px);
    padding: 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 40px -12px rgba(15, 23, 42, 0.18), 0 4px 12px -4px rgba(15, 23, 42, 0.08);
    white-space: normal;
}
.bank-sync__pop h4 { margin: 0 0 8px; font-size: 14px; }
.bank-sync__pop p { margin: 0 0 6px; font-size: 12.5px; line-height: 1.6; }
.bank-sync__current { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.bank-sync__current strong { font-size: 15px; }
.bank-sync__ago, .bank-sync__meta { color: var(--color-text-muted); }
.bank-sync__hint { color: var(--color-text); }
.bank-sync__form { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--color-border); }
.bank-sync__form label { font-size: 12px; font-weight: 600; color: var(--color-text-muted); }
.bank-sync__row { display: flex; gap: 6px; }
.bank-sync__row .form-input { flex: 1 1 auto; min-width: 0; }
.bank-sync__save { align-self: flex-start; }

/* Same collapse order as the rest of the bar: the word "Bank" goes first. */
@media (max-width: 1440px) { .bank-sync__label { display: none; } }
@media (max-width: 768px) {
    .bank-sync__chip { padding-inline: 8px; }
    .bank-sync__pop { position: fixed; top: 64px; inset-inline: 12px; width: auto; max-width: none; }
}
