/* ============ CSS VARIABLES ============ */
:root {
    /* Colors - Light Mode */
    --color-primary: #4A90A4;
    --color-primary-dark: #3A7A8E;
    --color-success: #28a745;
    --color-success-dark: #218838;
    --color-danger: #dc3545;
    --color-danger-dark: #c82333;
    --color-warning: #ffc107;
    --color-warning-dark: #e0a800;
    --color-text: #333333;
    --color-text-muted: #666666;
    --color-text-light: #888888;
    --color-background: #f5f5f5;
    --color-white: #ffffff;
    --color-border: #dddddd;
    --color-border-light: #eeeeee;

    /* Spacing */
    --spacing-xs: 0.25rem;   /* 4px */
    --spacing-sm: 0.5rem;    /* 8px */
    --spacing-md: 1rem;      /* 16px */
    --spacing-lg: 1.5rem;    /* 24px */
    --spacing-xl: 2rem;      /* 32px */

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.1);

    /* Font */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ============ DARK MODE ============ */
:root.dark-mode {
    --color-text: #e8e8e8;
    --color-text-muted: #b0b0b0;
    --color-text-light: #909090;
    --color-background: #121212;
    --color-white: #1e1e1e;
    --color-surface: #252525;
    --color-border: #3a3a3a;
    --color-border-light: #2a2a2a;
    --color-primary: #5ba8c0;
    --color-primary-dark: #4a98b0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.5);
}

/* Dark mode specific overrides */
:root.dark-mode .alert-error {
    background: #3d1a1a;
    color: #f8d7da;
    border-color: #5c2828;
}

:root.dark-mode .alert-success {
    background: #1a3d1a;
    color: #d4edda;
    border-color: #285c28;
}

:root.dark-mode .alert-warning,
:root.dark-mode .pending-users-section {
    background: #3d3520;
    color: #f0e6c8;
    border-color: #5c5030;
}

:root.dark-mode .pending-users-section h2 {
    color: #f0e6c8;
}

:root.dark-mode .section-help {
    color: #c0b898;
}

:root.dark-mode .pending-user-card {
    background: #2a2a2a;
}

:root.dark-mode input,
:root.dark-mode textarea,
:root.dark-mode select {
    background: #1a1a1a;
    color: var(--color-text);
    border-color: var(--color-border);
}

:root.dark-mode input:focus,
:root.dark-mode textarea:focus,
:root.dark-mode select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(91, 168, 192, 0.25);
}

:root.dark-mode input::placeholder,
:root.dark-mode textarea::placeholder {
    color: #666;
}

:root.dark-mode .btn-secondary {
    background: #3a3a3a;
    color: var(--color-text);
}

:root.dark-mode .btn-secondary:hover {
    background: #4a4a4a;
}

:root.dark-mode .btn-primary {
    color: #fff;
}

:root.dark-mode .btn-warning {
    background: #d4a800;
    color: #1a1a1a;
}

:root.dark-mode a {
    color: #6bc0d8;
}

:root.dark-mode a:hover {
    color: #8dd0e8;
}

/* Dark mode badges */
:root.dark-mode .badge-success {
    background: #28a745;
    color: #fff;
}

:root.dark-mode .badge-muted {
    background: #4a4a4a;
    color: #ccc;
}

:root.dark-mode .badge-pending {
    background: #5c5030;
    color: #f0e6c8;
}

/* Dark mode cards and surfaces */
:root.dark-mode .event-card,
:root.dark-mode .stat-card,
:root.dark-mode .auth-card,
:root.dark-mode .admin-form-page {
    background: var(--color-surface);
}

:root.dark-mode .event-card:hover {
    box-shadow: 0 6px 12px rgba(0,0,0,0.5);
}

/* Dark mode tables */
:root.dark-mode .data-table {
    background: var(--color-surface);
}

:root.dark-mode .data-table th {
    background: #2a2a2a;
    color: var(--color-text);
}

:root.dark-mode .data-table td {
    border-color: var(--color-border);
}

:root.dark-mode .data-table tr:hover td {
    background: #2a2a2a;
}

/* Dark mode form sections */
:root.dark-mode .form-section {
    background: #252525;
    border: 1px solid var(--color-border);
}

:root.dark-mode .user-checkboxes,
:root.dark-mode .checkbox-list {
    background: #1a1a1a;
    border-color: var(--color-border);
}

:root.dark-mode .checkbox-item:hover {
    background: #2a2a2a;
}

:root.dark-mode .checkbox-item {
    border-color: var(--color-border);
}

/* Dark mode poll/event pages */
:root.dark-mode .section,
:root.dark-mode .vote-option,
:root.dark-mode .invitee-item,
:root.dark-mode .host-item {
    background: var(--color-surface);
    border-color: var(--color-border);
}

:root.dark-mode .public-link-section {
    background: #1a3020;
    border-color: #2a5030;
}

:root.dark-mode .public-badge {
    background: #2a7040;
}

:root.dark-mode .public-link-box input {
    background: #1a1a1a;
    color: var(--color-text);
}

:root.dark-mode .converted-notice {
    background: #1a2a3d;
    border-color: #2a4060;
    color: #b0d0f0;
}

:root.dark-mode .converted-notice a {
    color: #80c0f0;
}

/* Dark mode vote results */
:root.dark-mode .vote-results-table tr.winner {
    background: #1a3020;
}

:root.dark-mode .vote-yes {
    color: #4caf50;
}

:root.dark-mode .vote-no {
    color: #f44336;
}

/* Dark mode poll status badges */
:root.dark-mode .poll-status.status-open {
    background: #1a3020;
    color: #6fcf7f;
}

:root.dark-mode .poll-status.status-closed {
    background: #3d3520;
    color: #e0c860;
}

:root.dark-mode .poll-status.status-converted {
    background: #1a2a3d;
    color: #80c0f0;
}

/* Dark mode modals */
:root.dark-mode .modal-content,
:root.dark-mode .chain-modal-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

:root.dark-mode .chain-modal-header {
    border-color: var(--color-border);
}

/* Dark mode chat */
:root.dark-mode .ultimate-chat {
    background: #1a1a1a;
}

:root.dark-mode .chat-bubble.bubble-other {
    background: #2a2a2a;
    color: var(--color-text);
}

:root.dark-mode .date-separator span {
    background: #2a2a2a;
    color: var(--color-text-muted);
}

:root.dark-mode .chat-input-area {
    background: #1e1e1e;
    border-color: var(--color-border);
}

:root.dark-mode .chat-form textarea {
    background: #252525;
    color: var(--color-text);
    border-color: var(--color-border);
}

:root.dark-mode .typing-indicator-bar {
    background: #252525;
    border-color: var(--color-border);
}

/* Dark mode attendee/assignment lists */
:root.dark-mode .attendee-list li {
    background: #2a2a2a;
}

:root.dark-mode .assignment-list li {
    border-color: var(--color-border);
}

/* Dark mode messages */
:root.dark-mode .message {
    background: #252525;
}

/* Dark mode navigation */
:root.dark-mode .nav {
    background: #1e1e1e;
    border-bottom: 1px solid var(--color-border);
}

:root.dark-mode .nav-menu {
    background: #1e1e1e;
}

:root.dark-mode .nav-link {
    color: var(--color-text);
}

:root.dark-mode .nav-link:hover {
    color: var(--color-primary);
}

/* Dark mode event header */
:root.dark-mode .event-header {
    background: #2a4050;
}

:root.dark-mode .event-description-box {
    background: #1a1a1a;
    border-color: var(--color-border);
}

:root.dark-mode .event-section {
    border-color: var(--color-border);
}

/* Dark mode tabs */
:root.dark-mode .tabs {
    border-color: var(--color-border);
}

:root.dark-mode .tab-btn {
    color: var(--color-text-muted);
}

:root.dark-mode .tab-btn.active {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Dark mode reaction badges */
:root.dark-mode .reaction-badge {
    background: #2a2a2a;
    border-color: var(--color-border);
    color: var(--color-text);
}

:root.dark-mode .reaction-badge:hover {
    background: #3a3a3a;
}

/* Dark mode emoji picker - needs solid background */
:root.dark-mode .emoji-picker {
    background: #2a2a2a;
    border: 2px solid #555;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

:root.dark-mode .emoji-btn:hover {
    background: #3a3a3a;
    border-radius: var(--radius-sm);
}

/* Dark mode scroll button */
:root.dark-mode .scroll-to-bottom {
    background: #2a2a2a;
    border-color: var(--color-border);
    color: var(--color-text);
}

/* Dark mode empty state */
:root.dark-mode .empty-state {
    color: var(--color-text-muted);
}

/* Dark mode small text helpers */
:root.dark-mode small,
:root.dark-mode .form-group small {
    color: var(--color-text-muted);
}

/* Dark mode form notice (yellow warning boxes) */
:root.dark-mode .form-notice {
    background: #3d3520;
    border-color: #5c5030;
    color: #f0e6c8;
}

:root.dark-mode .form-notice strong {
    color: #ffe082;
}

/* ============ RESET & BASE ============ */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-background);
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--spacing-md) 0;
    line-height: 1.2;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p { margin: 0 0 var(--spacing-md) 0; }
a { color: var(--color-primary); }

/* ============ NAVIGATION ============ */
.nav {
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    max-width: 1200px;
    margin: 0 auto;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--color-primary);
    text-decoration: none;
}

.nav-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--spacing-sm);
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    align-items: center;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--color-text);
    transition: transform 0.2s;
}

.nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-white);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-md);
}

.nav-menu.active {
    display: block;
}

.nav-link {
    display: block;
    padding: var(--spacing-md);
    color: var(--color-text);
    text-decoration: none;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-link:hover {
    color: var(--color-primary);
}

@media (min-width: 768px) {
    .nav-toggle {
        display: none;
    }

    .nav-menu {
        display: flex;
        position: static;
        box-shadow: none;
        padding: 0;
        gap: var(--spacing-md);
    }

    .nav-link {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* ============ MAIN CONTENT ============ */
.main {
    padding: var(--spacing-md);
    min-height: calc(100vh - 60px);
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .main {
        padding: var(--spacing-xl);
    }
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s, transform 0.1s;
    min-height: 44px;
    min-width: 44px;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-success {
    background: var(--color-success);
    color: var(--color-white);
}
.btn-success:hover { background: var(--color-success-dark); }

.btn-danger {
    background: var(--color-danger);
    color: var(--color-white);
}
.btn-danger:hover { background: var(--color-danger-dark); }

.btn-warning {
    background: var(--color-warning);
    color: var(--color-text);
}
.btn-warning:hover { background: var(--color-warning-dark); }

.btn-secondary {
    background: var(--color-border);
    color: var(--color-text);
}
.btn-secondary:hover { background: #cccccc; }

.btn-small {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.875rem;
    min-height: 36px;
}

.btn-large {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: 1.125rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* ============ FORMS ============ */
.form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-group label {
    font-weight: 500;
    color: var(--color-text);
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    min-height: 44px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 164, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group small {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.form-static {
    padding: var(--spacing-sm) 0;
    margin: 0;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

@media (min-width: 768px) {
    .form-row {
        flex-direction: row;
    }

    .form-row .form-group {
        flex: 1;
    }

    .form-row .flex-grow {
        flex: 2;
    }
}

.form-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    min-height: 44px;
}

.checkbox-item:hover {
    background: var(--color-background);
}

.checkbox-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: auto;
}

.checkbox-item small {
    color: var(--color-text-muted);
    margin-left: auto;
}

/* ============ ALERTS ============ */
.alert {
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* ============ BADGES ============ */
.badge {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: var(--color-success); color: white; }
.badge-danger { background: var(--color-danger); color: white; }
.badge-warning { background: var(--color-warning); color: var(--color-text); }
.badge-muted { background: var(--color-border); color: var(--color-text-muted); }

.badge-large {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
}

/* ============ AUTH PAGES ============ */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: var(--spacing-xl);
}

.auth-card {
    background: var(--color-white);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-lg);
}

.auth-help {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-top: var(--spacing-lg);
    margin-bottom: 0;
}

/* ============ HERO ============ */
.hero {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-md);
}

.hero h1 {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-md);
    color: var(--color-primary);
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-xl);
}

.hero-actions {
    margin-bottom: var(--spacing-xl);
}

.hero-note {
    color: var(--color-text-light);
    font-size: 0.875rem;
}

/* ============ DASHBOARD ============ */
.dashboard h1,
.admin-dashboard h1,
.admin-users h1 {
    margin-bottom: var(--spacing-lg);
}

.dashboard-header {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

@media (min-width: 768px) {
    .dashboard-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .dashboard-header h1 {
        margin-bottom: 0;
    }
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--color-white);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-primary);
}

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

/* ============ TABS ============ */
.tabs {
    display: flex;
    gap: var(--spacing-xs);
    border-bottom: 2px solid var(--color-border);
    margin-bottom: var(--spacing-lg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: var(--spacing-md);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-btn .badge {
    font-size: 0.625rem;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============ EVENT CARDS ============ */
.event-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.event-card {
    display: block;
    background: var(--color-white);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, transform 0.2s;
}

.event-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.event-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.event-card-header h3 {
    margin: 0;
    color: var(--color-text);
}

.event-card .event-date {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: 0;
}

.event-card .event-description {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: var(--spacing-sm) 0 0 0;
}

.event-card .event-location-small {
    color: var(--color-text-light);
    font-size: 0.875rem;
    margin: var(--spacing-xs) 0 0 0;
}

.event-card-past {
    opacity: 0.7;
}

/* ============ EVENT PAGE ============ */
.event-page {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.event-header {
    background: var(--color-primary);
    color: var(--color-white);
    padding: var(--spacing-xl);
    text-align: center;
}

.event-header h1 {
    margin-bottom: var(--spacing-sm);
}

.event-date-large {
    font-size: 1.125rem;
    opacity: 0.9;
    margin-bottom: var(--spacing-md);
}

.rsvp-buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
    flex-wrap: wrap;
}

.rsvp-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.rsvp-change {
    opacity: 0.8;
}

.event-description-box {
    padding: var(--spacing-lg);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border-light);
}

.event-section {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--color-border-light);
}

.event-section:last-child {
    border-bottom: none;
}

.event-section h2 {
    margin-bottom: var(--spacing-md);
    color: var(--color-text);
}

.event-location {
    font-size: 1.125rem;
    margin: 0;
}

.event-private-notice {
    padding: var(--spacing-xl);
    text-align: center;
}

/* ============ ATTENDEE LIST ============ */
.attendee-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.attendee-list li {
    background: var(--color-background);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
}

/* ============ ASSIGNMENTS ============ */
.assignment-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.assignment-list li {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
}

.assignment-list li:last-child {
    border-bottom: none;
}

.assignment-notes {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.assignment-form {
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--color-border-light);
}

/* ============ MESSAGES ============ */
.message-form {
    margin-bottom: var(--spacing-lg);
}

.message-form textarea {
    width: 100%;
    padding: var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 80px;
    margin-bottom: var(--spacing-md);
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.message {
    background: var(--color-background);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.message-date {
    color: var(--color-text-light);
    font-size: 0.75rem;
}

.message-content {
    margin: 0;
    white-space: pre-wrap;
}

.message-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
}

/* ============ ULTIMATE CHAT ============ */
.ultimate-chat {
    display: flex;
    flex-direction: column;
    height: 70vh;
    min-height: 400px;
    max-height: 800px;
    background: var(--color-background);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    padding: var(--spacing-md);
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 100%;
}

/* Date separators */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md) 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.date-separator span {
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Chat bubbles */
.chat-bubble {
    max-width: 75%;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    animation: none;
}

.chat-bubble.bubble-own {
    align-self: flex-end;
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.bubble-other {
    align-self: flex-start;
    background: var(--color-surface);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Bubble grouping */
.chat-bubble.bubble-first {
    margin-top: var(--spacing-sm);
}

.chat-bubble.bubble-own.bubble-first {
    border-top-right-radius: 18px;
}

.chat-bubble.bubble-other.bubble-first {
    border-top-left-radius: 18px;
}

.chat-bubble.bubble-own:not(.bubble-first) {
    border-top-right-radius: 4px;
}

.chat-bubble.bubble-other:not(.bubble-first) {
    border-top-left-radius: 4px;
}

.chat-bubble.bubble-own.bubble-last {
    border-bottom-right-radius: 18px;
    margin-bottom: var(--spacing-xs);
}

.chat-bubble.bubble-other.bubble-last {
    border-bottom-left-radius: 18px;
    margin-bottom: var(--spacing-xs);
}

/* Bubble content */
.bubble-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 4px;
    text-transform: capitalize;
}

.bubble-content {
    white-space: pre-wrap;
    line-height: 1.4;
}

.bubble-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-bubble:hover .bubble-meta {
    opacity: 1;
}

.bubble-time {
    font-size: 0.65rem;
    opacity: 0.7;
}

.bubble-action-btn {
    background: none;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
}

.bubble-action-btn:hover {
    opacity: 1;
    background: rgba(0,0,0,0.1);
}

.bubble-own .bubble-action-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Reply quote in bubble */
.bubble-reply-quote {
    background: rgba(0,0,0,0.1);
    border-left: 2px solid currentColor;
    padding: 4px 8px;
    margin-bottom: 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.bubble-own .bubble-reply-quote {
    background: rgba(255,255,255,0.15);
    border-left-color: rgba(255,255,255,0.5);
}

.bubble-reply-quote:hover {
    background: rgba(0,0,0,0.15);
}

.bubble-own .bubble-reply-quote:hover {
    background: rgba(255,255,255,0.25);
}

.reply-quote-author {
    font-size: 0.7rem;
    font-weight: 600;
    display: block;
}

.reply-quote-content {
    font-size: 0.75rem;
    opacity: 0.8;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reactions */
.bubble-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.reaction-badge {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.reaction-badge:hover {
    background: var(--color-background);
    transform: scale(1.1);
}

.reaction-badge.reaction-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

/* Bubble animation */
.bubble-animate-in {
    animation: bubbleSlideIn 0.3s ease-out forwards;
}

@keyframes bubbleSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scroll to bottom button */
.scroll-to-bottom {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 20;
}

.scroll-to-bottom:hover {
    background: var(--color-primary);
    color: white;
    transform: scale(1.1);
}

.scroll-arrow {
    font-size: 1.2rem;
    font-weight: bold;
}

/* New messages indicator */
.new-messages-indicator {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-primary);
    color: white;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 20;
    animation: bounceIn 0.3s ease-out;
}

@keyframes bounceIn {
    0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
    50% { transform: translateX(-50%) scale(1.05); }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Typing indicator bar */
.typing-indicator-bar {
    padding: 8px 16px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-style: italic;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

/* Chat input area */
.chat-input-area {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--spacing-sm) var(--spacing-md);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
}

.chat-form textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    max-height: 120px;
    background: var(--color-background);
}

.chat-form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Reply preview (in chat input) */
.reply-preview {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-background);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-sm);
    margin-bottom: var(--spacing-sm);
}

.reply-preview-content {
    flex: 1;
    min-width: 0;
}

.reply-preview-label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-primary);
}

.reply-preview-text {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-preview-cancel {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--spacing-xs);
    line-height: 1;
}

.reply-preview-cancel:hover {
    color: var(--color-danger);
}

/* Emoji picker */
.emoji-picker {
    position: fixed;
    background: #ffffff;
    border: 2px solid #ccc;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    padding: 8px;
    gap: 4px;
    z-index: 1001; /* Above snowfall (1000) and other overlays */
}

.emoji-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.emoji-btn:hover {
    background: var(--color-background);
    transform: scale(1.2);
}

/* ============ CHAIN MODAL ============ */
.chain-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.chain-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chain-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.chain-modal-content {
    position: relative;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chain-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--color-border);
}

.chain-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.chain-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    line-height: 1;
    padding: var(--spacing-xs);
}

.chain-modal-close:hover {
    color: var(--color-text);
}

.chain-modal-body {
    padding: var(--spacing-md);
    overflow-y: auto;
}

.chain-message {
    padding: var(--spacing-md);
    background: var(--color-background);
    border-radius: var(--radius-md);
}

.chain-message-current {
    background: var(--color-primary);
    color: white;
}

.chain-message-own:not(.chain-message-current) {
    background: rgba(74, 144, 164, 0.15);
}

.chain-message-current .chain-message-date {
    color: rgba(255, 255, 255, 0.8);
}

.chain-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xs);
}

.chain-message-date {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.chain-message-content {
    margin: 0;
    white-space: pre-wrap;
}

.chain-connector {
    display: flex;
    justify-content: center;
    padding: var(--spacing-sm) 0;
}

.chain-connector::before {
    content: '';
    width: 2px;
    height: 20px;
    background: var(--color-border);
}

.chain-modal-body .loading,
.chain-modal-body .error {
    text-align: center;
    color: var(--color-text-muted);
    padding: var(--spacing-lg);
}

/* Empty state in chat */
.chat-messages .empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
}

/* Mobile adjustments for chat */
@media (max-width: 600px) {
    .ultimate-chat {
        height: 75vh;
        min-height: 400px;
        max-height: none;
    }

    .chat-bubble {
        max-width: 85%;
    }

    .bubble-meta {
        opacity: 1;
    }
}

/* ============ iOS/IPHONE SPECIFIC FIXES ============ */
/* Prevent bouncy scrolling and jumping on iOS */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific */
    .ultimate-chat {
        /* Use svh for better iOS address bar handling, but keep it tall */
        height: 70svh;
        min-height: 350px;
        max-height: none;
    }

    .chat-container {
        /* Enable momentum scrolling */
        -webkit-overflow-scrolling: touch;
        /* Contain scroll within element */
        overscroll-behavior: contain;
        /* Prevent scroll chaining to parent */
        overscroll-behavior-y: contain;
    }

    /* Fix input zoom on iOS */
    .chat-form textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
}

/* General touch device improvements */
@media (hover: none) and (pointer: coarse) {
    .ultimate-chat {
        /* Taller chat on touch devices for better message viewing */
        height: 70vh;
        min-height: 350px;
        max-height: none;
    }

    .chat-container {
        /* Smooth scrolling with momentum */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        overscroll-behavior-y: contain;
        scroll-behavior: auto; /* Disable smooth scroll on touch for better performance */
    }

    /* Larger touch targets */
    .bubble-action-btn {
        min-width: 32px;
        min-height: 32px;
        padding: 6px 8px;
    }

    .emoji-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Always show meta on touch devices */
    .bubble-meta {
        opacity: 1;
    }

    /* Better tap response */
    .chat-bubble,
    .reaction-badge,
    .bubble-action-btn,
    .scroll-to-bottom,
    .new-messages-indicator {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Prevent text selection during scroll */
    .chat-messages {
        -webkit-user-select: none;
        user-select: none;
    }

    .bubble-content {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* Keyboard spacer - dynamic, controlled by JS */
.chat-keyboard-spacer {
    height: 0;
    transition: height 0.3s ease;
    pointer-events: none;
}

.chat-keyboard-spacer.active {
    height: 50vh;
}

/* iOS input focus fixes */
@media (max-width: 768px) {
    /* Prevent viewport jump when focusing input - 16px prevents iOS zoom */
    .chat-form textarea {
        font-size: 16px;
    }

    .chat-form textarea:focus {
        font-size: 16px;
    }

    /* Modal adjustments for mobile */
    .chain-modal-content {
        max-height: 70vh;
        margin: var(--spacing-md);
    }

    /* Emoji picker positioning is handled by JavaScript for better accuracy */
}

/* ============ DATA TABLE ============ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-white);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
    padding: var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
}

.data-table th {
    background: var(--color-background);
    font-weight: 600;
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Mobile table scroll */
@media (max-width: 767px) {
    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============ ADMIN EVENT DETAIL ============ */
.admin-event-detail .event-header {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    background: var(--color-white);
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

@media (min-width: 768px) {
    .admin-event-detail .event-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.event-actions {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.invite-form {
    margin-top: var(--spacing-lg);
}

/* ============ UTILITY CLASSES ============ */
.inline-form {
    display: inline;
}

.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: var(--spacing-xl);
}

.error-page {
    text-align: center;
    padding: var(--spacing-xl);
}

.error-page h1 {
    color: var(--color-danger);
}

/* ============ ADMIN FORM PAGE ============ */
.admin-form-page {
    background: var(--color-white);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.admin-form-page h1 {
    margin-bottom: var(--spacing-xl);
}

/* ============ DARK MODE TOGGLE ============ */
.dark-mode-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--spacing-sm);
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    font-size: 1.25rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.dark-mode-toggle:hover {
    background: var(--color-background);
}

.dark-mode-toggle .icon-sun,
.dark-mode-toggle .icon-moon {
    display: none;
}

/* Show sun in dark mode (to switch to light) */
:root.dark-mode .dark-mode-toggle .icon-sun {
    display: inline;
}

/* Show moon in light mode (to switch to dark) */
:root:not(.dark-mode) .dark-mode-toggle .icon-moon {
    display: inline;
}

/* ============ RICH TEXT DISPLAY ============ */
.rich-text {
    word-wrap: break-word;
    line-height: 1.6;
}

.rich-text p {
    margin: 0 0 var(--spacing-sm) 0;
}

.rich-text p:last-child {
    margin-bottom: 0;
}

/* Rich text editor content styling */
.rich-text h1,
.rich-text h2,
.rich-text h3 {
    margin-top: var(--spacing-md);
}

.rich-text ul,
.rich-text ol {
    padding-left: var(--spacing-lg);
    margin: var(--spacing-sm) 0;
}

.rich-text blockquote {
    border-left: 3px solid var(--color-primary);
    padding-left: var(--spacing-md);
    margin: var(--spacing-sm) 0;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Rich text images - clickable for lightbox */
.rich-text img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: opacity 0.2s;
}

.rich-text img:hover {
    opacity: 0.9;
}

/* ============ LIGHTBOX ============ */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    cursor: zoom-out;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-image {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.lightbox-overlay.active .lightbox-image {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* TinyMCE editor container styling */
.tinymce-container {
    border-radius: var(--radius-md);
    overflow: hidden;
}

.tox-tinymce {
    border-radius: var(--radius-md) !important;
    border-color: var(--color-border) !important;
}

:root.dark-mode .tox .tox-edit-area__iframe {
    background-color: #1a1a1a !important;
}

:root.dark-mode .tox-tinymce {
    border-color: var(--color-border) !important;
}
