/* 93 - Battalion Attendance App. Mobile-first, canopy as the design template
   (see D:\claude_orion\canopy for the reference: css/style-01.css tokens,
   bottom nav pattern, card/form/modal idioms). Ported look and interaction
   idioms, not canopy's code wholesale: 93 is a single small stylesheet (no
   need for canopy's 11-file split), system font stack instead of bundling
   Fira Sans (those font files live only in canopy's own repo), and a status
   pill system canopy has no equivalent of (93's 7 attendance statuses). */

/* ============ 1. RESET & TOKENS ============ */

:root {
    color-scheme: light;
    --color-primary: #254E48;
    --color-primary-light: #48716b;
    --color-primary-dark: #022b25;
    --color-on-primary: #fff;
    --color-bg: #F5F6E7;
    --color-card: #FFFFFF;
    --color-text: #2D2D2D;
    --color-text-light: #6B6B6B;
    --color-bg-subtle: rgba(0, 0, 0, 0.03);
    --color-border: #e1e2d3;
    --color-border-subtle: rgba(0, 0, 0, 0.08);
    --color-success: #1E6B3D;
    --color-success-bg: #e8f7ee;
    --color-error: #C0392B;
    --color-error-bg: #fdecea;
    --color-warning: #b45309;
    --color-warning-bg: #fff8e1;
    --color-shadow: 0 2px 8px rgba(37, 78, 72, 0.1);
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --font-size-heading: 1.2rem;
    --font-size-subheading: 0.85rem;
    --font-size-body: 0.9rem;
    --font-size-label: 0.82rem;
    --font-size-small: 0.74rem;

    --ease-out: cubic-bezier(0.4, 0, 0.2, 1);

    --card-radius: 12px;
    --card-pad: 20px;
    --input-radius: 8px;
    --btn-radius: 8px;

    /* Bottom nav geometry (canopy pattern: row height + gap/home-indicator
       clearance kept additive so box-sizing can't squeeze the buttons). */
    --bottom-nav-row: 56px;
    --bottom-nav-min-clear: 24px;

    /* Attendance status colors - mirrors the JS/SQL enum in
       js/supabase-client.js ATTENDANCE_STATUSES. */
    --status-present: #1E6B3D;
    --status-attach_out: #2563EB;
    --status-sick_in_camp: #D97706;
    --status-sick_outside: #B45309;
    --status-mc: #7C3AED;
    --status-off: #64748B;
    --status-others: #DB2777;
    --status-unmarked: #9CA3AF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--color-bg); scrollbar-gutter: stable; }

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Prevent iOS auto-zoom on input focus (needs font-size >= 16px). */
@media (max-width: 767px) {
    input, select, textarea { font-size: 16px !important; }
}

/* ============ 2. LAYOUT ============ */

.app-container {
    margin: 0 auto;
    padding: 16px;
    width: 100%;
    max-width: 480px;
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Desktop: a wider centered column for data-dense pages (summary/admin/log),
   phone stays the narrow single-column layout above. */
@media (min-width: 900px) {
    .app-container.app-container-wide { max-width: 760px; }
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 16px;
    gap: 12px;
}

.app-header .logo {
    font-size: var(--font-size-heading);
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-header .logo .logo-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--color-primary);
    color: var(--color-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.95rem;
}

.app-header-actions { display: flex; align-items: center; gap: 10px; }

.header-logout-btn {
    background: none;
    border: none;
    color: var(--color-text-light);
    font-size: var(--font-size-label);
    cursor: pointer;
    padding: 6px 4px;
}
.header-logout-btn:hover { color: var(--color-error); }

.page-body { flex: 1; padding-bottom: 24px; }

/* Page cleared for the fixed bottom nav bar. */
body.has-bottom-nav .app-container {
    padding-bottom: calc(var(--bottom-nav-row) + var(--bottom-nav-min-clear) + env(safe-area-inset-bottom, 0px));
}

/* ============ 3. COMPONENTS ============ */

.card {
    background: var(--color-card);
    border-radius: var(--card-radius);
    padding: var(--card-pad);
    margin-bottom: 16px;
    box-shadow: var(--color-shadow);
    border: 1px solid var(--color-border);
}

.card h2 {
    font-size: var(--font-size-heading);
    margin-bottom: 14px;
    color: var(--color-primary-dark);
}

.text-muted { color: var(--color-text-light); }
.mb-16 { margin-bottom: 16px; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: var(--font-size-label);
    font-weight: 600;
    margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--input-radius);
    font-size: var(--font-size-body);
    background: var(--color-card);
    color: var(--color-text);
    transition: border-color 0.2s;
}
.form-group textarea { resize: none; min-height: 72px; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 78, 72, 0.15);
}
.form-group input:disabled, .form-group select:disabled { opacity: 0.5; }
.form-group .hint { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.form-group select {
    padding-right: 36px;
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B6B6B' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.phone-input-group { display: flex; gap: 8px; }
.country-code-prefix {
    display: flex; align-items: center;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--input-radius);
    background: var(--color-bg-subtle);
    font-size: var(--font-size-body);
    color: var(--color-text-light);
}
.phone-input-group input { flex: 1; }

.password-field-wrap { position: relative; }
.password-field-wrap input { padding-right: 44px; }
.pw-toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--color-text-light);
    cursor: pointer; padding: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 24px;
    border: none;
    border-radius: var(--btn-radius);
    font-size: var(--font-size-body);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s var(--ease-out), transform 0.15s var(--ease-out);
    text-decoration: none;
    width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { background: var(--color-primary-light); opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--color-primary); border: 1px solid var(--color-primary); }
.btn-secondary:hover { background: rgba(37, 78, 72, 0.06); }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-small { padding: 9px 14px; font-size: var(--font-size-label); width: auto; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; margin-top: 4px; }
.btn-group .btn { flex: 1; }

.text-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: var(--font-size-body);
    text-align: center;
    display: block;
    margin-top: 14px;
}
.text-link:hover { text-decoration: underline; }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: var(--font-size-body);
    display: none;
}
.alert.show { display: block; }
.alert-error { background: var(--color-error-bg); color: var(--color-error); border: 1px solid #F5C6CB; }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid #b7e3c6; }
.alert-info { background: var(--color-bg-subtle); color: var(--color-text); border: 1px solid var(--color-border); }

.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 3px solid rgba(255,255,255,0.35);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}
.spinner-dark { border-color: rgba(37,78,72,0.2); border-top-color: var(--color-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    padding: 0;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--color-card);
    border-radius: 16px 16px 0 0;
    padding: 22px 20px calc(22px + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
}
@media (min-width: 641px) {
    .modal-overlay { align-items: center; }
    .modal { border-radius: 16px; max-height: 85vh; }
}
.modal h2 { font-size: var(--font-size-heading); margin-bottom: 14px; color: var(--color-primary-dark); }
.modal-close {
    float: right;
    background: none; border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--color-text-light);
    line-height: 1;
}

/* Bottom nav bar - canopy pattern, simplified to a fixed set of tabs (no
   per-user customization needed at 93's scale). */
.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 100%;
    max-width: 760px;
    height: calc(var(--bottom-nav-row) + var(--bottom-nav-min-clear) + env(safe-area-inset-bottom, 0px));
    padding-bottom: calc(var(--bottom-nav-min-clear) + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: stretch;
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
    z-index: 800;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-light);
    text-decoration: none;
    font-size: var(--font-size-small);
    transition: color 0.15s var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item .nav-icon { font-size: 20px; line-height: 1; }
.bottom-nav-item.active { color: var(--color-primary); font-weight: 700; }

/* ============ 4. STATUS PILLS ============ */

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: var(--font-size-small);
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}
.status-pill.status-unmarked {
    background: transparent;
    color: var(--status-unmarked);
    border: 1.5px dashed var(--status-unmarked);
}
.status-pill.status-present { background: var(--status-present); }
.status-pill.status-attach_out { background: var(--status-attach_out); }
.status-pill.status-sick_in_camp { background: var(--status-sick_in_camp); }
.status-pill.status-sick_outside { background: var(--status-sick_outside); }
.status-pill.status-mc { background: var(--status-mc); }
.status-pill.status-off { background: var(--status-off); }
.status-pill.status-others { background: var(--status-others); }

/* ============ 5. FEATURES ============ */

/* --- Check-in page --- */

.checkin-date {
    font-size: var(--font-size-subheading);
    color: var(--color-text-light);
    margin-bottom: 2px;
}

.checkin-toolbar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; }
.checkin-toolbar .form-group { flex: 1; margin-bottom: 0; }

.soldier-list { display: flex; flex-direction: column; gap: 8px; }
.soldier-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s var(--ease-out), background-color 0.15s var(--ease-out);
}
.soldier-row:active { background: var(--color-bg-subtle); }
.soldier-row.is-unmarked { border-style: dashed; }
.soldier-info { display: flex; flex-direction: column; min-width: 0; }
.soldier-name { font-weight: 600; font-size: var(--font-size-body); }
.soldier-rank { font-size: var(--font-size-small); color: var(--color-text-light); }
.soldier-reason { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-picker-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.status-picker-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 13px 14px;
    border-radius: 10px;
    border: 1.5px solid var(--color-border);
    background: var(--color-card);
    font-size: var(--font-size-body);
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    color: var(--color-text);
}
.status-picker-btn .status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.status-picker-btn.selected { border-color: var(--color-primary); background: rgba(37,78,72,0.06); }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--bottom-nav-row) + var(--bottom-nav-min-clear) + 12px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(12px);
    background: var(--color-primary-dark);
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: var(--font-size-body);
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
    max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-undo { background: none; border: none; color: #DEC5D8; font-weight: 700; cursor: pointer; font-size: var(--font-size-body); white-space: nowrap; }

/* --- Summary page --- */

.summary-date-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.summary-date-row .form-group { flex: 1; margin-bottom: 0; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 4px;
}
@media (min-width: 480px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-tile {
    background: var(--color-bg-subtle);
    border-radius: 10px;
    padding: 10px 8px;
    text-align: center;
}
.stat-tile .stat-value { font-size: 1.1rem; font-weight: 800; color: var(--color-primary-dark); }
.stat-tile .stat-label { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 2px; }

.section-summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    background: var(--color-card);
}
.section-summary-row:active { background: var(--color-bg-subtle); }
.section-summary-name { font-weight: 700; font-size: var(--font-size-body); }
.section-summary-counts { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 2px; }
.section-summary-chevron { color: var(--color-text-light); font-size: 1.1rem; }

/* --- Audit log page --- */

.log-filters { display: flex; gap: 8px; margin-bottom: 14px; }
.log-filters .form-group { flex: 1; margin-bottom: 0; }

.log-entry {
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--color-card);
}
.log-entry-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.log-entry-soldier { font-weight: 700; font-size: var(--font-size-body); }
.log-entry-time { font-size: var(--font-size-small); color: var(--color-text-light); white-space: nowrap; }
.log-entry-change { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--font-size-label); }
.log-entry-arrow { color: var(--color-text-light); }
.log-entry-reason { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 6px; font-style: italic; }
.log-entry-by { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 4px; }

/* --- Admin page --- */

.admin-tabs { display: flex; gap: 6px; margin-bottom: 16px; background: var(--color-bg-subtle); padding: 4px; border-radius: 10px; }
.admin-tab-btn {
    flex: 1;
    padding: 9px 6px;
    border: none;
    background: none;
    border-radius: 8px;
    font-size: var(--font-size-label);
    font-weight: 600;
    color: var(--color-text-light);
    cursor: pointer;
}
.admin-tab-btn.active { background: var(--color-card); color: var(--color-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.admin-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--color-card);
}
.admin-list-row.inactive { opacity: 0.55; }
.admin-list-main { min-width: 0; }
.admin-list-title { font-weight: 700; font-size: var(--font-size-body); }
.admin-list-sub { font-size: var(--font-size-small); color: var(--color-text-light); margin-top: 2px; }
.admin-list-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Account rows can carry up to three action buttons (Edit, Change role,
   Reset password); stack the actions in their own full-width wrapping row
   below the name/badge block instead of squeezing both into one row (which
   overlapped text at mobile widths once a third button was added). */
.admin-account-row { flex-direction: column; align-items: stretch; gap: 10px; }
.admin-account-row .admin-list-actions { flex-wrap: wrap; }
.admin-account-row .admin-list-actions .btn { flex: 1; min-width: 84px; }

.role-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: var(--font-size-small);
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
}

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--color-text-light);
    font-size: var(--font-size-body);
}

.brand-footer {
    text-align: center;
    padding: 16px 0 8px;
    font-size: var(--font-size-small);
    color: var(--color-text-light);
}
