:root {
    --primary: #1a5276;
    --primary-light: #2980b9;
    --accent: #27ae60;
    --danger: #c0392b;
    --warning: #f39c12;
    --bg: #f5f6fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #dcdde1;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}

main { width: 100%; flex: 1; }

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ──────────────────────────────── */
.navbar {
    background: var(--primary);
    color: #fff;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}
.navbar-brand:hover { text-decoration: none; color: #fff; }
.navbar-brand .icon { font-size: 1.4rem; }
.navbar-nav { display: flex; gap: 8px; align-items: center; }
.navbar-nav a {
    color: rgba(255,255,255,0.85);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.navbar-nav a:hover { background: rgba(255,255,255,0.15); color: #fff; text-decoration: none; }
.navbar-nav a.active { background: rgba(255,255,255,0.2); color: #fff; }
.navbar-user {
    color: rgba(255,255,255,0.9);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 12px;
}
.navbar-user .badge {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
}

/* ── Layout ──────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; width: 100%; }
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 1.5rem; font-weight: 600; }

/* ── Cards ───────────────────────────────── */
.card {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Tables ──────────────────────────────── */
.table-wrap {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 24px;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tr:hover { background: #f8f9fa; }

/* ── Buttons ─────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    touch-action: manipulation;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover { background: #219a52; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ── Forms ───────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-muted);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary-light); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }

/* ── Badges ──────────────────────────────── */
.badge-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-confirmed { background: #d5f5e3; color: #1e8449; }
.badge-pending { background: #fdebd0; color: #d68910; }
.badge-sick { background: #fff9c4; color: #b8860b; }
.badge-role {
    background: #eaf2f8;
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
}

/* ── Alerts ──────────────────────────────── */
.alert {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.alert-success { background: #d5f5e3; color: #1e8449; border: 1px solid #82e0aa; }
.alert-danger { background: #fadbd8; color: #922b21; border: 1px solid #f1948a; }
.alert-info { background: #d6eaf8; color: #1b4f72; border: 1px solid #85c1e9; }

/* ── Modal ───────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal h2 { font-size: 1.2rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Login page ──────────────────────────── */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    text-align: center;
}
.login-card h1 { font-size: 1.3rem; margin-bottom: 8px; color: var(--primary); }
.login-card .subtitle { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 28px; }
.login-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
    background: rgba(26, 82, 118, 0.9);
    color: rgba(255,255,255,0.9);
    font-size: 0.85rem;
}
.login-footer p { margin: 0; }
.login-footer .mp-link {
    color: #fff;
    font-weight: 700;
    text-decoration: underline;
    margin-left: 4px;
}

/* ── Diary entry card ────────────────────── */
.entry-card {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    border-left: 4px solid var(--warning);
}
.entry-card.confirmed { border-left-color: var(--accent); }
.entry-date { font-weight: 600; color: var(--primary); margin-bottom: 8px; }
.entry-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }
.entry-comment {
    background: #f0f0f0;
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    font-size: 0.85rem;
}
.entry-selfie { max-width: 200px; border-radius: 8px; margin-top: 10px; }

/* ── Choose role page ────────────────────── */
.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 24px;
}
.role-card {
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.role-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.role-card .role-icon { font-size: 2rem; margin-bottom: 12px; }
.role-card .role-name { font-weight: 600; font-size: 0.95rem; }

/* ── Collapsible blocks ──────────────────── */
details.acc {
    margin-bottom: 8px;
    background: var(--card-bg);
    border-radius: 12px;
}
summary.acc-sum {
    cursor: pointer;
    user-select: none;
    padding: 16px;
    font-size: 23px;
    font-weight: 800;
    letter-spacing: .2px;
    color: var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border-radius: 12px;
    list-style: none;
    transition: background .15s ease;
}
summary.acc-sum::-webkit-details-marker { display: none; }
summary.acc-sum:hover { background: #f0f5fa; }
summary.acc-sum .acc-title { display: flex; align-items: center; gap: 10px; }
summary.acc-sum .acc-count {
    background: var(--primary-light);
    color: #fff;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 700;
    padding: 3px 11px;
}
details.acc[open] summary.acc-sum {
    border-bottom: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    color: var(--primary);
}
.acc-body { padding: 16px; }

/* ── Date filter chips ─────────────────── */
.day-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 46px;
    padding: 5px 0;
    border-radius: 8px;
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: .78rem;
    transition: all .15s ease;
    touch-action: manipulation;
}
.day-chip:hover { text-decoration: none; border-color: var(--primary); }
.day-chip .chip-d { font-weight: 700; font-size: .95rem; line-height: 1.1; }
.day-chip .chip-w { font-size: .66rem; color: var(--text-muted); }
.day-chip.has-data { background: rgb(0,255,0); border-color: #00cc00; }
.day-chip.has-data .chip-d { color: #000; }
.day-chip.has-data .chip-w { color: #14532d; }
.day-chip.is-missing { background: rgb(255,0,0); border-color: #d32f2f; }
.day-chip.is-missing .chip-d { color: #fff; }
.day-chip.is-missing .chip-w { color: #ffd9d9; }
.day-chip.is-missing:hover { border-color: #b71c1c; }
.day-chip.is-sick { background: rgb(255,235,59); border-color: #f9a825; }
.day-chip.is-sick .chip-d { color: #000; }
.day-chip.is-sick .chip-w { color: #5d5100; }
.day-chip.is-sick:hover { border-color: #f57f17; }
.day-chip.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); color: var(--primary); }
.day-chip.selected .chip-d { color: var(--primary); }
.day-chip.today { outline: 1px dashed var(--primary-light); }

/* ── Responsive ──────────────────────────── */
body { padding-bottom: env(safe-area-inset-bottom); }
main { padding-left: max(env(safe-area-inset-left), 0px); padding-right: max(env(safe-area-inset-right), 0px); }

@media (display-mode: standalone) {
    .navbar {
        padding-top: env(safe-area-inset-top);
        height: calc(56px + env(safe-area-inset-top));
    }
}

@media (max-width: 768px) {
    .navbar { padding: 0 10px; gap: 8px; }
    .navbar-brand { font-size: 1rem; gap: 6px; }
    .navbar-nav { gap: 4px; }
    .navbar-nav a { padding: 6px 10px; font-size: .85rem; }
    .navbar-user { gap: 6px; font-size: .8rem; }
    .navbar-user > span:first-child { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .container { padding: 12px; }
    .page-header { margin-bottom: 16px; }
    .page-header h1 { font-size: 1.2rem; }
    .card-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 10px; }
    .form-row .form-group { min-width: 0; }
    .form-control, select.form-control, .btn {
        font-size: 16px;
    }
    th, td { padding: 8px 10px; font-size: .8rem; }
    th { font-size: .72rem; }
    .modal { padding: 20px; width: 95%; }
    .modal h2 { font-size: 1.05rem; }
    .acc-body { padding: 12px; }
    summary.acc-sum { font-size: 23px; padding: 12px; }
    .stat-card .stat-value { font-size: 1.6rem; }
    .login-card { padding: 28px 20px; }
    .entry-selfie { max-width: 160px; }
    .role-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
    .role-card { padding: 16px; }
}

@media (max-width: 380px) {
    .role-grid { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 1.05rem; }
}
