:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --text: #1a1f36;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #059669;
    --error: #dc2626;
    --border: #e5e7eb;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --radius: 12px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
}

.navbar-brand small {
    font-weight: 400;
    color: var(--muted);
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    font-size: 1rem;
}

.logo.large {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
}

.navbar-links {
    display: flex;
    gap: 0.25rem;
}

.navbar-links a {
    text-decoration: none;
    color: var(--muted);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.15s;
}

.navbar-links a:hover,
.navbar-links a.active {
    background: #eef2ff;
    color: var(--primary);
}

.navbar-links a.logout {
    color: var(--error);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

.page-header p {
    color: var(--muted);
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    margin-bottom: 1rem;
}

.card-header h2 {
    font-size: 1.1rem;
}

.card-form {
    max-width: 640px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--muted);
    font-size: 0.9rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #f3f4f6;
    color: var(--text);
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.btn-danger {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
}

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

.btn-sm {
    padding: 0.4rem 0.875rem;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

.form h2 {
    font-size: 1rem;
    margin: 1.5rem 0 1rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form h2:first-child {
    margin-top: 0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
}

input, textarea, select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.field-error {
    display: block;
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.field-hint {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.form-actions {
    margin-top: 1.5rem;
}

.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    margin-bottom: 1.5rem;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.status {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-in {
    background: #ecfdf5;
    color: var(--success);
}

.status-visitor {
    background: #fef3c7;
    color: #b45309;
}

.status-member {
    background: #eef2ff;
    color: var(--primary);
}

.status-out {
    background: #f3f4f6;
    color: var(--muted);
}

.badge {
    display: inline-block;
    background: #eef2ff;
    color: var(--primary);
    padding: 0.2rem 0.625rem;
    border-radius: 6px;
    font-family: monospace;
    font-weight: 700;
    font-size: 0.9rem;
}

.pickup-code {
    font-family: monospace;
    font-size: 1.25rem;
    letter-spacing: 0.1em;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 2rem;
}

.auth-card {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem 2rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--muted);
}

.hint {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 1.5rem;
}

.checkin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.checkin-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 1024px) {
    .checkin-grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .checkin-grid,
    .checkin-grid-3 { grid-template-columns: 1fr; }
}

.search-form-page {
    margin-bottom: 1.5rem;
    max-width: 640px;
}

.card-highlight {
    border-color: #c7d2fe;
    background: linear-gradient(180deg, #eef2ff 0%, var(--surface) 100%);
    margin-bottom: 1.5rem;
}

.card-hint {
    color: var(--muted);
    font-size: 0.875rem;
    margin: 0 0 1rem;
}

.child-item-pre {
    border-left: 3px solid var(--primary);
}

.status-pre {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-photo {
    background: #dbeafe;
    color: #1d4ed8;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-form input {
    flex: 1;
}

.child-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.child-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg);
    border-radius: 8px;
    gap: 1rem;
}

.child-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.child-info small {
    color: var(--muted);
    font-size: 0.85rem;
}

.error-page {
    text-align: center;
    padding: 4rem 0;
}

.error-page h1 {
    font-size: 4rem;
    color: var(--primary);
}

.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.page-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.admin-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s, box-shadow 0.15s;
}

.admin-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.12);
}

.admin-card-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.75rem;
}

.admin-card h2 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.admin-card p {
    color: var(--muted);
    font-size: 0.9rem;
}

.inline-form {
    display: inline;
}

.actions-cell {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    align-items: center;
}

.badge-role {
    background: #f3f4f6;
    color: var(--text);
    font-family: inherit;
    font-weight: 600;
}

.row-inactive {
    opacity: 0.6;
}

.muted {
    color: var(--muted);
}

.admin-birthday-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
    .admin-birthday-grid { grid-template-columns: 1fr; }
}

.card-birthday-today {
    border: 1px solid #fcd34d;
    background: linear-gradient(180deg, #fffbeb 0%, #ffffff 100%);
}

.birthday-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.birthday-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: 8px;
}

.birthday-item small {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.15rem;
}

.birthday-item-today {
    background: #fef3c7;
}

.status-birthday {
    background: #fef3c7;
    color: #b45309;
}

.row-birthday {
    background: #fffbeb;
}

.empty-compact {
    padding: 1.25rem;
}

.period-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.freq-cell {
    min-width: 140px;
    width: 20%;
}

.freq-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

.freq-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    min-width: 0;
    transition: width 0.2s;
}

.row-no-visits {
    opacity: 0.75;
}

select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: white;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ——— Mobile / touch ——— */

.bottom-nav {
    display: none;
}

body.has-mobile-nav {
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
    body.has-mobile-nav {
        padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
    }

    .navbar {
        height: auto;
        min-height: 56px;
        padding: 0.625rem 1rem;
    }

    .navbar-brand {
        flex-wrap: wrap;
        gap: 0.35rem 0.5rem;
        min-width: 0;
    }

    .navbar-title {
        font-size: 0.95rem;
    }

    .navbar-church {
        flex-basis: 100%;
        margin-left: 2.5rem !important;
        font-size: 0.75rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .navbar-links-desktop {
        display: none;
    }

    .container {
        padding: 1rem 0.875rem 1.5rem;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 1rem;
    }

    .page-header h1 {
        font-size: 1.45rem;
    }

    .page-header .btn,
    .page-actions .btn {
        width: 100%;
    }

    .page-actions {
        flex-direction: column;
    }

    .card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: 10px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.625rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }

    .btn-sm {
        min-height: 40px;
        padding: 0.5rem 0.875rem;
    }

    .search-form,
    .search-form-page {
        flex-direction: column;
        max-width: none;
    }

    .search-form .btn,
    .search-form-page .btn {
        width: 100%;
    }

    .child-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .child-item form,
    .child-item .btn {
        width: 100%;
    }

    .actions-cell {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .actions-cell form,
    .actions-cell .btn {
        width: 100%;
    }

    .inline-form {
        display: block;
        width: 100%;
    }

    .inline-form .btn {
        width: 100%;
    }

    th, td {
        padding: 0.625rem 0.5rem;
        font-size: 0.875rem;
    }

    .auth-card {
        margin: 1.5rem auto;
        padding: 1.75rem 1.25rem;
    }

    .period-filter {
        gap: 0.375rem;
    }

    .period-filter .btn-sm {
        flex: 1 1 calc(50% - 0.375rem);
        min-width: 0;
    }

    .footer {
        padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
        font-size: 0.8rem;
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
        justify-content: space-around;
        align-items: stretch;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        padding: 0.35rem 0.25rem;
        min-height: 52px;
        text-decoration: none;
        color: var(--muted);
        border-radius: 10px;
        font-size: 0.65rem;
        font-weight: 600;
        transition: background 0.15s, color 0.15s;
    }

    .bottom-nav-item.active {
        color: var(--primary);
        background: #eef2ff;
    }

    .bottom-nav-item-primary .bottom-nav-icon {
        background: var(--primary);
        color: #fff;
        width: 2rem;
        height: 2rem;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        font-weight: 700;
    }

    .bottom-nav-item-primary.active .bottom-nav-icon {
        background: var(--primary-hover);
    }

    .bottom-nav-icon {
        font-size: 1.15rem;
        line-height: 1;
    }

    .bottom-nav-label {
        line-height: 1.1;
        text-align: center;
    }

    .bottom-nav-logout {
        color: #b91c1c;
    }
}

@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .bottom-nav-label {
        font-size: 0.6rem;
    }
}

.consent-box {
    margin-top: 1.25rem;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.consent-box h2 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.consent-text {
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.45;
    margin-bottom: 0.75rem;
}

.consent-check {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
}

.consent-check input {
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.125rem;
    flex-shrink: 0;
}

.consent-check small {
    font-weight: 400;
    color: var(--muted);
}
