/* ============================================================
   Majalis Al-Quran Center - Staff Management System
   Plain white/blue, government-form aesthetic.
   MOBILE FIRST: base styles target phones, media queries scale up.
   Animations capped at 250ms.
   ============================================================ */

:root {
    --blue: #1a4d8f;
    --blue-dark: #123a6b;
    --blue-light: #eaf1fb;
    --white: #ffffff;
    --grey-line: #d7dbe0;
    --grey-bg: #f4f6f8;
    --text: #1c1f24;
    --text-light: #5a6068;
    --green: #1f8a4c;
    --green-bg: #e3f5e9;
    --red: #b3261e;
    --red-bg: #fdeceb;
    --yellow: #a67c00;
    --yellow-bg: #fdf4dd;
    --grey-toggle: #8a8f96;
    --sidebar-width: 230px;
    --radius: 4px;
    --transition: 200ms ease;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
    background: var(--grey-bg);
    color: var(--text);
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--blue); text-decoration: none; }

/* ---------- Layout (mobile base) ---------- */
.app-shell { display: block; min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 264px;
    max-width: 84vw;
    background: var(--white);
    border-right: 1px solid var(--grey-line);
    display: flex;
    flex-direction: column;
    z-index: 120;
    transform: translateX(-100%);
    transition: transform var(--transition);
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(20,30,45,.4);
    z-index: 110;
    display: none;
}
.sidebar-backdrop.show { display: block; }

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--grey-line);
}
.sidebar-brand img { width: 36px; height: 36px; object-fit: contain; }
.sidebar-brand .name { font-weight: 700; font-size: 14px; line-height: 1.25; color: var(--blue-dark); }
.sidebar-brand .sub { font-size: 11px; color: var(--text-light); }

.nav-list { list-style: none; margin: 8px 0; padding: 0; flex: 1; }
.nav-list li a {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 18px;
    color: var(--text);
    font-size: 15px;
    border-left: 3px solid transparent;
    transition: background var(--transition), border-color var(--transition);
}
.nav-list li a .ic { width: 20px; height: 20px; flex: 0 0 20px; color: var(--text-light); }
.nav-list li a:hover { background: var(--blue-light); }
.nav-list li a.active {
    background: var(--blue-light);
    border-left-color: var(--blue);
    color: var(--blue-dark);
    font-weight: 600;
}
.nav-list li a.active .ic { color: var(--blue); }

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--grey-line);
    font-size: 11px;
    color: var(--text-light);
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--grey-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    position: sticky;
    top: 0;
    z-index: 90;
    min-height: 56px;
}
.topbar .page-title { font-size: 16px; font-weight: 700; color: var(--blue-dark); }
.topbar .date-display { font-size: 12px; color: var(--text-light); text-align: right; }
.topbar .menu-toggle {
    background: var(--white);
    border: 1px solid var(--grey-line);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 16px;
    cursor: pointer;
    color: var(--blue-dark);
    min-height: 40px;
}

.content { padding: 14px; flex: 1; }

/* ---------- Summary cards ---------- */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}
.summary-card {
    background: var(--white);
    border: 1px solid var(--grey-line);
    border-left: 4px solid var(--blue);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.summary-card .label {
    font-size: 11px; color: var(--text-light);
    text-transform: uppercase; letter-spacing: .03em;
    line-height: 1.3;
}
.summary-card .value {
    font-size: 26px; font-weight: 700; color: var(--blue-dark);
    margin-top: 4px; line-height: 1.1;
}
.summary-card.wide { grid-column: 1 / -1; }
.summary-card.clickable { cursor: pointer; transition: background var(--transition); }
.summary-card.clickable:hover { background: var(--blue-light); }
.summary-card.clickable .label::after {
    content: '';
    display: inline-block;
    width: 5px; height: 5px;
    margin-left: 7px;
    vertical-align: 1px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    opacity: .5;
}
.summary-card.accent-green { border-left-color: var(--green); }
.summary-card.accent-red   { border-left-color: var(--red); }
.summary-card.accent-yellow{ border-left-color: var(--yellow); }

/* Group breakdown inside the Total Macalimin card */
.group-breakdown {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-top: 10px; padding-top: 10px;
    border-top: 1px solid var(--grey-line);
}
.group-breakdown span {
    font-size: 12px; color: var(--text-light);
    background: var(--grey-bg);
    padding: 3px 9px; border-radius: 10px;
    white-space: nowrap;
}
.group-breakdown span b { color: var(--blue-dark); font-size: 13px; }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex; flex-direction: column; gap: 10px;
    margin-bottom: 14px;
}
.search-box {
    display: flex; align-items: center;
    background: var(--white);
    border: 1px solid var(--grey-line);
    border-radius: var(--radius);
    padding: 10px 12px;
    min-height: 44px;
}
.search-box .ic { color: var(--text-light); margin-right: 8px; width: 18px; height: 18px; flex: 0 0 18px; }
.search-box input {
    border: none; outline: none; flex: 1;
    font-size: 16px; /* 16px stops iOS zooming on focus */
    background: transparent; min-width: 0;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px;
    border: 1px solid var(--blue);
    background: var(--blue);
    color: var(--white);
    padding: 11px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    cursor: pointer;
    min-height: 44px;
    transition: background var(--transition), transform 100ms ease;
    font-family: inherit;
}
.btn:hover { background: var(--blue-dark); }
.btn:active { transform: scale(.97); }
.btn.btn-outline { background: var(--white); color: var(--blue); }
.btn.btn-outline:hover { background: var(--blue-light); }
.btn.btn-danger { background: var(--red); border-color: var(--red); }
.btn.btn-danger:hover { background: #8f1e18; }
.btn.btn-full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tabs (group + session), horizontally scrollable ---------- */
.tab-row {
    display: flex; gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.tab-row::-webkit-scrollbar { height: 4px; }
.tab-row::-webkit-scrollbar-thumb { background: var(--grey-line); border-radius: 2px; }

.tab-btn {
    flex: 0 0 auto;
    padding: 10px 16px;
    border: 1px solid var(--grey-line);
    border-radius: var(--radius);
    background: var(--white);
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    min-height: 42px;
    font-family: inherit;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tab-btn.active { background: var(--blue); color: var(--white); border-color: var(--blue); }
.tab-btn small { display: block; font-size: 10px; opacity: .75; font-weight: 400; }

.tab-row.filter-row .tab-btn { padding: 8px 14px; min-height: 38px; font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--white);
    border: 1px solid var(--grey-line);
    border-radius: var(--radius);
    overflow-x: auto;
    animation: fadeIn 220ms ease;
    margin-bottom: 18px;
}
table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--grey-line);
    font-size: 14px;
    color: var(--text);
    vertical-align: middle;
}
table.data-table th {
    background: var(--grey-bg);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-light);
    white-space: nowrap;
}
table.data-table tbody tr { transition: background var(--transition); }
table.data-table tbody tr.row-clickable { cursor: pointer; }
table.data-table tbody tr:hover { background: var(--blue-light); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.empty-cell { text-align: center; color: var(--text-light); padding: 26px 14px; }

/* MOBILE: turn each row into a stacked card instead of scrolling sideways */
@media (max-width: 700px) {
    table.stacked, table.stacked thead, table.stacked tbody,
    table.stacked th, table.stacked td, table.stacked tr { display: block; }
    table.stacked thead { position: absolute; left: -9999px; }
    table.stacked tr {
        border-bottom: 1px solid var(--grey-line);
        padding: 10px 12px;
    }
    table.stacked tr:last-child { border-bottom: none; }
    table.stacked td {
        border: none;
        padding: 5px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        font-size: 14px;
    }
    table.stacked td::before {
        content: attr(data-label);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--text-light);
        flex: 0 0 auto;
    }
    table.stacked td.cell-name {
        font-weight: 700;
        color: var(--blue-dark);
        font-size: 16px;
        padding-bottom: 8px;
    }
    table.stacked td.cell-attendance { display: block; }
    table.stacked td.cell-attendance::before { display: block; margin-bottom: 8px; }
    .table-wrap { overflow-x: visible; }
}

/* ---------- Status pills ---------- */
.status-pill {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition), color var(--transition);
}
.status-pill.active { background: var(--green-bg); color: var(--green); }
.status-pill.inactive { background: #eceef0; color: var(--grey-toggle); }
.status-pill.readonly { cursor: default; }

.group-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    background: var(--blue-light);
    color: var(--blue-dark);
    white-space: nowrap;
}

.paid-pill, .unpaid-pill {
    display: inline-block;
    padding: 5px 12px; border-radius: 12px;
    font-size: 12px; font-weight: 600;
    cursor: pointer; user-select: none;
}
.paid-pill { background: var(--green-bg); color: var(--green); }
.unpaid-pill { background: var(--red-bg); color: var(--red); }

/* ---------- Attendance toggles (thumb sized on mobile) ---------- */
.att-toggle-group { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; }
.att-btn {
    border: 1px solid var(--grey-line);
    background: var(--white);
    color: var(--text-light);
    padding: 12px 8px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    min-height: 46px;
    font-family: inherit;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.att-btn[data-state="present"].is-active { background: var(--green); border-color: var(--green); color: var(--white); }
.att-btn[data-state="absent"].is-active  { background: var(--red);   border-color: var(--red);   color: var(--white); }
.att-btn[data-state="leave"].is-active   { background: var(--yellow); border-color: var(--yellow);color: var(--white); }
.att-btn[data-state="none"].is-active    { background: var(--grey-toggle); border-color: var(--grey-toggle); color: var(--white); }

@media (min-width: 701px) {
    .att-toggle-group { display: flex; gap: 6px; flex-wrap: wrap; }
    .att-btn { padding: 8px 14px; min-height: 40px; font-size: 13px; }
}

/* ---------- Section titles ---------- */
.section-title {
    font-size: 15px; font-weight: 700; color: var(--blue-dark);
    margin: 20px 0 10px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
}
.section-title .btn { font-size: 13px; padding: 8px 14px; min-height: 40px; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(20,30,45,.45);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 200ms ease;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--white);
    border-radius: 10px 10px 0 0;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    padding: 22px 18px 26px;
    position: relative;
    animation: modalUp 200ms ease;
    -webkit-overflow-scrolling: touch;
}
@keyframes modalUp { from { transform: translateY(18px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes modalScale { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 701px) {
    .modal-overlay { align-items: center; }
    .modal-box {
        max-width: 460px;
        border-radius: var(--radius);
        border: 1px solid var(--grey-line);
        padding: 24px;
        max-height: 88vh;
        animation: modalScale 200ms ease;
    }
}

.modal-close {
    position: absolute; top: 12px; right: 12px;
    background: none; border: none; font-size: 20px; cursor: pointer;
    color: var(--text-light);
    width: 40px; height: 40px; border-radius: 50%;
    transition: background var(--transition), transform 200ms ease;
}
.modal-close:hover { background: var(--grey-bg); transform: rotate(90deg); }

.modal-box h3 { margin: 0 40px 16px 0; color: var(--blue-dark); font-size: 18px; }
.modal-field { margin-bottom: 14px; }
.modal-field label {
    display: block; font-size: 11px; color: var(--text-light);
    margin-bottom: 4px; text-transform: uppercase; letter-spacing: .03em;
}
.modal-field .val { font-size: 15px; }
.modal-field input, .modal-field select {
    width: 100%; padding: 12px 12px;
    border: 1px solid var(--grey-line); border-radius: var(--radius);
    font-size: 16px; font-family: inherit;
    background: var(--white); color: var(--text);
    min-height: 46px;
}
.modal-stats {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 10px; margin: 16px 0;
}
.modal-stats .stat-box {
    background: var(--grey-bg); border-radius: var(--radius);
    padding: 12px 8px; text-align: center;
}
.modal-stats .stat-box .num { font-size: 20px; font-weight: 700; color: var(--blue-dark); }
.modal-stats .stat-box .lbl { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 130px; }

/* Name list inside the clickable dashboard cards */
.name-list { list-style: none; margin: 0; padding: 0; }
.name-list li {
    padding: 12px 4px;
    border-bottom: 1px solid var(--grey-line);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.name-list li:last-child { border-bottom: none; }
.name-list .nm { font-weight: 600; }
.name-list .ph { font-size: 13px; color: var(--text-light); }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 14px; right: 14px; bottom: 16px;
    background: var(--blue-dark);
    color: var(--white);
    padding: 14px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 300;
    text-align: center;
    animation: fadeIn 200ms ease;
}
.toast.error { background: var(--red); }
@media (min-width: 701px) {
    .toast { left: auto; right: 20px; bottom: 20px; max-width: 340px; text-align: left; }
}

/* ---------- Forms ---------- */
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-field label { font-size: 12px; color: var(--text-light); }
.form-field input {
    padding: 12px; border: 1px solid var(--grey-line);
    border-radius: var(--radius); font-size: 16px;
    font-family: inherit; min-height: 46px;
}
input:focus, select:focus, .btn:focus, .tab-btn:focus,
.att-btn:focus, .status-pill:focus, .summary-card.clickable:focus {
    outline: 2px solid var(--blue); outline-offset: 1px;
}

.checkbox-row {
    display: flex; align-items: center; gap: 10px;
    margin: 14px 0 4px; font-size: 14px; cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--blue); }

.live-dot {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--green); margin-right: 6px; vertical-align: middle;
}

/* ---------- Desktop layout ---------- */
@media (min-width: 901px) {
    .app-shell { display: flex; }
    .sidebar { transform: none; width: var(--sidebar-width); max-width: none; }
    .sidebar-backdrop { display: none !important; }
    .main { margin-left: var(--sidebar-width); flex: 1; }
    .topbar { padding: 0 22px; min-height: 60px; }
    .topbar .page-title { font-size: 17px; }
    .topbar .date-display { font-size: 13px; }
    .topbar .menu-toggle { display: none; }
    .content { padding: 22px; }
    .summary-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
    .summary-card.wide { grid-column: auto; }
    .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
    .search-box { flex: 1; max-width: 340px; }
    table.data-table { min-width: 560px; }
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .toolbar, .tab-row, .btn, .no-print { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; }
    .table-wrap { border: none; }
}


/* ---------- Inline SVG icons ---------- */
.ic {
    width: 16px; height: 16px;
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: -3px;
}
.btn .ic { width: 16px; height: 16px; }
.menu-toggle .ic { width: 20px; height: 20px; vertical-align: -4px; }
.modal-close .ic { width: 18px; height: 18px; vertical-align: -3px; }
