/* ============================================
   Personal Planner - Pastel Modern Theme
   Clean, calm, highly readable
   ============================================ */

:root {
    --bg: #F8F5F1;
    --surface: #FFFFFF;
    --surface-2: #FDF9F3;
    --text: #3F3A36;
    --text-muted: #7A7169;
    --border: #EDE6DC;

    /* Pastel category colors (from C# extensions too) */
    --cat-personal: #A8D5BA;
    --cat-work: #A8C5D8;
    --cat-family: #F2C4C4;
    --cat-spiritual: #D4C1EC;

    --accent: #C9B8E0;
    --accent-dark: #8B6FA8;
    --primary: #7B6B8F;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    /* Prevent horizontal “wiggle” on narrow phones */
    overflow-x: hidden;
    max-width: 100vw;
    /* Fill phone viewport including dynamic browser chrome */
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.2px;
    overflow-wrap: anywhere;
}

/* ========== Random quote areas (from Life with Him API) ========== */
.quote-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.quote-area-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.45rem;
}

.quote-area-body {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.45;
    color: var(--text);
    font-style: italic;
}

.quote-area-attr {
    margin-top: 0.45rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.quote-area-refresh {
    margin-top: 0.65rem;
}

.quote-area-hero {
    background: linear-gradient(145deg, #5c4d6e 0%, #7B6B8F 100%);
    color: #fff;
    border: none;
}

.quote-area-hero .quote-area-title,
.quote-area-hero .quote-area-attr {
    color: rgba(255, 255, 255, 0.8);
}

.quote-area-hero .quote-area-body {
    color: #fff;
    font-size: 1.25rem;
}

.quote-area-compact {
    min-height: 8.5rem;
}

.quote-area-inline {
    border-style: dashed;
    background: var(--surface-2);
}

/* ========== Interactive media (Desktop shell) ========== */
.media-page {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

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

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

.media-status {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
}

.media-status-ok {
    border-color: #b8d9c8;
    background: #f3faf6;
}

.media-status-error {
    border-color: #e8b8b8;
    background: #fdf6f6;
    color: #8a3a3a;
}

.media-card-shell {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.media-remove-btn {
    font-size: 0.8rem;
    padding: 0.35rem 0.65rem;
}

.media-offline-badge {
    position: absolute;
    left: 0.55rem;
    top: 0.55rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    background: #2a6b5a;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
}

.media-source-pill {
    display: inline-block;
    margin: 0.35rem 0 0.5rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.media-source-pill.offline {
    background: #e8f4ef;
    color: #2a6b5a;
}

.media-source-pill.online {
    background: #fff4e0;
    color: #8a6200;
}

.media-page-header h1 {
    margin: 0 0 0.35rem;
    font-size: 1.5rem;
}

.media-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.85rem;
}

.media-card-btn {
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    overflow: hidden;
    cursor: pointer;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.media-card-btn:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.media-card-btn .media-card-preview {
    position: relative;
    aspect-ratio: 16 / 9;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-card-btn .media-card-icon {
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.9);
}

.media-card-btn .media-card-duration {
    position: absolute;
    right: 0.55rem;
    bottom: 0.55rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 0.75rem;
}

.media-card-btn .media-card-body {
    padding: 0.85rem 1rem 1rem;
}

.media-card-btn .media-card-body h2 {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
}

.media-card-btn .media-card-body p {
    margin: 0;
}

.media-back {
    display: inline-block;
    margin-bottom: 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.media-detail-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.45rem;
}

.media-detail-intro {
    margin: 0 0 1rem;
    color: var(--text-muted);
}

.media-player-host {
    border-radius: 14px;
    overflow: hidden;
}

@media (max-width: 768px) {
    .media-page-header {
        flex-direction: column;
        align-items: stretch;
    }

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

    .media-card-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== App shell layout ========== */
.page {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
}

.main-content,
main {
    flex: 1;
    width: 100%;
    max-width: 100%;
    padding: 1.25rem 1.75rem 2rem;
    /* Leave room for bottom tab bar on phones (overridden in media query) */
    padding-bottom: 2rem;
}

/* Sticky top header */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 1rem;
    padding-top: max(0.55rem, env(safe-area-inset-top));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 3.25rem;
}

.app-header .brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    white-space: nowrap;
    min-width: 0;
}

.brand-emoji {
    font-size: 1.25rem;
    line-height: 1;
}

.brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.desktop-nav.nav-links,
.app-header .nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-left: 0.5rem;
    min-width: 0;
}

.app-header .nav-links a,
.nav-links .nav-link {
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.92rem;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.app-header .nav-links a.active,
.app-header .nav-links a:hover,
.nav-links .nav-link.active,
.nav-links a.active {
    background: #F0E9E0;
    color: var(--text);
}

.user-chip {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-2);
    padding: 0.2rem 0.55rem 0.2rem 0.35rem;
    border-radius: 999px;
    font-size: 0.88rem;
    max-width: min(280px, 40vw);
}

.user-chip .user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 10rem;
}

.user-chip .avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Account dropdown (signed-in) */
.account-menu-wrap {
    position: relative;
    overflow: visible;
    max-width: none;
}

.account-menu {
    position: relative;
}

.account-menu-summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    color: var(--text);
    user-select: none;
}

.account-menu-summary::-webkit-details-marker {
    display: none;
}

.account-menu-caret {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.account-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.45rem);
    min-width: 11rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    padding: 0.35rem;
    z-index: 200;
}

.account-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: 0;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font: inherit;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
}

.account-menu-item:hover {
    background: #F0E9E0;
}

.account-menu-form {
    margin: 0;
}

.account-menu-danger {
    color: #8a3a3a;
}

/* Phone bottom tab bar — hidden on desktop */
.bottom-nav {
    display: none;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.btn {
    border-radius: 10px;
    padding: 0.55rem 1.15rem;
    font-weight: 600;
    font-size: 0.95rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary {
    background: #7B6B8F;
    color: white;
    border-color: #7B6B8F;
}

.btn-primary:hover {
    background: #655A77;
}

.btn-outline {
    background: transparent;
    border-color: #D4C8B8;
    color: var(--text);
}

.btn-outline:hover {
    background: #F5F0E8;
}

.btn-danger {
    background: #E8B8B8;
    color: #5C3A3A;
    border-color: #E8B8B8;
}

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

/* Cards & Surfaces */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.section-title {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Calendar Views */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.calendar-header h2 {
    margin: 0;
    font-size: 1.65rem;
    font-weight: 600;
}

.view-switcher {
    display: inline-flex;
    background: #F0E9E0;
    border-radius: 999px;
    padding: 3px;
}

.view-switcher button {
    background: none;
    border: none;
    padding: 0.4rem 1.1rem;
    border-radius: 999px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.1s;
}

.view-switcher button.active {
    background: white;
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Month View Grid */
.month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    background: var(--border);
    padding: 4px;
    border-radius: 14px;
}

.month-grid .day-header {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.4rem 0 0.25rem;
    background: var(--surface-2);
}

.day-cell {
    background: var(--surface);
    min-height: 108px;
    padding: 6px 8px;
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    border: 1px solid transparent;
}

.day-cell:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.day-cell.other-month {
    opacity: 0.45;
    background: #FAF7F2;
}

.day-cell.today {
    border-color: #C9B8E0;
    background: #FBF8F3;
}

.day-number {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.day-events {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.event-pill {
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1.3;
    font-weight: 500;
}

.holiday-pill {
    background: #F5D78E;
    color: #6B4E16;
    border: 1px solid #E8C56A;
    font-weight: 600;
    cursor: default;
}

.holiday-all-day {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #FFF8E8;
    border: 1px solid #F0DFA8;
    border-radius: 10px;
}

.relationship-pill {
    background: #F2C4C4;
    color: #7A4F4F;
    border: 1px solid #E5A8A8;
    font-weight: 600;
}

.relationships-page,
.relationship-form-page {
    max-width: 1100px;
    margin: 0 auto;
}

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

.relationship-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.relationship-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.relationship-type-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: #FBF8F3;
    color: #7A7169;
    font-size: 0.82rem;
}

.relationship-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.75rem;
}

.relationship-section {
    margin-top: 0.75rem;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag-pill {
    background: #E8F4EC;
    color: #4F7359;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
}

.important-date-row {
    font-size: 0.88rem;
    color: #666;
    margin-bottom: 0.2rem;
}

.relationship-form-card {
    max-width: 760px;
}

.repeatable-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.important-date-form-row {
    grid-template-columns: 1.2fr 1fr auto;
}

.relationship-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Week View */
.week-grid {
    display: grid;
    grid-template-columns: 62px repeat(7, 1fr);
    gap: 3px;
}

.week-day-header {
    text-align: center;
    padding: 0.5rem 0.25rem;
    font-weight: 600;
}

.week-day-header .date {
    font-size: 1.35rem;
    line-height: 1;
    margin-top: 2px;
}

/* Daily Agenda (Hourly) */
.day-agenda {
    display: flex;
    flex-direction: column;
}

.time-slot {
    display: flex;
    border-bottom: 1px solid #F0E9E0;
    min-height: 52px;
    cursor: pointer;
}

.time-slot:hover {
    background: #FBF8F3;
}

.time-label {
    width: 68px;
    flex-shrink: 0;
    padding-top: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
    padding-right: 12px;
    user-select: none;
}

.time-content {
    flex: 1;
    padding: 4px 6px;
    border-left: 1px solid #F0E9E0;
}

.time-content .entry {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 4px 10px;
    margin-bottom: 4px;
    font-size: 0.88rem;
    border-left: 4px solid;
}

/* Modal / Entry Form */
/* Custom modal styles - namespaced to avoid conflict with Bootstrap's .modal */
.planner-modal-backdrop {
    position: fixed !important;
    inset: 0;
    background: rgba(60, 55, 50, 0.45);
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 9999 !important;
}

.planner-modal {
    background: var(--surface);
    width: 100%;
    max-width: 520px;
    min-width: 320px;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
    overflow: hidden;
    display: flex !important;
    flex-direction: column;
    color: var(--text);
    box-sizing: border-box;
}

.planner-modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.planner-modal-body {
    padding: 1.25rem;
    flex: 1 1 auto;
    overflow: auto;
}

.planner-modal-footer {
    padding: 0.85rem 1.25rem;
    background: var(--surface-2);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-shrink: 0;
}

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

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

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.form-control, select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.97rem;
    background: white;
    color: var(--text);
}

textarea {
    min-height: 86px;
    resize: vertical;
}

/* Category Pills */
.category-pills {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.category-pill {
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    border: 2px solid transparent;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s;
}

.category-pill.active {
    border-color: currentColor;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

/* Profile Page */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.25rem;
}

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

.upcoming-list .entry-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    margin-bottom: 0.35rem;
    background: var(--surface-2);
}

.today-notes {
    min-height: 220px;
}

/* Misc */
.pastel-shadow {
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

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

.empty-state .icon {
    font-size: 2.4rem;
    opacity: 0.6;
}

/* Auth page */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #F8F5F1, #F0E9E0);
    padding: 2rem;
}

.auth-card {
    background: white;
    width: 100%;
    max-width: 380px;
    border-radius: 20px;
    padding: 2rem 1.75rem;
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}

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

.auth-header .logo {
    font-size: 2.8rem;
    margin-bottom: 0.25rem;
}

.auth-header h1 {
    margin: 0 0 0.2rem;
    font-size: 1.65rem;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-tabs {
    display: flex;
    background: #F4EDE4;
    border-radius: 999px;
    padding: 3px;
    margin-bottom: 1.1rem;
}

.auth-tabs .tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: none;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
}

.auth-tabs .tab.active {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.auth-form .form-group {
    margin-bottom: 0.9rem;
}

.btn-block {
    width: 100%;
    margin-top: 0.4rem;
}

.auth-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* ============================================
   Mobile / small screens (phones & narrow emulators)
   ============================================ */
@media (max-width: 768px) {
    html, body {
        font-size: 15px;
    }

    /* Hide desktop nav; use bottom tabs */
    .desktop-nav {
        display: none !important;
    }

    .app-header {
        justify-content: center;
        padding: 0.5rem 0.75rem;
        padding-top: max(0.5rem, env(safe-area-inset-top));
    }

    .app-header .brand {
        font-size: 1.05rem;
        margin: 0 auto;
    }

    .brand-text {
        max-width: 70vw;
    }

    /* Fixed bottom tab bar */
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 18px rgba(60, 50, 40, 0.08);
        padding: 0.35rem 0.25rem;
        padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
        justify-content: space-around;
        align-items: stretch;
        gap: 0;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.1rem;
        min-height: 3.25rem;
        padding: 0.25rem 0.15rem;
        text-decoration: none;
        color: var(--text-muted);
        font-weight: 600;
        font-size: 0.68rem;
        letter-spacing: 0.01em;
        border-radius: 12px;
        transition: background 0.12s ease, color 0.12s ease;
        -webkit-tap-highlight-color: transparent;
    }

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

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

    /* Content clears the tab bar */
    .page-authed .main-content,
    .page-authed main {
        padding: 0.85rem 0.85rem;
        padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
        padding-left: max(0.85rem, env(safe-area-inset-left));
        padding-right: max(0.85rem, env(safe-area-inset-right));
    }

    /* ---- Calendar toolbar ---- */
    .calendar-page {
        width: 100%;
        max-width: 100%;
    }

    .calendar-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
        margin-bottom: 0.85rem;
    }

    .calendar-header > div:first-child {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.4rem;
        justify-content: center;
    }

    .calendar-header h2 {
        font-size: 1.2rem;
        width: 100%;
        text-align: center;
        order: -1;
        margin: 0 0 0.15rem;
    }

    .calendar-header .btn {
        padding: 0.45rem 0.75rem;
        font-size: 0.88rem;
        min-height: 40px;
    }

    .view-switcher {
        width: 100%;
        justify-content: stretch;
    }

    .view-switcher button {
        flex: 1;
        padding: 0.5rem 0.4rem;
        font-size: 0.85rem;
        min-height: 40px;
    }

    .calendar-header > .btn-primary {
        width: 100%;
    }

    /* ---- Month grid: compact, aligned, dots for events ---- */
    .month-grid {
        gap: 2px;
        padding: 2px;
        border-radius: 12px;
        width: 100%;
    }

    .month-grid .day-header {
        font-size: 0.65rem;
        padding: 0.35rem 0;
        letter-spacing: 0;
    }

    .day-cell {
        min-height: 3.4rem;
        padding: 3px 2px 4px;
        border-radius: 8px;
        overflow: hidden;
    }

    .day-cell:hover {
        transform: none; /* no hover lift on touch */
        box-shadow: none;
    }

    .day-number {
        font-size: 0.78rem;
        text-align: center;
        margin-bottom: 2px;
    }

    .day-events {
        align-items: center;
        gap: 2px;
        max-height: 1.4rem;
        overflow: hidden;
    }

    /* Shrink event labels to color dots so the grid stays neat */
    .day-events .event-pill {
        width: 6px;
        height: 6px;
        min-width: 6px;
        padding: 0;
        border-radius: 50%;
        font-size: 0 !important;
        line-height: 0;
        color: transparent !important;
        overflow: hidden;
        border-width: 0;
    }

    /* ---- Week view: scroll sideways if needed ---- */
    .week-grid {
        grid-template-columns: 48px repeat(7, minmax(4.5rem, 1fr));
        min-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: grid;
    }

    .week-grid.card {
        padding: 0.5rem;
    }

    .week-day-header {
        font-size: 0.75rem;
        padding: 0.35rem 0.1rem;
    }

    .week-day-header .date {
        font-size: 1.05rem;
    }

    /* ---- Day agenda ---- */
    .time-label {
        width: 52px;
        font-size: 0.72rem;
        padding-right: 6px;
    }

    .time-slot {
        min-height: 48px;
    }

    .time-content .entry {
        font-size: 0.82rem;
        padding: 4px 8px;
    }

    /* ---- Modals: full-width sheet on phone ---- */
    .planner-modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .planner-modal {
        max-width: 100%;
        min-width: 0;
        width: 100%;
        max-height: min(92dvh, 92vh);
        border-radius: 18px 18px 0 0;
        margin: 0;
    }

    .planner-modal-header,
    .planner-modal-body,
    .planner-modal-footer {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .planner-modal-footer {
        flex-wrap: wrap;
        padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
    }

    .planner-modal-footer .btn {
        flex: 1 1 auto;
        min-width: 30%;
        min-height: 44px;
    }

    /* Forms stack on narrow screens */
    .form-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .form-control,
    select,
    textarea,
    input.form-control {
        font-size: 16px !important; /* prevents iOS zoom on focus */
        max-width: 100%;
    }

    .category-pills {
        gap: 0.4rem;
    }

    .category-pill {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
    }

    /* ---- Relationships ---- */
    .relationships-header {
        flex-direction: column;
        align-items: stretch;
    }

    .relationships-header .btn {
        width: 100%;
    }

    .relationship-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .important-date-form-row,
    .repeatable-row {
        grid-template-columns: 1fr;
    }

    .relationship-form-actions {
        flex-direction: column-reverse;
    }

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

    /* ---- Cards / profile / bible ---- */
    .card {
        padding: 0.9rem;
        border-radius: 14px;
    }

    .profile-grid {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .bible-header {
        flex-direction: column;
        align-items: stretch;
    }

    .version-switcher {
        width: 100%;
    }

    .version-btn {
        flex: 1;
        justify-content: center;
        padding: 0.45rem 0.5rem;
        font-size: 0.85rem;
    }

    .auth-container {
        padding: 1rem;
        align-items: flex-start;
        padding-top: max(1.5rem, env(safe-area-inset-top));
        min-height: 100dvh;
    }

    .auth-card {
        padding: 1.35rem 1.1rem;
        border-radius: 16px;
        margin: auto 0;
    }

    .auth-header h1 {
        font-size: 1.4rem;
    }

    /* Touch targets */
    .btn {
        min-height: 42px;
    }

    /* Avoid content wider than viewport from tables/pre */
    img, video, svg {
        max-width: 100%;
        height: auto;
    }
}

/* Extra-narrow phones */
@media (max-width: 380px) {
    .day-cell {
        min-height: 2.85rem;
        padding: 2px 1px;
    }

    .day-number {
        font-size: 0.72rem;
    }

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

    .app-header .brand {
        font-size: 0.98rem;
    }
}

/* Tablet: show top nav, hide bottom bar */
@media (min-width: 769px) {
    .bottom-nav {
        display: none !important;
    }

    .desktop-nav {
        display: flex !important;
    }

    .app-header .nav-links.desktop-nav {
        flex: 1;
    }
}

/* === Bible Study Styles === */
.bible-container {
    max-width: 920px;
    margin: 0 auto;
}

.bible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.version-switcher {
    display: flex;
    gap: 4px;
    background: #F0E9E0;
    padding: 3px;
    border-radius: 999px;
}

.version-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text-muted);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.version-btn.active {
    background: white;
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.current-ref {
    font-weight: 600;
    font-size: 1.05rem;
}

.current-ref .translation-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: normal;
}

.bible-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.book-selector {
    min-width: 220px;
}

.book-selector label {
    display: block;
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.book-selector select {
    font-size: 1rem;
    padding: 0.5rem;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.chapter-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.chapter-nav .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.chapter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
    padding: 6px;
    background: #F8F5F1;
    border-radius: 8px;
}

.chapter-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 0.95rem;
    border: 1px solid #D4C8B8;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.chapter-btn.active {
    background: #7B6B8F;
    color: white;
    border-color: #7B6B8F;
}

.verse {
    margin-bottom: 0.35rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #F0E9E0;
}

.verse-text {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* Verse number: tappable anchor for passage start/end */
button.verse-number,
.verse-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #7B6B8F;
    min-width: 1.65rem;
    min-height: 1.65rem;
    padding: 0 0.2rem;
    margin: 0;
    line-height: 1;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
}

button.verse-number:hover,
button.verse-number:focus-visible {
    background: #F0E9F8;
    outline: none;
}

/* Passage bookmark: light purple circle (start, end, and all between) */
button.verse-number.passage-marked,
.verse-number.passage-marked {
    background: #DCCCEC;
    color: #4A3F57;
    box-shadow: 0 0 0 1px rgba(123, 107, 143, 0.25);
}

button.verse-number.passage-start-pending {
    background: #E8DFF5;
    box-shadow: 0 0 0 2px rgba(123, 107, 143, 0.35);
}

.note-toggle-btn.has-passage {
    filter: none;
    background: #E8DFF5;
    border-radius: 6px;
}

/* Commentary (server-authored, read-only) — brown "C" before notes */
button.commentary-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    min-height: 1.75rem;
    padding: 0 0.35rem;
    margin: 0;
    border: 1px solid #8B5E3C;
    border-radius: 6px;
    background: #A67C52;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 800;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.02em;
}

button.commentary-toggle-btn:hover,
button.commentary-toggle-btn:focus-visible {
    background: #8B5E3C;
    outline: none;
}

button.commentary-toggle-btn.active {
    box-shadow: 0 0 0 2px rgba(139, 94, 60, 0.35);
}

.verse-commentary-panel {
    margin: 0.45rem 0 0.65rem;
    padding: 0.75rem 0.9rem;
    background: #FBF6F0;
    border: 1px solid #E5D4C0;
    border-left: 4px solid #A67C52;
    border-radius: 8px;
}

.verse-commentary-panel .commentary-label {
    margin: 0 0 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: #8B5E3C;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.verse-commentary-panel .commentary-body {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #3D3229;
    white-space: pre-wrap;
}

.verse-commentary-panel .commentary-readonly-hint {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    color: #8A7A6A;
}

/* Passage study (3 reflection fields + free notes) under end verse */
.passage-study-panel {
    margin: 0.5rem 0 0.75rem;
    padding: 0.85rem 1rem;
    background: #F7F3FB;
    border: 1px solid #E4D8F2;
    border-radius: 10px;
}

.passage-study-panel h4 {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    color: #4A3F57;
}

.passage-study-field {
    margin-bottom: 0.75rem;
}

.passage-study-field label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #5B4A6F;
    margin-bottom: 0.3rem;
    line-height: 1.35;
}

.passage-study-field textarea {
    width: 100%;
    min-height: 4.5rem;
    font-size: 0.92rem;
    line-height: 1.4;
    resize: vertical;
}

.passage-study-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.35rem;
}

/* Start / end point dialog */
.verse-anchor-dialog {
    max-width: min(360px, 94vw);
}

.verse-anchor-dialog .verse-anchor-ref {
    margin: 0 0 0.85rem;
    font-size: 0.95rem;
    color: #4A3F57;
}

.verse-anchor-choices {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.verse-anchor-choices button {
    width: 100%;
    text-align: left;
    padding: 0.75rem 0.9rem;
    min-height: 48px;
}

.verse-body {
    flex: 1;
    line-height: 1.55;
}

/* KJV: tappable words that have Strong's numbers in the tagged text pack */
button.bible-word-strongs {
    display: inline;
    margin: 0;
    padding: 0 1px;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: #7B6B8F;
    text-underline-offset: 3px;
    border-radius: 2px;
    -webkit-tap-highlight-color: transparent;
}

button.bible-word-strongs:hover,
button.bible-word-strongs:focus-visible {
    background: #F0E9F8;
    color: #4A3F57;
    outline: none;
}

.bible-word-popup {
    max-width: min(480px, 96vw);
}

.bible-word-popup .strongs-definition {
    margin-top: 0.35rem;
    font-size: 0.95rem;
    line-height: 1.45;
    color: #333;
}

.bible-word-popup-intro {
    margin: 0 0 0.85rem;
    padding: 0.65rem 0.75rem;
    font-size: 0.88rem;
    line-height: 1.4;
    color: #4A3F57;
    background: #F5F0FA;
    border-radius: 8px;
    border: 1px solid #E4D8F2;
}

.strongs-word-index {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: #5B4A6F;
}

.strongs-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    letter-spacing: 0.01em;
}

.strongs-badge-gloss {
    background: #E8F2E8;
    color: #2F5C3A;
}

.strongs-badge-untranslated {
    background: #F5EDE0;
    color: #6B5344;
}

.strongs-word-untranslated {
    background: #FBF7F1;
    margin: 0 -0.35rem;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    border-radius: 8px;
}

.bible-word-popup .strongs-word-row + .strongs-word-row {
    margin-top: 0.35rem;
    padding-top: 0.65rem;
}

.note-privacy-hint {
    margin: 0.4rem 0 0.55rem;
    font-size: 0.8rem;
    color: #5C8C6E;
    line-height: 1.35;
}

.note-toggle-btn {
    background: none;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.note-toggle-btn:hover {
    opacity: 1;
}

.strongs-toggle-btn {
    border: none;
    background: #F0E9E0;
    color: #5B4A6F;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 6px;
    line-height: 1.6;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}

.strongs-toggle-btn:hover,
.strongs-toggle-btn.active {
    opacity: 1;
    background: #E4D8F2;
}

.verse-strongs-panel {
    margin-top: 0.45rem;
    margin-left: 28px;
    background: #FBF8F3;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    border: 1px solid #E8DFF0;
}

.strongs-loading,
.strongs-empty {
    margin: 0;
    font-size: 0.88rem;
    color: #7A7169;
}

.strongs-word-row {
    padding: 0.55rem 0;
    border-bottom: 1px solid #EDE6DC;
}

.strongs-word-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.strongs-word-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.strongs-original {
    font-size: 1.15rem;
    font-weight: 700;
    color: #4A3F57;
}

.strongs-language {
    font-size: 0.75rem;
    font-weight: 600;
    color: #7B6B8F;
    background: #F0E9F8;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
}

.strongs-number {
    font-size: 0.78rem;
    font-weight: 700;
    color: #6B5A7F;
}

.strongs-meta,
.strongs-submeta {
    font-size: 0.84rem;
    color: #666;
    margin-top: 0.15rem;
}

.strongs-definition {
    margin-top: 0.35rem;
    font-size: 0.88rem;
    line-height: 1.45;
    color: #3F3A36;
}

.strongs-import-banner {
    margin-bottom: 1rem;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    background: #FFF8E8;
    border: 1px solid #F0DFA8;
    color: #6B4E16;
    font-size: 0.9rem;
}

.strongs-import-banner.complete {
    background: #EEF8F1;
    border-color: #B9DEC5;
    color: #3F6B4F;
}

.strongs-import-banner.failed {
    background: #FDEEEE;
    border-color: #E8B4B4;
    color: #8B3A3A;
}

.verse-note-editor {
    margin-top: 0.35rem;
    margin-left: 28px;
    background: #FBF8F3;
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid #EDE6DC;
}

.note-textarea {
    min-height: 68px;
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}

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

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}
