/**
 * My Masonic Diary - Responsive Styles
 * Version: 2025102602
 * Mobile-optimized for standard phones (375-428px) and tablets (768-1024px)
 * Accessibility-enhanced for screen readers and keyboard navigation
 */

/* ============================================
   ACCESSIBILITY - SKIP LINK
   ============================================ */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--bs-primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    z-index: 9999;
    font-weight: 600;
    transform: translateY(-100%);
    transition: transform 0.2s ease;
}

.skip-link:focus,
.skip-link:active {
    top: 0;
    transform: translateY(0);
}

/* ============================================
   ACCESSIBILITY - SCREEN READER ONLY
   ============================================ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   ACCESSIBILITY - FOCUS INDICATORS
   ============================================ */
*:focus {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Better focus indicators for specific elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Dark mode focus indicators */
[data-bs-theme="dark"] *:focus,
[data-bs-theme="dark"] a:focus,
[data-bs-theme="dark"] button:focus {
    outline-color: var(--bs-info);
}

/* Don't show focus outline on mouse click, only keyboard */
*:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

*:focus-visible {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
}

/* ============================================
   BASE LAYOUT STRUCTURE
   ============================================ */
html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1 0 auto;
    padding: 2rem 0;
}

/* Mobile: Reduce padding for more content space */
@media (max-width: 767.98px) {
    .main-content {
        padding: 1rem 0;
    }
}

/* ============================================
   NAVIGATION
   ============================================ */
.navbar-brand {
    font-weight: 600;
}

/* Mobile: Ensure proper spacing in collapsed navbar */
@media (max-width: 991.98px) {
    .navbar-nav {
        padding: 0.5rem 0;
    }

    .navbar-nav .nav-item {
        padding: 0.25rem 0;
    }

    .navbar-nav .dropdown-menu {
        border: none;
        box-shadow: none;
    }
}

/* ============================================
   BREADCRUMBS
   ============================================ */
.breadcrumb {
    background: none;
    padding: 0;
    margin-bottom: 1.5rem;
}

@media (max-width: 767.98px) {
    .breadcrumb {
        margin-bottom: 1rem;
        font-size: 0.875rem;
    }
}

/* ============================================
   FOOTER
   ============================================ */
footer {
    flex-shrink: 0;
    background-color: var(--bs-light);
    border-top: 1px solid var(--bs-border-color);
    padding: 1.5rem 0;
    margin-top: auto;
}

[data-bs-theme="dark"] footer {
    background-color: var(--bs-dark);
}

/* Mobile: Adjust footer padding */
@media (max-width: 767.98px) {
    footer {
        padding: 1rem 0;
    }

    footer .col-md-3 {
        margin-bottom: 1.5rem;
    }

    footer .col-md-3:last-child {
        margin-bottom: 0;
    }
}

/* Tablet: Better footer column layout */
@media (min-width: 576px) and (max-width: 991.98px) {
    footer .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ============================================
   THEME TOGGLE
   ============================================ */
.theme-toggle {
    cursor: pointer;
    font-size: 1.2rem;
    transition: transform 0.3s ease;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

.theme-toggle .fa-sun {
    display: none;
}

[data-bs-theme="dark"] .theme-toggle .fa-sun {
    display: inline-block;
}

[data-bs-theme="dark"] .theme-toggle .fa-moon {
    display: none;
}

/* ============================================
   DARK MODE FIXES
   ============================================ */
[data-bs-theme="dark"] code {
    background-color: var(--bs-gray-800);
    color: var(--bs-light);
}

[data-bs-theme="dark"] pre {
    background-color: var(--bs-gray-800);
    color: var(--bs-light);
}

[data-bs-theme="dark"] .bg-light {
    background-color: var(--bs-gray-800) !important;
    color: var(--bs-light);
}

[data-bs-theme="dark"] .alert-info code,
[data-bs-theme="dark"] .alert code {
    background-color: rgba(0, 0, 0, 0.2);
    color: inherit;
}

/* ============================================
   CARDS & CONTAINERS
   ============================================ */
/* Mobile: Reduce card padding */
@media (max-width: 767.98px) {
    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }
}

/* ============================================
   BUTTONS & TOUCH TARGETS
   ============================================ */
/* Ensure minimum 44x44px touch target size (WCAG 2.1 AA) */
.btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
    font-weight: 500;
}

.btn-sm {
    min-height: 38px;
    padding: 0.375rem 0.75rem;
}

/* Better button contrast */
.btn-outline-primary {
    border-width: 2px;
}

.btn-outline-secondary {
    border-width: 2px;
}

/* Increase spacing between adjacent buttons */
.btn + .btn {
    margin-left: 0.5rem;
}

/* Mobile: Full-width buttons in button groups */
@media (max-width: 767.98px) {
    .btn-group-mobile-stack {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .btn-group-mobile-stack .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .btn-group-mobile-stack .btn:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   FORMS
   ============================================ */
/* Ensure form controls are touch-friendly */
.form-control,
.form-select {
    min-height: 44px;
}

/* Mobile: Add spacing between form elements */
@media (max-width: 767.98px) {
    .mb-3,
    .mb-2 {
        margin-bottom: 1rem !important;
    }

    /* Stack form buttons on mobile */
    form .d-flex.gap-2,
    form .d-flex.gap-3 {
        flex-direction: column;
    }

    form .d-flex.gap-2 > *,
    form .d-flex.gap-3 > * {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    form .d-flex.gap-2 > *:last-child,
    form .d-flex.gap-3 > *:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   TABLES - RESPONSIVE CARD VIEW
   ============================================ */
/* Hide tables on mobile, show card view */
@media (max-width: 767.98px) {
    .table-responsive table {
        display: none;
    }

    /* Show mobile card view */
    .mobile-card-view {
        display: block !important;
    }
}

/* Hide mobile card view on desktop */
@media (min-width: 768px) {
    .mobile-card-view {
        display: none !important;
    }
}

/* Mobile card styling */
.mobile-card {
    background: var(--bs-card-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.mobile-card:last-child {
    margin-bottom: 0;
}

.mobile-card-header {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--bs-border-color-translucent);
}

.mobile-card-row:last-of-type {
    border-bottom: none;
}

.mobile-card-label {
    font-weight: 600;
    color: var(--bs-secondary-color);
    flex: 0 0 40%;
}

.mobile-card-value {
    flex: 1;
    text-align: right;
    word-break: break-word;
}

.mobile-card-actions {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--bs-border-color);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mobile-card-actions .btn {
    flex: 1;
    min-width: calc(50% - 0.25rem);
}

/* ============================================
   STAT CARDS / DASHBOARD CARDS
   ============================================ */
/* Better stacking for dashboard stat cards */
@media (max-width: 767.98px) {
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }

    .row > [class*='col-']:last-child {
        margin-bottom: 0;
    }
}

/* Tablet: 2-column layout for stat cards */
@media (min-width: 576px) and (max-width: 991.98px) {
    .row-cols-md-2 > * {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ============================================
   DROPDOWN MENUS
   ============================================ */
/* Mobile navbar collapsed state - override Bootstrap dropdown positioning */
@media (max-width: 991.98px) {
    /* For dropdowns in collapsed navbar, integrate inline */
    .navbar-collapse .dropdown-menu {
        position: static !important;
        float: none;
        width: auto;
        margin-top: 0;
        background-color: transparent !important;
        border: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        left: auto !important;
        right: auto !important;
        max-width: none !important;
    }

    .navbar-collapse .dropdown-menu .dropdown-item {
        padding-left: 2rem;
        color: rgba(255, 255, 255, 0.75);
    }

    .navbar-collapse .dropdown-menu .dropdown-item:hover,
    .navbar-collapse .dropdown-menu .dropdown-item:focus {
        color: rgba(255, 255, 255, 1);
        background-color: rgba(255, 255, 255, 0.1);
    }

    .navbar-collapse .dropdown-divider {
        border-top-color: rgba(255, 255, 255, 0.1);
    }
}

/* Prevent dropdown overflow on small screens (non-navbar dropdowns) */
@media (max-width: 767.98px) {
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
    }
}

/* ============================================
   MODALS
   ============================================ */
/* Mobile: Full screen modals on small devices */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }

    .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }
}

/* ============================================
   BADGES & PILLS
   ============================================ */
/* Ensure badges are readable on mobile */
@media (max-width: 767.98px) {
    .badge {
        font-size: 0.8rem;
        padding: 0.35em 0.65em;
    }
}

/* ============================================
   ALERTS
   ============================================ */
/* Mobile: Adjust alert padding */
@media (max-width: 767.98px) {
    .alert {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* ============================================
   PAGINATION
   ============================================ */
/* Mobile: Smaller pagination buttons */
@media (max-width: 767.98px) {
    .pagination {
        font-size: 0.875rem;
    }

    .page-link {
        padding: 0.375rem 0.75rem;
    }
}

/* ============================================
   DATATABLES MOBILE ADJUSTMENTS
   ============================================ */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        margin-top: 1rem;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: center;
        margin-bottom: 1rem;
    }

    .dataTables_wrapper .dataTables_length label,
    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin: 0.5rem 0 0 0 !important;
    }
}

/* ============================================
   SPACING UTILITIES
   ============================================ */
/* Mobile: Reduce excessive spacing */
@media (max-width: 767.98px) {
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }

    .mb-5 {
        margin-bottom: 2rem !important;
    }

    .mt-4 {
        margin-top: 1.5rem !important;
    }

    .mt-5 {
        margin-top: 2rem !important;
    }

    .py-4 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }

    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
/* Improved base typography for readability (especially for older users) */
body {
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: 0.01em;
}

/* Increase minimum font size for better readability */
.small, small {
    font-size: 0.9rem;
}

/* Better text contrast */
.text-muted {
    color: #6c757d !important;
}

[data-bs-theme="dark"] .text-muted {
    color: #adb5bd !important;
}

/* Better link contrast */
a {
    text-decoration-skip-ink: auto;
}

/* Mobile: Slightly smaller headings for better fit */
@media (max-width: 767.98px) {
    h1, .h1 {
        font-size: 2rem;
    }

    h2, .h2 {
        font-size: 1.5rem;
    }

    h3, .h3 {
        font-size: 1.25rem;
    }

    .display-1 {
        font-size: 3.5rem;
    }

    .display-2 {
        font-size: 3rem;
    }

    .display-3 {
        font-size: 2.5rem;
    }

    .display-4 {
        font-size: 2rem;
    }
}

/* Desktop: Ensure comfortable reading for older users */
@media (min-width: 768px) {
    body {
        font-size: 17px;
    }

    .lead {
        font-size: 1.35rem;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
/* Mobile-specific utility classes */
.mobile-only {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-only {
        display: block;
    }

    .mobile-hide {
        display: none !important;
    }

    .mobile-text-center {
        text-align: center !important;
    }
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .desktop-only {
        display: block;
    }
}
