/**
 * OLAMI Attendance Matrix — Premium Styles
 * Replaces the old .om-matrix-* block from admin-common.css
 * Uses design tokens exclusively — no hardcoded hex values.
 */

/* ── Entrance animation ─────────────────────────────────── */
@keyframes omSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Wrap ────────────────────────────────────────────────── */
.om-matrix-wrap {
    font-family: var(--font-sans);
    animation: omSlideUp 0.3s ease-out;
}

/* ── Card — clip overflow so table scroll stays inside rounded corners ── */
.om-matrix-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;          /* clips scroll content to rounded corners */
    margin-bottom: 20px;
}

/* ── Header ──────────────────────────────────────────────── */
.om-matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: 8px;
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-hover) 100%);
}

.om-matrix-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.om-matrix-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.om-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

.om-stat-num {
    font-weight: 600;
    color: var(--text);
    background: var(--surface-active);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
}

.om-stat-male   { color: var(--info); background: var(--info-bg); }
.om-stat-female  { color: #ec4899; background: #fce7f3; }
.om-stat-latino  { color: var(--warning); background: var(--warning-bg); }

/* ── Toolbar (search + export) ───────────────────────────── */
.om-matrix-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface);
    flex-wrap: wrap;
}

.om-search-input {
    flex: 1;
    min-width: 140px;
    max-width: 280px;
    padding: 6px 10px 6px 30px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2386868b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 10px center;
    outline: none;
    transition: border-color 0.2s;
}

.om-search-input:focus {
    border-color: var(--info);
    box-shadow: 0 0 0 3px var(--info-soft);
}

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

.om-csv-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.om-csv-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    color: var(--text);
}

/* ── Table wrapper — scroll stays inside card rounded corners ── */
.om-table-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 70vh;
    position: relative;
}

/* ── Table ────────────────────────────────────────────────── */
.om-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    min-width: 400px;
}

/* ── Sticky thead ─────────────────────────────────────────── */
.om-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 6px 6px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--surface-hover);
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

/* Session header pills */
.om-table th.session {
    text-align: center;
    min-width: 40px;
    padding: 5px 3px;
}

.om-table th.session .om-session-pill {
    display: inline-block;
    background: var(--info-soft);
    color: var(--info);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    font-size: 9px;
    font-weight: 600;
    line-height: 1.3;
}

.om-table th.session .om-session-date {
    display: block;
    font-weight: 400;
    font-size: 8px;
    color: var(--text-muted);
    text-transform: none;
    margin-top: 1px;
}

.om-table th.total-col {
    background: var(--surface-active);
    text-align: center;
    cursor: pointer;
    user-select: none;
    min-width: 52px;
}

.om-table th.total-col:hover {
    color: var(--text);
}

.om-table th.status-col {
    background: var(--surface-active);
    text-align: center;
    min-width: 68px;
}

/* ── Sticky first column (student name) ───────────────────── */
.om-table th:first-child,
.om-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    max-width: 150px;
    width: 150px;
}

.om-table thead th:first-child {
    z-index: 4;
    background: var(--surface-hover);
}

/* ── Table body — compact rows, no heavy borders ──────────── */
.om-table td {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    vertical-align: middle;
    font-size: 12px;
}

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

.om-table tbody tr:hover td {
    background: var(--surface-hover);
}

/* ── Student cell — compact, not greedy ───────────────────── */
.om-student {
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: 150px;
}

.om-student-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.om-gender-tag {
    font-size: 8px;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    font-weight: 600;
    flex-shrink: 0;
}

.om-gender-tag.m       { background: var(--info-bg); color: var(--info-text); }
.om-gender-tag.f       { background: var(--danger-bg); color: var(--danger-text); }
.om-gender-tag.unknown { background: var(--surface-active); color: var(--text-secondary); }

.om-latino-tag {
    font-size: 8px;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    font-weight: 500;
    background: var(--warning-bg);
    color: var(--warning-text);
    flex-shrink: 0;
}

/* ── Attendance icon badges ───────────────────────────────── */
.om-table td.session { text-align: center; }

.om-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--success-bg);
    color: var(--success);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.om-miss {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

.om-future {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--surface-active);
    color: var(--text-muted);
    font-size: 9px;
    line-height: 1;
}

/* ── Total column + progress bar ──────────────────────────── */
.om-table td.total-col {
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    color: var(--text);
    background: var(--surface-hover);
    font-variant-numeric: tabular-nums;
}

.om-total-bar {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--surface-active);
    border-radius: 2px;
    margin-top: 2px;
    overflow: hidden;
}

.om-total-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--success);
    transition: width 0.3s ease;
}

.om-total-fill.at-risk { background: var(--warning); }
.om-total-fill.behind  { background: var(--danger); }

/* ── Status column ────────────────────────────────────────── */
.om-table td.status-col {
    text-align: center;
    background: var(--surface-hover);
}

.om-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 9px;
    font-weight: 600;
    white-space: nowrap;
}

.om-status.eligible { background: var(--success-bg); color: var(--success-text); }
.om-status.at-risk  { background: var(--warning-bg); color: var(--warning-text); }
.om-status.behind   { background: var(--danger-bg); color: var(--danger); }

/* ── Row eligibility tinting (soft left accent, no heavy bg) ─ */
.om-row-eligible td:first-child {
    border-left: 3px solid var(--success);
    background: rgba(52, 199, 89, 0.04);
}
.om-row-eligible:hover td:first-child {
    background: rgba(52, 199, 89, 0.08);
}

.om-row-risk td:first-child {
    border-left: 3px solid var(--warning);
    background: rgba(255, 149, 0, 0.04);
}
.om-row-risk:hover td:first-child {
    background: rgba(255, 149, 0, 0.08);
}

.om-row-behind td:first-child {
    border-left: 3px solid var(--danger);
    background: rgba(255, 59, 48, 0.04);
}
.om-row-behind:hover td:first-child {
    background: rgba(255, 59, 48, 0.08);
}

/* ── Trip cell ────────────────────────────────────────────── */
.om-trip-cell {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── Footer summary row ───────────────────────────────────── */
.om-table tfoot td {
    padding: 6px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-hover);
    border-top: 1px solid var(--border-light);
    text-align: center;
    white-space: nowrap;
}

.om-table tfoot td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface-hover);
}

/* ── Empty state ──────────────────────────────────────────── */
.om-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

/* ── Modal chrome improvements ────────────────────────────── */
#oc-program-matrix-modal .oc-modal {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.om-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-hover) 100%);
    border-bottom: 1px solid var(--border-light);
    z-index: 10;
}

.om-modal-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.om-modal-close {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: none;
    background: var(--surface-active);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.om-modal-close:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ── Eligibility banner ───────────────────────────────────── */
.om-eligibility-banner {
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--info-bg);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--info);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

/* ── Responsive — mobile ──────────────────────────────────── */
@media (max-width: 768px) {
    .om-matrix-header {
        padding: 10px 12px;
        flex-direction: column;
        align-items: flex-start;
    }

    .om-matrix-title { font-size: 13px; gap: 6px; }
    .om-matrix-stats { gap: 5px; }
    .om-stat { font-size: 10px; }
    .om-stat-num { font-size: 10px; padding: 2px 6px; }

    .om-matrix-toolbar {
        padding: 6px 12px;
        flex-direction: column;
        align-items: stretch;
    }

    .om-search-input {
        max-width: 100%;
        font-size: 13px;
        padding: 8px 10px 8px 30px;
    }

    .om-csv-btn {
        align-self: flex-end;
    }

    .om-csv-btn span.om-csv-label { display: none; }

    /* Smaller table content on mobile */
    .om-table thead th {
        padding: 4px 4px;
        font-size: 9px;
    }

    .om-table td {
        padding: 3px 4px;
        font-size: 11px;
    }

    .om-table th:first-child,
    .om-table td:first-child {
        max-width: 110px;
        width: 110px;
    }

    .om-student {
        max-width: 110px;
        gap: 3px;
    }

    .om-student-name { font-size: 11px; }

    .om-table th.session {
        min-width: 32px;
    }

    .om-table th.session .om-session-pill {
        font-size: 8px;
        padding: 1px 3px;
    }

    .om-table th.session .om-session-date {
        font-size: 7px;
    }

    .om-check, .om-miss, .om-future {
        width: 16px;
        height: 16px;
        font-size: 9px;
    }

    .om-status {
        font-size: 8px;
        padding: 2px 6px;
    }

    .om-eligibility-banner {
        font-size: 11px;
        padding: 8px 10px;
        gap: 6px;
    }

    .om-modal-header {
        padding: 12px 14px;
    }

    .om-modal-header h2 {
        font-size: 14px;
    }

    #oc-program-matrix-modal .oc-modal {
        max-width: 100vw !important;
        width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0;
        margin: 0;
    }

    #oc-matrix-content {
        max-height: calc(100vh - 60px) !important;
    }
}

/* ── Small screens — extra compact ────────────────────────── */
@media (max-width: 480px) {
    .om-table th:first-child,
    .om-table td:first-child {
        max-width: 90px;
        width: 90px;
    }

    .om-student {
        max-width: 90px;
    }

    .om-student-name { font-size: 10px; }
    .om-gender-tag { display: none; }
    .om-latino-tag { display: none; }

    .om-table th.session {
        min-width: 28px;
    }

    .om-check, .om-miss, .om-future {
        width: 14px;
        height: 14px;
        font-size: 8px;
    }
}

/* ── Dark mode coverage via design tokens ─────────────────── */
/* All colors use CSS custom properties redefined by design-tokens.css
   under #omm-wrapper[data-theme="dark"]. Override hardcoded values: */
#omm-wrapper[data-theme="dark"] .om-stat-female {
    color: #f472b6;
    background: rgba(236, 72, 153, 0.15);
}

#omm-wrapper[data-theme="dark"] .om-gender-tag.f {
    color: #f472b6;
    background: rgba(236, 72, 153, 0.15);
}

#omm-wrapper[data-theme="dark"] .om-table td {
    border-bottom-color: rgba(255,255,255,0.04);
}

#omm-wrapper[data-theme="dark"] .om-row-eligible td:first-child {
    background: rgba(48, 209, 88, 0.06);
}
#omm-wrapper[data-theme="dark"] .om-row-risk td:first-child {
    background: rgba(255, 214, 10, 0.06);
}
#omm-wrapper[data-theme="dark"] .om-row-behind td:first-child {
    background: rgba(255, 69, 58, 0.06);
}
