/* CSS Variables for theming */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-nav: #333;
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #888;
    --border-color: #ddd;
    --accent: #722F37;
    --accent-dark: #5a252c;
    --shadow: rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #252542;
    --bg-nav: #16213e;
    --text-primary: #eaeaea;
    --text-secondary: #b0b0b0;
    --text-muted: #888;
    --border-color: #3a3a5c;
    --accent: #9b4f57;
    --accent-dark: #722F37;
    --shadow: rgba(0,0,0,0.3);
}

[data-theme="dark"] .panel,
[data-theme="dark"] .card,
[data-theme="dark"] .stat-box,
[data-theme="dark"] .event-card,
[data-theme="dark"] .member-card,
[data-theme="dark"] .section,
[data-theme="dark"] form {
    background: var(--bg-secondary);
}

[data-theme="dark"] table {
    background: var(--bg-secondary);
}

[data-theme="dark"] th {
    background: var(--accent);
}

[data-theme="dark"] tr:hover {
    background: var(--bg-primary);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-text-size-adjust: 100%;
    transition: background-color 0.3s, color 0.3s;
}

header {
    background: #722F37;
    color: white;
    padding: 15px 20px;
    text-align: center;
    position: relative;
}

header h1 {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    padding: 0 50px; /* Prevent text running into hamburger menu */
}

header p {
    font-size: clamp(0.75rem, 2.5vw, 0.9rem);
    padding: 0 50px;
}

@media (min-width: 769px) {
    header h1, header p {
        padding: 0; /* Reset padding on desktop */
    }
}

/* Mobile menu toggle button */
.menu-toggle {
    display: none;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
    z-index: 1001;
}

.menu-toggle span {
    display: block;
    width: 25px;
    height: 3px;
    background: white;
    margin: 5px 0;
    transition: 0.3s;
    border-radius: 2px;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

nav {
    background: #333;
    padding: 10px;
    text-align: center;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

nav a {
    color: white;
    text-decoration: none;
    margin: 0 10px;
    padding: 10px 15px;
    display: inline-block;
    border-radius: 5px;
    transition: background 0.2s;
}

/* Desktop hover only - prevent sticky hover on touch devices */
@media (hover: hover) and (pointer: fine) {
    nav a:hover {
        background: #722F37;
    }
}

nav a.active {
    background: #722F37;
}

/* Touch device active state */
@media (hover: none) {
    nav a:active {
        background: #722F37;
    }
}

.nav-switch-view {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%) !important;
    border-radius: 4px;
    font-size: 13px;
    padding: 8px 12px !important;
}

.nav-switch-view:hover {
    background: linear-gradient(135deg, #fb8c00 0%, #ef6c00 100%) !important;
}

.nav-logout {
    margin-left: auto;
}

/* Mobile navigation */
@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }

    nav {
        padding: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s ease;
    }

    nav.active {
        max-height: none;
        height: auto;
        overflow-y: auto;
        padding: 10px;
    }

    .nav-links {
        flex-direction: column;
        gap: 0;
    }

    nav a {
        display: block;
        width: 100%;
        margin: 0;
        padding: 15px 20px;
        border-radius: 0;
        border-bottom: 1px solid #444;
        text-align: left;
    }

    nav a:last-child {
        border-bottom: none;
    }

    nav a[style*="float: right"] {
        float: none !important;
    }
}

/* Dropdown Menu */
.nav-dropdown {
    position: relative;
    display: inline-block;
}

.nav-dropdown > a {
    cursor: pointer;
}

.nav-dropdown > a::after,
.dropdown-trigger::after {
    content: ' ▾';
    font-size: 10px;
}

/* Dropdown trigger - explicit styling for touch devices */
.dropdown-trigger {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #444;
    min-width: 180px;
    border-radius: 0 0 5px 5px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 1000;
}

.dropdown-menu a {
    display: block;
    padding: 10px 15px;
    margin: 0;
    color: white;
    text-decoration: none;
    border-bottom: 1px solid #555;
}

.dropdown-menu a:last-child {
    border-bottom: none;
}

.dropdown-menu a:hover {
    background: #722F37;
    border-radius: 0;
}

/* Desktop hover dropdown - show on screens wider than mobile */
@media (min-width: 769px) {
    .nav-dropdown:hover .dropdown-menu {
        display: block;
    }
}

/* Mobile dropdown */
@media (max-width: 768px) {
    .nav-dropdown {
        display: block;
        width: 100%;
    }

    .nav-dropdown > a {
        display: block;
        width: 100%;
        padding: 15px 20px;
        border-bottom: 1px solid #444;
        text-align: left;
    }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        background: #3a3a3a;
        border-radius: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .nav-dropdown.open .dropdown-menu {
        max-height: none;
        height: auto;
        display: block;
        overflow: visible;
    }

    .dropdown-menu a {
        padding-left: 40px;
        min-height: 44px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid #444;
    }

    .dropdown-menu a:last-child {
        border-bottom: 1px solid #444;
    }

    /* Fix touch issues on mobile nav */
    nav a, .nav-dropdown > a, .dropdown-menu a {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

main {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
}

@media (max-width: 768px) {
    main {
        margin: 8px auto;
        padding: 12px;
    }

    main > *:not(:last-child) {
        margin-bottom: 14px;
    }

    main h2, main h3 {
        font-size: 18px;
    }
}

.stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .stats {
        gap: 10px;
    }
}

.stat-box {
    background: white;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    flex: 1;
    min-width: 120px;
}

@media (max-width: 768px) {
    .stat-box {
        padding: 15px;
        min-width: 80px;
    }
}

.stat-box h3 {
    font-size: clamp(28px, 6vw, 48px);
    color: #722F37;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    margin-top: 20px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

@media (max-width: 768px) {
    th, td {
        padding: 10px 8px;
        font-size: 13px;
    }
}

th {
    background: #722F37;
    color: white;
}

tr:hover {
    background: #f5f5f5;
}

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -15px;
    padding: 0 15px;
}

@media (max-width: 768px) {
    .table-responsive {
        margin: 0 -10px;
        padding: 0 10px;
    }

    .table-responsive table {
        min-width: 600px;
    }
}

.btn {
    background: #722F37;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    line-height: 1.4;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    background: #5a252c;
}

@media (max-width: 768px) {
    .btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
}

form {
    background: white;
    padding: 20px;
    border-radius: 10px;
    max-width: 500px;
}

@media (max-width: 768px) {
    form {
        padding: 15px;
        max-width: 100%;
    }
}

form label {
    display: block;
    margin-top: 15px;
    font-weight: bold;
}

form input, form select, form textarea {
    width: 100%;
    padding: 12px;
    margin-top: 5px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px; /* Prevents zoom on iOS */
}

form > button:not(.btn) {
    margin-top: 20px;
}

/* Mobile-friendly touch targets */
@media (max-width: 768px) {
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        min-width: 20px;
    }

    select {
        min-height: 44px;
    }
}

/* Responsive grid utilities */
.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

@media (max-width: 768px) {
    .grid-responsive {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* Hide on mobile */
.hide-mobile {
    /* no override needed on desktop - elements use their natural display */
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block;
    }
}

/* Responsive text utilities */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Table scroll wrapper - used for horizontal scrolling on mobile */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -10px;
    padding: 0 10px;
}

/* Stack buttons on mobile */
.btn-stack {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .btn-stack {
        flex-direction: column;
    }

    .btn-stack .btn {
        width: 100%;
        text-align: center;
    }
}

/* Mobile: prevent horizontal page overflow */
@media (max-width: 768px) {
    main {
        overflow-x: hidden;
    }

    /* Ensure inline flex/grid containers wrap on mobile */
    .flex-wrap-mobile {
        flex-wrap: wrap !important;
    }
}