/* ==========================================================================
    Google Fonts Import (use DM Sans for a cleaner responsive UI)
    ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap');

/* ==========================================================================
   CSS Variables for Theming
   ========================================================================== */
:root {
    --primary-color: #007bff; /* Default Blue */
    --primary-font-color: #ffffff;
    --background-color: #002952;
    --text-color: #343a40;
    --border-color: #dee2e6;
    --slot-text-color: #495057;
    --hover-color: #f1f3f5;
    --row-shade: #82B5E8; /* default alternate row shade */
    --glass-bg: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.18);

    /* Aliases inspired by OG example for smoother theming */
    --primary-light: #3498db;
    --primary-dark: #154360;
}

/* Theme Presets */
.theme-blue { --primary-color: #007bff; --row-shade: #82B5E8; }
.theme-yellow { --primary-color: #ffc107; --row-shade: #F6E6A5; }
.theme-green { --primary-color: #28a745; --row-shade: #C8E6C9; }
.theme-red { --primary-color: #dc3545; --row-shade: #F8C6C6; }
.theme-orange { --primary-color: #fd7e14; --row-shade: #FAD7C1; }

/* ==========================================================================
   Global Styles
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'DM Sans', sans-serif;
    /* Purple-tinged gradient background to make glass effect pop */
    /*background: radial-gradient(circle at 10% 10%, rgba(0, 20, 39, 0.18), transparent 15%),
                linear-gradient(180deg, #1b122b 0%, #4a2a75 45%, #243b55 100%);*/
    background: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    font-size: 15px;
    touch-action: auto; /* allow pinch-zoom on mobile */
    min-height: 100vh;
    display: block; /* stack content vertically so footer sits below the table */
    padding-top: 24px; /* give some top breathing room */
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

/* Centered white card for sheet content to match sample */
.sheet-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px) saturate(120%);
    -webkit-backdrop-filter: blur(10px) saturate(120%);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.2);
    margin: 28px auto;
    max-width: 90%; /* Changed from 1100px to percentage for better spacing */
    overflow-x: auto;
    display: block;
}

.sheet-card.sheet-meta-card {
    background: #ffffff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.view-toggle-bar {
    max-width: 90%;
    margin: 12px auto 0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.view-toggle-bar .btn {
    min-width: 180px;
    background-color: #ffffff;
    color: #1f2937;
    border: 1px solid rgba(15, 23, 42, 0.15);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.view-toggle-bar .import-notes-group {
    position: relative;
}

.view-toggle-bar .import-notes-group .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Glass effect variant for the table area inspired by sample code */
.sheet-card.glass {
    background: linear-gradient(rgba(255,255,255,0.6), rgba(255,255,255,0.3));
    backdrop-filter: blur(10px) saturate(120%);
    -webkit-backdrop-filter: blur(10px) saturate(120%);
    border: 1px solid rgba(255,255,255,0.35);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.2);
}

@media (max-width: 768px) {
    .sheet-card {
        margin: 12px 8px;
        padding: 12px;
        border-radius: 8px;
        overflow-x: auto; /* Allow horizontal scrolling */
        max-width: 95%; /* Increased max-width for better mobile experience */
    }
    .sheet-card + .sheet-card {
        margin-top: 22px !important;
    }
    .table-container {
        padding: 8px 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }
    .volunteer-table {
        width: 100%; /* Allow table to be wider than container */
        min-width: 100%;
        table-layout: auto;
        font-size: 0.95rem;
        word-break: break-word;
    }
    .volunteer-table th, .volunteer-table td {
        padding: 7px 6px;
    }
    
    .slot {
        display: block;
        margin-bottom: 6px;
        font-size: 0.95rem;
    }
    .cell-controls {
        top: 4px;
        right: 4px;
    }
}

/* Make the table body responsive with a max-height similar to the sample
   Use calc to subtract header controls/margins. Adjust as needed per layout. */
.table-container {
    /* default comfortable height on desktop - feel free to tweak */
    max-height: calc(89vh - 6rem); /* keep header and other UI visible */
    overflow: auto; /* scroll inside the table container */
    background: var(--glass-bg);
    backdrop-filter: blur(8px) saturate(110%);
    -webkit-backdrop-filter: blur(8px) saturate(110%);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    margin: 0 auto; /* center the table area */
    padding: 0 16px 16px; /* pull table upward while keeping side spacing */
    max-width: 100%; /* changed from 920px to allow full width */
}

body.full-table-view {
    --table-scale: 0.9;
}

body.full-table-view .sheet-card {
    max-width: min(100%, 1280px);
    padding: 20px 0 16px;
    margin: 18px 4px;
}

body.full-table-view .container {
    padding-left: 4px;
    padding-right: 4px;
}

body.full-table-view .view-toggle-bar {
    max-width: 100%;
    justify-content: flex-start;
    margin-left: 0;
}

body.full-table-view .sheet-card.glass,
body.full-table-view .table-container {
    overflow: visible;
}

body.full-table-view .sheet-card.glass {
    background: transparent;
    border: none;
    box-shadow: none;
}

body.full-table-view .table-container {
    max-width: 100%;
    width: 100%;
    padding: 0;
    text-align: left;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow-x: hidden;
}

body.full-table-view #sheetContainer {
    display: block;
    transform-origin: top left;
    transform: scale(var(--table-scale, 1));
    width: calc(100% / var(--table-scale, 1));
    max-width: 1280px;
    margin: 0;
    padding: 0 18px 18px 0;
}

body.full-table-view .volunteer-table th,
body.full-table-view .volunteer-table td {
    padding: 10px 6px;
}

body.full-table-view textarea.slot,
body.full-table-view .row-header-input,
body.full-table-view .column-header-input {
    font-size: 0.78rem;
}

/* Apply the 'glass' look specifically to the table container when desired */
.table-container.glass {
    background: linear-gradient(rgba(255,255,255,0.5), rgba(255,255,255,0.2));
    backdrop-filter: blur(8px) saturate(110%);
    -webkit-backdrop-filter: blur(8px) saturate(110%);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
}

/* Custom scrollbar styling */
.table-container::-webkit-scrollbar {
    width: 0.5rem;
    height: 0.5rem;
}

.table-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0.5rem;
}

.table-container::-webkit-scrollbar-thumb {
    border-radius: 0.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    visibility: hidden;
}

.table-container:hover::-webkit-scrollbar-thumb {
    visibility: visible;
}

/* Make table columns equal width and the table appear compact */
.volunteer-table {
    width: 100%;
    table-layout: fixed; /* distribute columns equally */
    border-collapse: collapse;
}
.volunteer-table th,
.volunteer-table td {
    /* allow text to wrap to next line when column is narrower */
    overflow-wrap: anywhere;
    word-wrap: break-word;
    white-space: normal; /* enable wrapping */
    vertical-align: top; /* align cell content to top */
    border: none;
    padding: 12px 8px;
}

/* Remove left padding from event columns to eliminate gap */
.volunteer-table td:nth-child(2),
.volunteer-table td:nth-child(3),
.volunteer-table td:nth-child(4) {
    padding-left: 6px; /* reasonable left padding for event columns */
}

/* Reduce visual weight on mobile so the table appears smaller and centered */
@media (max-width: 768px) {
    .sheet-card {
        max-width: 95%; /* keep card narrower */
    }
    .table-container {
        max-width: 100%; /* increased from calc(100% - 144px) */
        padding: 12px;
    }
    .volunteer-table th, .volunteer-table td {
        padding: 8px 6px;
        padding-left: 0; /* no left padding to eliminate gap */
        font-size: 0.88rem;
    }
}

@media (max-width: 420px) {
    .sheet-card {
        max-width: calc(100% - 32px);
        margin: 12px auto;
        padding: 12px;
    }
    .table-container {
        max-width: calc(100% - 32px); /* increased from calc(100% - 96px) */
        padding: 8px;
        border-radius: 6px;
    }
    .volunteer-table th, .volunteer-table td {
        padding: 6px 4px;
        font-size: 0.82rem;
    }
}

/* Ensure the card sits above the page content and is visible on narrow screens */
@media (max-width: 480px) {
    .sheet-card {
        margin: 8px 4px;
        padding: 8px;
        border-radius: 6px;
        overflow-x: auto; /* Allow horizontal scrolling */
        max-width: 95%; /* increased max-width */
    }
    .sheet-card + .sheet-card {
        margin-top: 22px !important;
    }
    .table-container {
        padding: 8px 0;
        margin: 0 auto;
        display: block;
        justify-content: flex-start; /* Left-align table for horizontal scroll */
        align-items: center;
        width: 100%;
        max-width: 100%;
    }
    .volunteer-table {
        width: 100%; /* Allow table to be wider than container */
        min-width: 100%;
    }
    .volunteer-table th, .volunteer-table td { 
        padding: 6px 4px; 
        font-size: 0.9rem;
    }
}

/* ==========================================================================
   Header & Footer
   ========================================================================== */
.main-header {
    background-color: var(--primary-color);
    color: var(--primary-font-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.main-header h1 {
    font-size: 1.9rem;
    font-weight: 700;
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.main-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    margin-top: 40px;
    font-size: 0.9rem;
    color: #6c757d;
    gap: 6px;
}

.main-footer a {
    color: #6c757d;
    text-decoration: none;
    font-weight: 600;
}

.main-footer a:hover,
.main-footer a:focus {
    color: #4b5563;
    text-decoration: underline;
}

.main-footer .footer-row {
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.footer-testing {
    background: #ffc107;
    color: #1f2937;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.75rem;
}

/* Admin header inline edit inputs */
.column-header-input {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--primary-font-color);
    box-shadow: none;
    transition: box-shadow 150ms ease, border-color 150ms ease;
}
.column-header-input:focus {
    outline: none;
    box-shadow: inset 0 -2px 0 rgba(255,255,255,0.6);
}
.column-header-input.saved {
    box-shadow: 0 0 0 3px rgba(40,167,69,0.12);
    border-color: #28a745;
}

.column-header-input::placeholder,
.row-header-input::placeholder {
    color: rgba(73, 80, 87, 0.55);
}

@media (max-width: 768px) {
    .column-header-input {
        padding: 5px 7px;
        font-size: 0.88rem;
    }
}

@media (max-width: 480px) {
    .column-header-input {
        padding: 4px 6px;
        font-size: 0.8rem;
    }
}

/* Visual feedback when header input exceeds maxlength and we trim it */
.column-header-input.header-too-long {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220,53,69,0.12) !important;
}

/* Inline conflict banner for slot edit conflicts */
.conflict-banner {
    position: absolute;
    left: 8px;
    right: 8px;
    top: -42px;
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #664d03;
    padding: 8px 10px;
    border-radius: 6px;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.06);
    z-index: 50;
}
.conflict-banner .btn {
    padding: 6px 8px;
    font-size: 0.85rem;
}

/* Better mobile handling for the inline conflict banner */
@media (max-width: 480px) {
    .conflict-banner {
        position: static; /* flow with document so it doesn't overlap or get cut off */
        margin: 6px 0 8px 0;
        top: auto;
        left: auto;
        right: auto;
        width: 100%;
        box-shadow: none;
        padding: 10px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .conflict-banner span { font-size: 0.95rem; }
    .conflict-banner .btn { width: 100%; padding: 10px; font-size: 1rem; }
}

/* Small remote-update indicator for slots where a remote update couldn't be applied */
.remote-update-pending {
    position: relative;
}
.remote-update-pending::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 8px;
    width: 8px;
    height: 8px;
    background: #ffc107;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(255,193,7,0.12);
}

/* Conflict modal styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(12,16,20,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}
.modal-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 16px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.modal-card h3 { margin-bottom: 8px; font-size: 1.05rem; }
.modal-card .modal-server-value {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 12px;
    color: #333;
    min-height: 36px;
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

@media (max-width: 480px) {
    .modal-card { padding: 12px; }
    .modal-card h3 { font-size: 1rem; }
    .modal-server-value { font-size: 0.95rem; }
}

/* Alert modal variant (red) */
.modal-overlay.modal-alert .modal-card {
    border: 1px solid #dc3545;
}
.modal-overlay.modal-alert .modal-card h3 { color: #7f1d1d; }
.modal-overlay.modal-alert .modal-server-value { background: #fff1f0; border-color: #f5c2c7; color: #7f1d1d; }
.modal-overlay.modal-alert .btn-danger { background: #dc3545; color: white; }

/* Responsive: Header & Footer
   Place responsive adjustments for the header/footer immediately after their block
   so related rules are colocated for easier maintenance. */
@media (max-width: 768px) {
    .main-header {
        padding: 1rem;
    }
    .main-header h1 {
        font-size: 1.5rem;
        width: 100%;
        margin-bottom: 10px;
    }
}

@media (max-width: 480px) {
    .main-header h1 {
        font-size: 1.25rem;
    }
}

/* ==========================================================================
   Buttons & Form Elements
   ========================================================================== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif; /* Changed from Merriweather to match body font */
    font-size: 0.9rem;
    transition: background-color 0.2s, color 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--primary-font-color);
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-accent {
    background-color: #ffffff;
    color: #1f2937;
    border: 1px solid rgba(15, 23, 42, 0.15);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.btn-accent:hover,
.btn-accent:focus {
    background-color: #f1f5f9;
    color: #1f2937;
    border-color: rgba(15, 23, 42, 0.25);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.slot:last-child {
    margin-bottom: 0;
}

.slot:focus {
    outline: none; /* Remove default outline */
    border-color: var(--primary-color); /* Use theme color for border */
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25); /* Glowing effect with theme color */
    background-color: #ffffff;
}

.sheet-list {
    list-style: none;
}

.sheet-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.sheet-info h3 {
    margin-bottom: 5px;
}

.sheet-info p {
    font-size: 0.9rem;
    color: #6c757d;
}

.sheet-actions {
    display: flex;
    gap: 10px;
}

/* ==========================================================================
   Sheet View (sheet.php)
   ========================================================================== */
.sheet-header {
    margin-bottom: 16px;
    text-align: left;
}

.sheet-title {
    font-size: 1.18rem;
    margin-bottom: 8px;
    text-align: left;
}

.sheet-description {
    font-size: 0.96rem;
    color: #4b5560;
    margin-bottom: 10px;
    line-height: 1.35;
    white-space: pre-wrap;
    text-align: left;
}

.sheet-card .sheet-title { color: #1f2937; }
.sheet-card .sheet-description { color: #374151; }
.sheet-card + .sheet-card {
    margin-top: 22px !important;
}

@media (max-width: 480px) {
    .sheet-card .sheet-title { font-size: 1.4rem; }
    .sheet-card .sheet-description { font-size: 0.92rem; }
}

/* Table Controls */
.table-controls {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Volunteer Table */
.table-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    border: none;
    border-radius: 8px;
    background-color: transparent;
    display: block;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

/* When there are exactly 3 columns, force equal widths for a balanced layout */
.three-equal-cols .volunteer-table {
    table-layout: fixed;
}
.three-equal-cols .volunteer-table th,
.three-equal-cols .volunteer-table td {
    width: 33.3333%;
}

@media (max-width: 992px) {
    .three-equal-cols .volunteer-table th,
    .three-equal-cols .volunteer-table td {
        width: auto; /* allow narrower widths on smaller screens */
    }
}

/* ========================================================================== */
/* Added Responsive Table Width for Small Screens - Keeps all columns visible */
/* ========================================================================== */

/* Make table always scrollable horizontally on mobile, and ensure all columns are visible */
@media (max-width: 992px) {
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Let the table size itself to its content but cap width so cells wrap when
       content is excessively wide. This keeps the table narrow when content is
       small and prevents a perpetual horizontal scrollbar on smaller screens. */
    .volunteer-table {
        width: 100%;
        max-width: 1200px; /* cap overall table width */
        font-size: 0.85rem;
        table-layout: auto;
    }
    .volunteer-table th, .volunteer-table td {
        padding: 8px 6px;
    }
}

@media (max-width: 768px) {
    /* Allow the table to shrink below previous min-width to enable pinch-zooming on very narrow devices.
       We still prefer horizontal scroll when content overflows, but do not force a large min-width. */
    .table-container {
        overflow-x: auto; /* still allow horizontal scrolling when needed */
        -webkit-overflow-scrolling: touch;
        /* do not set touch-action here; some values (e.g. pan-*) block pinch-zoom
           on certain mobile browsers. Leave default (auto) so pinch gestures work. */
    }

    .volunteer-table {
        min-width: 100%; /* allow table to match viewport width */
        width: max-content; /* Allow table to be wider than container for horizontal scroll */
        table-layout: auto;
        font-size: 0.85rem;
        word-break: break-word;
    }

    .volunteer-table th, .volunteer-table td {
        padding: 7px 6px;
    }

    .slot {
        /* keep .slot lightweight on small screens; actual input/textarea control padding is handled by input.slot/textarea.slot */
        font-size: 0.95rem;
    }

    .cell-controls {
        top: 4px;
        right: 4px;
    }
}

@media (max-width: 480px) {
    /* Keep the table readable on small screens: prefer horizontal scroll rather than squashing columns */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px; /* slightly reduce outer padding */
    }

    .volunteer-table {
        min-width: 520px; /* keep a reasonable minimum table width to avoid extreme collapsing */
        width: 100%;
        font-size: 0.86rem;
        table-layout: auto;
    }

    .volunteer-table th, .volunteer-table td {
        padding: 6px 8px;
    }

    /* Make inputs and textareas easier to tap and consistently sized */
    textarea.slot, input.slot {
        min-width: 120px;
        width: auto;
        font-size: 0.88rem;
        padding: 5px 7px;
        min-height: 36px;
    }

    .slot-wrapper { gap: 6px; align-items: center; }
    .slot-num { flex: 0 0 20px; font-size: 0.82rem; }

    .cell-controls button { width: 28px; height: 28px; font-size: 13px; }
}

/* Expand-page mode: let the table expand the page width so users can pinch-zoom out
   to see the entire table. This is toggled by JS via adding/removing the
   `expand-page` class on `.table-container`. */
.table-container.expand-page {
    overflow-x: auto;
}
.table-container.expand-page .volunteer-table {
    /* In expand-page mode we simply allow the table to grow to its content up
       to the same max-width. Avoid forcing a fixed oversized width which can
       cause layout issues. */
    width: 100%;
    max-width: 1600px; /* allow a larger cap when explicitly expanded */
}

/* Toggle button styling */
.table-view-toggle { display:none; }
.table-view-toggle.active { display:none; }

.volunteer-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    background: transparent;
}

.volunteer-table th {
    border: none;
    padding: 12px 10px;
    text-align: left;
    vertical-align: middle;
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--primary-color);
    color: var(--primary-font-color);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap; /* keep header labels on one line */
    overflow: hidden;
    text-overflow: ellipsis;
}

.volunteer-table th:hover {
    background-color: var(--primary-dark);
    color: var(--primary-font-color);
}

.volunteer-table td.primary-col {
    background-color: rgba(0, 36, 72, 0.8);
    font-weight: 400;
    width: 220px;
    color: #343a40;
    white-space: normal; /* Allow text wrapping */
    word-wrap: break-word;
    font-size: 0.82rem; /* match slot text size */
    min-width: 140px; /* prevent column collapsing on small screens */
}

/* Primary column stacked layout (date on top, note slot below) */
.volunteer-table td.primary-col .primary-col-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.volunteer-table td.primary-col .primary-col-date {
    font-weight: 400;
    color: #343a40;
    white-space: normal; /* Allow text wrapping */
    word-wrap: break-word;
    font-size: inherit; /* inherit from primary column to match slot text */
}

.volunteer-table td.primary-col .primary-col-note {
    font-size: 0.95rem;
    color: var(--slot-text-color);
    background: transparent;
    border: none;
}

/* Refined input styling inspired by the OG example: make inputs feel native and clean */
input.slot {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 8px;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

input.slot:focus {
    outline: none;
    border-color: #6c00bd;
    background-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 2px rgba(108, 0, 189, 0.2);
}

/* Responsive: inputs and primary column adjustments */
@media (max-width: 768px) {
    input.slot {
        padding: 8px;
    }

    .volunteer-table td.primary-col .primary-col-date {
        font-size: 0.95rem;
    }
}

.volunteer-table {
    /* Base: let table be intrinsic-width (content-sized) but constrain to a
       practical maximum so very long single-line content will wrap instead of
       pushing the layout indefinitely wide. */
    width: 100%; /* Allow table to size to content for horizontal scroll */
    max-width: 1200px;
    border-collapse: collapse;
    table-layout: auto;
    flex: 0 0 auto; /* prevent flexbox from shrinking the table */
}

/* Slots */
.cell {
    position: relative;
    padding: 4px; /* small inner padding for cells */
    min-width: 0; /* allow cells to shrink to content size */
}

.slot:last-child {
    margin-bottom: 0;
}

.slot:focus {
    outline: 2px solid rgba(21,76,96,0.12);
    border-radius: 6px;
    background-color: rgba(255,255,255,0.98);
}

/* Slot wrapper: show a non-editable number and the input/textarea next to it */
.slot-wrapper {
    display: flex;
    align-items: center; /* vertically center number with input */
    gap: 6px; /* small gap between number and slot */
    width: 100%;
    max-width: 100%; /* constrain to column width */
    padding-left: 0; /* keep wrapper edge-aligned */
}
.slot-wrapper { min-height: 24px; }
.slot-num {
    flex: 0 0 22px; /* slightly wider to avoid crowding */
    color: #6c757d;
    font-weight: 400; /* match slot text weight */
    font-size: 0.82rem; /* match textarea.slot font-size */
    line-height: 1.2;
    text-align: right; /* align number next to the slot */
    margin-right: 0; /* no extra margin */
    margin-left: -8px; /* pull number left to the inner border of the cell */
}

@media (max-width: 480px) {
    .slot-num { font-size: 0.84rem; }
    .slot-num { margin-left: -8px; }
}

/* Use textarea for slots to allow multi-line and auto height */
textarea.slot {
    resize: none; /* prevent manual drag; we auto-resize via JS */
    /* single line height by default - grows when content added */
    height: auto;
    min-height: 36px;
    max-height: 220px;
    line-height: 1.25;
    font-family: inherit;
    font-size: 0.82rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.7);
    width: 100%; /* fill available space in flex container */
    box-sizing: border-box;
    color: var(--slot-text-color);
    flex: 1; /* allow textarea to grow and shrink with column width */
    white-space: normal; /* Allow text wrapping */
    word-wrap: break-word;
    overflow: hidden; /* hide native scrollbars; JS will auto-resize the textarea */
    padding: 6px 8px;
    transition: all 0.2s ease;
}

textarea.slot:focus {
    outline: none;
    border-color: #6c00bd;
    background-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 2px rgba(108, 0, 189, 0.2);
}

.slot-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    font-size: 0.92rem;
}

.slot-wrapper.unavailable .slot-label {
    color: #adb5bd;
}

/* Slot error message (transient) */
.slot-error {
    color: #b91c1c; /* red */
    font-size: 0.86rem;
    margin-left: 6px;
}

.slot.unavailable {
    background-color: transparent;
    color: #adb5bd;
    cursor: not-allowed;
}

/* Slot Controls (+ / - buttons) */
.cell-controls {
    position: absolute;
    top: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
}

.cell-controls button {
    width: 20px;
    height: 20px;
    line-height: 18px;
    padding: 0;
    font-size: 12px;
    border-radius: 3px;
}

/* Make slot controls more visible */
.cell-controls button {
    background: var(--primary-color);
    color: var(--primary-font-color);
    border: none;
}

/* Primary row (header) - keep the primary color background with white text */
.vol-row {
    background-color: var(--primary-color);
    color: var(--primary-font-color);
}

/* Row glass effect: soft translucent background per row, subtle borders */
.volunteer-table.row-glass tbody tr {
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
    border-radius: 6px;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.03);
    transition: all 0.2s ease;
}
.volunteer-table.row-glass tbody tr:nth-child(even) {
    background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
}

/* When row-glass is active, give slots a more glassy background */
.volunteer-table.row-glass .slot {
    background: rgba(255,255,255,0.25);
    border-radius: 6px;
    padding: 4px 8px;
}

/* Compact typography adjustments for better mobile density */
@media (max-width: 480px) {
    .volunteer-table { font-size: 0.86rem; }
    textarea.slot { font-size: 0.8rem; }
    .slot-num { font-size: 0.76rem; flex: 0 0 14px; }
    .slot-wrapper { gap: 3px; }

    /* Keep date label on one line on very small screens to avoid vertical stacking */
    .volunteer-table td.primary-col .primary-col-date {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Primary column - use a lighter background with dark text */
.volunteer-table td.primary-col {
    background-color: rgba(244, 246, 248, 0.8);
    color: var(--text-color);
}

/* Remove inner white boxes for primary areas — show text over fill */
.volunteer-table td.primary-col input,
.volunteer-table th.primary-row input {
    background: transparent;
    border: none;
    color: var(--primary-font-color);
}

/* Prevent primary column/row from being deletable via UI button styles */
.no-delete {
    opacity: 0.6;
    pointer-events: none;
}

/* Adjust column sizing: let middle columns flex but cap max width so second column doesn't expand too much */
.volunteer-table th:nth-child(2),
.volunteer-table td:nth-child(2) {
    max-width: 320px;
    word-wrap: break-word;
    padding-left: 6px; /* keep some left padding so content doesn't hit border */
}

@media (max-width: 992px) {
    .volunteer-table th:nth-child(2),
    .volunteer-table td:nth-child(2) {
        max-width: 260px;
    }
    
    .volunteer-table {
        /* Base: let table be intrinsic-width (content-sized) but constrain to a
           practical maximum so very long single-line content will wrap instead of
           pushing the layout indefinitely wide. */
        width: 100%;
        max-width: 1100px;
        border-collapse: collapse;
        table-layout: auto;
        flex: 0 0 auto; /* prevent flexbox from shrinking the table */
        background: transparent;
    }
}

/* ==========================================================================
   Table Row Styling (Alternating Rows)
   ========================================================================== */
.volunteer-table tbody tr {
    transition: all 0.2s ease;
}

.volunteer-table tbody tr:nth-child(odd) td {
    background-color: var(--row-shade) !important; /* theme-driven alternate row shade */
}
.volunteer-table tbody tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.5); /* Semi-transparent white for even rows */
}
.theme-blue .volunteer-table tbody tr:nth-child(odd) td {
    background-color: rgba(130, 181, 232, 0.5) !important; /* Light blue with transparency for theme-blue */
}

/* Add hover effect to rows */
.volunteer-table tbody tr:hover td {
    background-color: rgba(255, 255, 255, 0.7) !important;
}

.volunteer-table tbody tr:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
    /* On smaller screens, allow the table container to scroll horizontally
       but try to make columns readable by reducing padding and font-size. */
    /* Avoid forcing a min-width here; keep the content-sized behavior and
       allow wrapping when necessary. */

    .slot {
        padding: 6px;
        font-size: 0.95rem;
    }

    .volunteer-table {
        font-size: 0.95rem;
    }

    .cell-controls {
        top: 4px;
        right: 4px;
    }
}

@media (max-width: 480px) {
    /* Mobile: keep inputs usable, allow horizontal scroll and make buttons tappable */
    /* Keep content-sized behavior on very small screens as well. */

    .slot {
        font-size: 0.92rem;
    }

    .cell-controls button {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
}

/* --------------------------------------------------------------------------
   Mobile slot fixes
   Prevent textareas from collapsing to a very narrow column (which makes
   characters stack vertically). Keep the slot-wrapper horizontal, allow the
   textarea to grow and wrap naturally, and ensure single-line numbering
   remains aligned.
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .slot-wrapper {
        flex-direction: row; /* ensure number + textarea are side-by-side */
        align-items: center;
        gap: 8px;
    }

    .slot-num {
        margin-top: 0; /* align number vertically when wrapper is a row */
        width: 34px;
        text-align: right;
        flex: 0 0 auto;
    }

    /* Let the textarea expand to a readable width; allow wrapping of words
       but avoid breaking words into single characters. */
    textarea.slot, input.slot {
        min-width: 120px;
        width: auto;
        flex: 1 1 auto;
        white-space: normal;
        word-break: break-word;
        font-size: 0.88rem;
        padding: 4px 6px;
        min-height: 32px;
    }

    /* Ensure table cells vertically center their content on mobile */
    .volunteer-table td, .volunteer-table th {
        vertical-align: middle;
    }
}

/* ==========================================================================
   Welcome Modal (Public View)
   ========================================================================== */
#welcomeModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* place modal at top rather than center */
    padding-top: 40px; /* give space from top so modal is visible without zoom */
    z-index: 1000;
}

#welcomeModal .modal-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
#welcomeModal .modal-content { margin-top: 0; }

#welcomeModal .modal-content h2 {
    margin-bottom: 15px;
}

#welcomeModal .modal-content p {
    margin-bottom: 25px;
}

.hidden {
    display: none;
}
/* ==========================================================================
   Header Controls (Specific Styling)
   ========================================================================== */
.header-controls .control-select,
.header-controls .control-color-picker {
    width: auto; /* Override default 100% width */
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid var(--primary-font-color);
    background-color: var(--primary-color);
    color: var(--primary-font-color);
    font-family: 'DM Sans', sans-serif; /* Changed from Merriweather to match body font */
}

.header-controls .control-select option {
    background-color: var(--primary-color);
    color: var(--primary-font-color);
}

/* Responsive styles for Header Controls */
@media (max-width: 768px) {
    .header-controls .control-select,
    .header-controls .control-color-picker {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .header-controls .control-select,
    .header-controls .control-color-picker {
        padding: 5px 8px;
        font-size: 0.75rem;
    }
}

@media (max-width: 420px) {
    .volunteer-table td.primary-col {
        min-width: 120px;
        font-size: 0.8rem;
    }
    .slot-num { flex: 0 0 18px; font-size: 0.78rem; }
}

@media (max-width: 420px) {
    .slot-num { margin-left: -4px; flex: 0 0 18px; }
}

.slot.saving {
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

.slot.saved {
    background-color: #d4edda;
    border-color: #c3e6cb;
}

/* Row Head Styles (new addition) */
.row-header-input {
    width: 100%;
    padding: 6px 8px;
    /* Match slot font properties for consistent UI */
    font-family: inherit;
    /* Default (desktop) slot font-size is 0.82rem (textarea.slot) */
    font-size: 0.82rem;
    font-weight: 400;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--slot-text-color, var(--text-color));
    box-shadow: none;
    transition: box-shadow 150ms ease, border-color 150ms ease;
}

.row-header-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    background: rgba(255, 255, 255, 0.9);
}

.row-header-input.saved {
    box-shadow: 0 0 0 3px rgba(40,167,69,0.12);
    border-color: #28a745;
}

.row-header-input.header-too-long {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220,53,69,0.12) !important;
}

/* Responsive adjustments for row heads */
@media (max-width: 768px) {
    .row-header-input {
        padding: 5px 7px;
        font-size: 0.88rem;
    }
}

@media (max-width: 480px) {
    .row-header-input {
        padding: 4px 6px;
        font-size: 0.8rem;
    }
}

/* Add this to disable resize for all textareas */
textarea {
    resize: none;
}