/* assets/css/style.css
   JCExcellente Christian Academy — QR Attendance System
   Mobile-first, no framework, pure CSS
   ─────────────────────────────────────────────────────── */

/* ── Reset & variables ─────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --green: #16a34a;
    --green-dk: #15803d;
    --green-lt: #dcfce7;
    --amber: #d97706;
    --amber-dk: #b45309;
    --amber-lt: #fef3c7;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
    --danger: #dc2626;
    --danger-lt: #fee2e2;
    --radius: 10px;
    --shadow: 0 1px 4px rgba(0,0,0,.10);
    --shadow-md: 0 4px 16px rgba(0,0,0,.12);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
    font-size: 16px;
    overflow-x: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
}

img {
    max-width: 100%;
    display: block;
}

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

    a:hover {
        text-decoration: underline;
    }

/* ── Layout helpers ────────────────────────────────────── */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
}

.page-wrap {
    padding: 20px 0 40px;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 8px;
}

.gap-4 {
    gap: 16px;
}

.mt-2 {
    margin-top: 8px;
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.text-center {
    text-align: center;
}

.w-full {
    width: 100%;
}

.hidden {
    display: none !important;
}

/* ── Header / Nav ──────────────────────────────────────── */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 16px;
    max-width: 1100px;
    margin: 0 auto;
    gap: 10px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    flex: 1 1 auto;
    min-width: 0;   /* lets this shrink below its content size instead of pushing nav-user off-screen */
    overflow: hidden;
}

    .header-brand img {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: contain;
        flex-shrink: 0;
    }

    .header-brand > div {
        min-width: 0;
    }

    .header-brand .school-name {
        font-size: .78rem;
        font-weight: 700;
        line-height: 1.2;
        color: var(--green);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-brand .sys-name {
        font-size: .65rem;
        color: var(--muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: .85rem;
    flex-shrink: 0;   /* username/logout keep their size; header-brand yields room to them */
}

    .nav-user span {
        color: var(--muted);
        max-width: 140px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
    }

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: var(--radius);
    font-size: .8rem;
    cursor: pointer;
    color: var(--muted);
    transition: background .15s;
}

    .btn-logout:hover {
        background: var(--bg);
        color: var(--text);
    }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

/* ── Summary stat cards ─────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8%;
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}

    .stat-card .stat-value {
        font-size: 2rem;
        font-weight: 700;
        color: var(--green);
        line-height: 1;
    }

    .stat-card .stat-label {
        font-size: .75rem;
        color: var(--muted);
        margin-top: 4px;
    }

    .stat-card.amber .stat-value {
        color: var(--amber);
    }

    .stat-card.danger .stat-value {
        color: var(--danger);
    }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, transform .1s;
    text-decoration: none;
}

    .btn:active {
        transform: scale(.97);
    }

.btn-primary {
    background: var(--green);
    color: #fff;
}

    .btn-primary:hover {
        background: var(--green-dk);
        color: #fff;
        text-decoration: none;
    }

.btn-amber {
    background: var(--amber);
    color: #fff;
}

    .btn-amber:hover {
        background: var(--amber-dk);
        color: #fff;
    }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

    .btn-danger:hover {
        background: #b91c1c;
    }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

    .btn-outline:hover {
        background: var(--bg);
        text-decoration: none;
    }

.btn-sm {
    padding: 5px 12px;
    font-size: .8rem;
}

.btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

/* ── Form controls ─────────────────────────────────────── */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

    .form-control:focus {
        border-color: var(--green);
        box-shadow: 0 0 0 3px rgba(22,163,74,.15);
    }

    .form-control.error {
        border-color: var(--danger);
    }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── Alert / Error messages ────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: .88rem;
    margin-bottom: 12px;
}

.alert-error {
    background: var(--danger-lt);
    color: var(--danger);
    border: 1px solid #fca5a5;
}

.alert-success {
    background: var(--green-lt);
    color: var(--green-dk);
    border: 1px solid #86efac;
}

.alert-warning {
    background: var(--amber-lt);
    color: var(--amber-dk);
    border: 1px solid #fcd34d;
}

/* ── Table ─────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-weight: 700;
    font-size: .78rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

    tbody tr:last-child {
        border-bottom: none;
    }

    tbody tr:hover {
        background: #f9fafb;
    }

tbody td {
    padding: 10px 14px;
    vertical-align: middle;
}

/* ── Badges ────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: .73rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-green {
    background: var(--green-lt);
    color: var(--green-dk);
}

.badge-amber {
    background: var(--amber-lt);
    color: var(--amber-dk);
}

.badge-gray {
    background: #f3f4f6;
    color: var(--muted);
}

.badge-red {
    background: var(--danger-lt);
    color: var(--danger);
}

/* ── Modal ─────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
}

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

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Login page ────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 50%, #f3f4f6 100%);
    padding: 24px 16px;
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
    padding: 32px 28px;
    text-align: center;
}

.login-logo {
    width: 250px;
    height: 250px;
    border-radius: 14px;
    margin: 0 auto 12px;
    object-fit: contain;
}

.login-school {
    font-size: 1rem;
    font-weight: 800;
    color: var(--green);
    line-height: 1.3;
    margin-bottom: 2px;
}

.login-subtitle {
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 24px;
}

.login-form {
    text-align: left;
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: .95rem;
    margin-top: 6px;
}

/* ── Scanner page ──────────────────────────────────────── */
.scanner-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
}

.scanner-header-bar {
    width: 100%;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .scanner-header-bar .school-name {
        font-size: .85rem;
        font-weight: 700;
        color: var(--green);
    }

    .scanner-header-bar .sys-name {
        font-size: .72rem;
        color: var(--muted);
    }

.scanner-wrap {
    position: relative;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
}

#camera-video {
    width: 100%;
    display: block;
    background: #000;
    max-height: 60vh;
    object-fit: cover;
}

.scan-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-box {
    width: 200px;
    height: 200px;
    border: 3px solid rgba(255,255,255,.9);
    border-radius: 14px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
    animation: scan-pulse 2s ease-in-out infinite;
}

@keyframes scan-pulse {
    0%, 100% {
        border-color: rgba(255,255,255,.9);
    }

    50% {
        border-color: var(--green);
        box-shadow: 0 0 0 9999px rgba(0,0,0,.35), 0 0 20px var(--green);
    }
}

.scan-status {
    width: 100%;
    max-width: 520px;
    padding: 12px 16px;
    text-align: center;
    font-size: .85rem;
    color: var(--muted);
}

/* ── Scan result card ──────────────────────────────────── */
.result-card {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 16px;
}

.result-inner {
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.result-header {
    padding: 20px;
    text-align: center;
    color: #fff;
}

    .result-header.time-in {
        background: var(--green);
    }

    .result-header.time-out {
        background: var(--amber);
    }

.result-emoji {
    font-size: 2.5rem;
    line-height: 1;
}

.result-type {
    font-size: 1.1rem;
    font-weight: 700;
    margin-top: 6px;
}

.result-body {
    background: var(--surface);
    padding: 16px 20px;
}

.result-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
}

.result-section {
    font-size: .85rem;
    color: var(--muted);
    margin-top: 2px;
}

.result-time {
    font-size: .95rem;
    font-weight: 600;
    margin-top: 10px;
}

    .result-time.time-in {
        color: var(--green);
    }

    .result-time.time-out {
        color: var(--amber);
    }

/* ── Toolbar ───────────────────────────────────────────── */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}

    .toolbar .search-input {
        flex: 1;
        min-width: 180px;
    }

.page-title {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.page-sub {
    font-size: .82rem;
    color: var(--muted);
    margin-bottom: 20px;
}

/* ── QR print page ─────────────────────────────────────── */
.qr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    padding: 20px;
}

.qr-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow);
}

    .qr-card .qr-img {
        margin: 0 auto 8px;
        width: 192px;
        height: 192px;
    }

    .qr-card .qr-name {
        font-size: .85rem;
        font-weight: 700;
        color: var(--text);
        line-height: 1.3;
    }

@media print {
    body {
        background: #fff;
    }

    .site-header, .print-hide, .btn {
        display: none !important;
    }

    .qr-card {
        break-inside: avoid;
    }

    .qr-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 0;
    }

    .qr-card .qr-img {
        width: 2in;
        height: 2in;
    }

        .qr-card .qr-img img,
        .qr-card .qr-img canvas {
            width: 2in !important;
            height: 2in !important;
        }
}

/* ── Date filter row ───────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
}

    .filter-bar .form-group {
        margin-bottom: 0;
        flex: 1;
        min-width: 140px;
    }

/* ── Loading spinner ───────────────────────────────────── */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Camera error ──────────────────────────────────────── */
.camera-error {
    width: 100%;
    max-width: 520px;
    padding: 32px 20px;
    text-align: center;
    color: var(--muted);
}

    .camera-error .icon {
        font-size: 3rem;
        margin-bottom: 12px;
    }

/* ── Responsive tweaks ─────────────────────────────────── */
@media (max-width: 600px) {
    .modal-footer {
        flex-direction: column;
    }

        .modal-footer .btn {
            width: 100%;
        }

    .filter-bar {
        flex-direction: column;
    }

        .filter-bar .form-group {
            min-width: 100%;
        }
}

@media (max-width: 480px) {
    .header-inner {
        padding: 0 12px;
    }

    .header-brand img {
        width: 30px;
        height: 30px;
    }

    .header-brand .school-name {
        font-size: .72rem;
    }

    .nav-user {
        gap: 8px;
    }

        .nav-user span {
            max-width: 90px;
        }

    .btn-logout {
        padding: 5px 10px;
        font-size: .75rem;
    }

    /* Tighten data tables so more columns fit before scrolling is needed,
       and hint that the rest is a swipe away. */
    thead th {
        padding: 8px 10px;
        font-size: .68rem;
    }

    tbody td {
        padding: 8px 10px;
        font-size: .82rem;
    }

    .table-wrap {
        position: relative;
    }

        .table-wrap::after {
            content: "";
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            width: 18px;
            pointer-events: none;
            background: linear-gradient(to right, transparent, rgba(17,24,39,.06));
        }
}
