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

:root {
    --c-primary:    #1a5276;
    --c-primary-dk: #154360;
    --c-accent:     #2980b9;
    --c-success:    #27ae60;
    --c-warning:    #e67e22;
    --c-error:      #e74c3c;
    --c-muted:      #7f8c8d;
    --c-bg:         #f4f6f9;
    --c-surface:    #ffffff;
    --c-border:     #dde1e7;
    --c-text:       #2c3e50;
    --c-text-light: #5d6d7e;
    --radius:       8px;
    --shadow:       0 1px 4px rgba(0,0,0,.10);
    --sidebar-w:    240px;
}

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent iOS from zooming in on input focus (requires font-size >= 16px) */
input, select, textarea {
    font-size: 16px !important;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth page (login) ────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-box {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
}

.auth-box h1 {
    font-size: 1.1rem;
    color: var(--c-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.auth-box h2 {
    font-size: 1.5rem;
    margin-bottom: 28px;
}

/* ── Admin layout ─────────────────────────────────────────── */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--c-primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.15);
}

.brand-name { display: block; font-weight: 700; font-size: 1rem; }
.brand-sub  { display: block; font-size: .75rem; opacity: .7; margin-top: 2px; }

.nav-links { list-style: none; padding: 12px 0; flex: 1; }

.nav-links li a {
    display: block;
    padding: 10px 20px;
    color: rgba(255,255,255,.85);
    font-size: .9rem;
    transition: background .15s;
}

.nav-links li a:hover,
.nav-links li.active a {
    background: rgba(255,255,255,.15);
    color: #fff;
    text-decoration: none;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.15);
    font-size: .8rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer a { color: rgba(255,255,255,.7); }
.sidebar-footer a:hover { color: #fff; }

/* Main content */
.admin-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title { font-size: 1.1rem; font-weight: 600; }

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--c-text);
    padding: 4px;
}

.main-area { padding: 24px; max-width: 1100px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--c-border);
}

/* ── Stats grid ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

.stat-card--alert { border-top: 3px solid var(--c-error); }

.stat-value { font-size: 2rem; font-weight: 700; color: var(--c-primary); }
.stat-label { font-size: .8rem; color: var(--c-muted); margin-top: 4px; }
.stat-action { display: inline-block; margin-top: 8px; font-size: .8rem; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--c-bg);
    border-bottom: 2px solid var(--c-border);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--c-text-light);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8f9fb; }

.data-table td.actions { white-space: nowrap; display: flex; gap: 6px; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-success { background: #d5f5e3; color: #1e8449; }
.badge-warning { background: #fef9e7; color: #b7770d; }
.badge-error   { background: #fdecea; color: #c0392b; }
.badge-muted   { background: #ecf0f1; color: var(--c-muted); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--c-text-light);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px rgba(41,128,185,.15);
}

.form-group small { display: block; margin-top: 4px; font-size: .8rem; color: var(--c-muted); }

.req { color: var(--c-error); }

.form-row { display: flex; gap: 16px; }
.form-row.two-col   > .form-group { flex: 1; }
.form-row.three-col > .form-group { flex: 1; }
.form-group--action { display: flex; align-items: flex-end; }

.form-actions { margin-top: 24px; display: flex; gap: 12px; }

.inline-form { display: contents; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    min-height: 44px; /* WCAG touch target */
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, opacity .15s;
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

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

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

.btn-secondary { background: var(--c-bg); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: #e8ecf0; }

.btn-outline { background: transparent; color: var(--c-accent); border-color: var(--c-accent); }
.btn-outline:hover { background: rgba(41,128,185,.08); }

.btn-full { width: 100%; }
.btn-sm   { padding: 5px 10px; font-size: .82rem; }
.btn-xs   { padding: 3px 8px;  font-size: .75rem; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: .9rem;
}

.alert-success { background: #d5f5e3; color: #1e8449; }
.alert-error   { background: #fdecea; color: #c0392b; }
.alert-warning { background: #fef9e7; color: #b7770d; }

/* ── Modals ───────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }

.modal-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.45);
}

.modal-box {
    position: relative;
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    padding: 28px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-box h2 { margin-bottom: 20px; font-size: 1.15rem; }

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--c-border);
}

/* ── Misc ─────────────────────────────────────────────────── */
.toolbar { margin-bottom: 20px; }
.muted   { color: var(--c-muted); font-size: .8rem; display: block; }
.empty-state { color: var(--c-muted); font-style: italic; padding: 12px 0; }
.page-intro { color: var(--c-text-light); font-size: .9rem; margin-bottom: 20px; }

/* Dropdown option list */
.option-list { list-style: none; }
.option-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--c-border);
    font-size: .9rem;
}
.option-list li:last-child { border-bottom: none; }
.option-inactive > span { color: var(--c-muted); text-decoration: line-through; }

/* ── Member (PWA) app ─────────────────────────────────────── */
/* ── Offline banner ───────────────────────────────────────── */
.offline-banner {
    background: #e67e22;
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    font-size: .88rem;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 300;
}

/* ── Member PWA shell ─────────────────────────────────────── */
.app-shell {
    min-height: 100vh;
    min-height: 100dvh; /* dynamic viewport height (iOS Safari) */
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    background: var(--c-bg);
}

.app-header {
    background: var(--c-primary);
    color: #fff;
    padding: 16px 20px;
    padding-top: calc(16px + env(safe-area-inset-top));
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: .01em;
    flex-shrink: 0;
}

.app-body {
    flex: 1;
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
}

.screen { display: none; flex-direction: column; flex: 1; }
.screen.active { display: flex; }

.screen-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
    margin-bottom: 16px;
}

.screen-card h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    color: var(--c-primary);
}

.screen-intro {
    color: var(--c-text-light);
    font-size: .9rem;
    margin-bottom: 20px;
    margin-top: -10px;
}

.welcome-msg {
    font-size: 1.05rem;
    margin-bottom: 24px;
    color: var(--c-text-light);
}

.welcome-msg strong { color: var(--c-text); }

.btn-signout {
    margin-top: auto;
    color: var(--c-muted);
    border-color: var(--c-border);
}

.coming-soon {
    text-align: center;
    color: var(--c-muted);
    font-style: italic;
    padding: 32px 0;
}

/* Password input with show/hide toggle */
.input-with-toggle {
    position: relative;
    display: flex;
}

.input-with-toggle input {
    padding-right: 44px;
}

.pw-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--c-muted);
    padding: 4px;
    line-height: 1;
}

/* Loading spinner */
#screen-loading {
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* ── Home: open session ───────────────────────────────────── */
.session-info {
    background: var(--c-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 20px;
}

.session-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 5px 0;
    border-bottom: 1px solid var(--c-border);
    font-size: .9rem;
    gap: 12px;
}

.session-row:last-child { border-bottom: none; }
.session-label { color: var(--c-muted); flex-shrink: 0; }
.session-value { font-weight: 500; text-align: right; }

/* ── Reason list ──────────────────────────────────────────── */
.reason-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.reason-btn {
    width: 100%;
    padding: 14px 16px;
    min-height: 52px;
    text-align: left;
    background: var(--c-bg);
    border: 2px solid var(--c-border);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    color: var(--c-text);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    -webkit-tap-highlight-color: transparent;
}

.reason-btn:hover    { border-color: var(--c-accent); background: #eaf4fb; }
.reason-btn.selected { border-color: var(--c-primary); background: #eaf4fb; font-weight: 600; }

/* ── Location check ───────────────────────────────────────── */
.center-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    gap: 16px;
}

.loading-label { color: var(--c-text-light); font-size: .95rem; }

/* ── Signature ────────────────────────────────────────────── */
.signature-wrap {
    position: relative;
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    background: #fff;
    margin-bottom: 16px;
    touch-action: none;
}

#signature-canvas {
    display: block;
    width: 100%;
    height: 200px;
    cursor: crosshair;
    touch-action: none;
    border-radius: calc(var(--radius) - 2px);
}

.sig-clear-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,.85);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: .78rem;
    cursor: pointer;
    color: var(--c-text-light);
}

.sig-clear-btn:hover { background: #fff; color: var(--c-error); border-color: var(--c-error); }

/* ── Confirmation ─────────────────────────────────────────── */
.confirm-icon {
    width: 64px;
    height: 64px;
    background: var(--c-success);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 16px;
}

.confirm-details {
    width: 100%;
    margin: 16px 0 24px;
}

.confirm-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--c-border);
    font-size: .9rem;
    gap: 12px;
}

.confirm-row:last-child { border-bottom: none; }
.confirm-row span:first-child { color: var(--c-muted); flex-shrink: 0; }
.confirm-row span:last-child  { font-weight: 500; text-align: right; }

/* ── Logs page ────────────────────────────────────────────── */
.filter-bar {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 20px;
}

.filter-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

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

.filter-fields .form-group label {
    font-size: .78rem;
    margin-bottom: 4px;
}

.form-group--check {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
    min-width: auto !important;
    flex: 0 !important;
    white-space: nowrap;
}

.form-group--check label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .88rem !important;
    color: var(--c-text) !important;
    cursor: pointer;
    margin-bottom: 0 !important;
}

.filter-actions { display: flex; gap: 8px; }

.toolbar--spread {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-btns { display: flex; gap: 8px; }

.result-count {
    font-size: .88rem;
    color: var(--c-text-light);
}

.logs-table .actions { display: flex; gap: 6px; align-items: center; }
.nowrap { white-space: nowrap; }
.badges-cell { display: flex; gap: 4px; flex-wrap: wrap; }

.row-flagged td { background: #fff8f7; }
.row-flagged:hover td { background: #ffefed; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--c-border);
}

.page-info { font-size: .88rem; color: var(--c-text-light); }

/* ── Info note (PWA screens) ──────────────────────────────── */
.info-note {
    background: #eaf4fb;
    border-left: 3px solid var(--c-accent);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: .85rem;
    color: var(--c-text-light);
    margin-top: 20px;
    line-height: 1.6;
}

.info-note p            { margin-bottom: 7px; }
.info-note p:last-child { margin-bottom: 0; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s;
    }
    .sidebar.open { transform: translateX(0); }
    .admin-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .form-row { flex-direction: column; gap: 0; }
    .main-area { padding: 16px; }
}
