/* public/style.css */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #f4f4f9;
    color: #333;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* Anchor background: prevent page scroll */
    overscroll-behavior: none; /* Disable rubber-band scroll on body */
}
html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none; /* Anchor root as well (prevents header scroll bounce) */
}

header {
    background-color: #522d80; /* Clemson Purple */
    color: white;
    padding: 1rem 2rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Compact header variant */
header.compact {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding-top: calc(0.4rem + var(--safe-top));
    padding-bottom: 0.4rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
}

header.compact .welcome {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.95;
}
header.compact .last-updated {
    margin: 0;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.75); /* slightly greyed-out on purple header */
}

header.compact .brand {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1;
}
header.compact .brand a {
    color: #fff;
    text-decoration: none;
}
header.compact .brand a:hover, 
header.compact .brand a:focus-visible {
    text-decoration: underline;
    outline: none;
}

h1 {
    margin: 0;
    font-size: 1.8rem;
}

.container {
    position: relative;
    display: flex;
    flex-grow: 1;
    padding: 0;
    gap: 0;
    overflow: hidden;
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100% !important;
    border-radius: 0;
    box-shadow: none;
    z-index: 1;
}

#dashboard {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    transform: translateY(calc(100% - 48px));
    transition: transform 0.25s ease-in-out;
    z-index: 1000;
}
#dashboard[aria-expanded="true"] {
    transform: translateY(0);
}
#dashboard.dragging {
    transition: none !important;
}
.tray-handle:active {
    cursor: grabbing;
    cursor: -webkit-grabbing;
}
html.tray-dragging, body.tray-dragging {
    user-select: none;
    -webkit-user-select: none;
}
.tray-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: grab;
    cursor: -webkit-grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}
.tray-grip {
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: #cfcfcf;
}
.tray-title {
    font-weight: 600;
    color: #555;
}
.tray-content {
    max-height: min(60vh, 540px);
    overflow: auto;
    padding: 8px 12px calc(12px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background-color: #f8f8f8;
    position: sticky;
    top: 0;
}

.status-bar {
    width: 100%;
    background-color: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    height: 20px;
}

.fill {
    height: 100%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    font-weight: bold;
    transition: width 0.5s ease-in-out;
}

.green { background-color: #4CAF50; }
.yellow { background-color: #FFC107; }
.red { background-color: #F44336; }

/* Map marker with vacancy badge */
.lot-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}
.lot-marker .dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #000;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    transition: transform 0.15s ease;
}
.lot-marker .badge {
    position: absolute;
    top: -4px;
    right: -6px;
    background: #F56600; /* Clemson Orange */
    color: #fff;
    border-radius: 10px;
    padding: 0 4px;
    font-size: 11px;
    font-weight: 800;
    line-height: 16px;
    min-width: 16px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.lot-marker.active .dot {
    transform: scale(1.25);
    border-color: #522d80;
}

/* Popup redesign */
.popup-title {
    font-weight: 700;
    margin-bottom: 8px;
}
.stats-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: #f7f4fc;
    border: 1px solid #e6ddfa;
    border-radius: 8px;
    padding: 8px;
}
.stat .label {
    font-size: 0.75rem;
    color: #666;
}
.stat .value {
    font-size: 1.1rem;
    font-weight: 800;
}
.stat.vacant .value {
    color: #2e7d32;
}
.stat.occupied .value {
    color: #c62828;
}
.popup-note {
    margin-top: 6px;
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
}
.popup-divider {
    margin: 8px 0;
    height: 1px;
    background: #eee;
}

/* Popup content and navigate button styles */
.leaflet-popup-content .popup-content {
    max-width: 240px;
    line-height: 1.3;
}

.navigate-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 10px;
    background-color: #F56600; /* Clemson Orange */
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    font-weight: 600;
    font-size: 0.9rem;
}

.navigate-link:hover {
    background-color: #d45500;
}

/* Center CTA in popup and force white icon/text color */
.leaflet-popup-content .navigate-cta {
    display: flex;
    justify-content: center;
}
.leaflet-popup-content .navigate-link {
    color: #fff;
}
.leaflet-popup-content .navigate-link .nav-icon {
    background-color: #fff; /* make SVG icon white on popup button */
}

/* Toast notifications */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(16px + var(--safe-bottom));
    transform: translateX(-50%) translateY(16px);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.2;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 2000;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Install FAB (floating action button) */
.install-fab {
    position: fixed;
    right: max(16px, var(--safe-right));
    bottom: calc(16px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #F56600; /* Clemson Orange */
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    cursor: pointer;
    z-index: 1600;
}
.install-fab:hover {
    background: #d45500;
}
.install-fab:focus-visible {
    outline: 2px solid #522d80;
    outline-offset: 2px;
}

/* Lift FAB higher on mobile to avoid overlapping the tray handle */
@media (max-width: 900px) {
    .install-fab {
        bottom: calc(96px + var(--safe-bottom));
    }
}

/* Install instructions modal */
.install-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.install-modal.open {
    opacity: 1;
    pointer-events: auto;
}
.install-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
}
.install-card {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 420px);
    max-height: 80vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    padding: 16px 16px 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.install-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: transparent;
    border: none;
    color: #555;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}
.install-card h2 {
    margin: 0 28px 8px 0;
    font-size: 1.2rem;
}
.install-steps {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    display: grid;
    gap: 12px;
}
.install-steps li img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid #eee;
    display: block;
}
.install-steps li p {
    margin: 6px 0 0;
    font-size: 0.95rem;
}

/* Small square navigate icon button used in the table */
.nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: #F56600; /* Clemson Orange */
    color: #fff;
    margin-right: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    text-decoration: none;
    transition: background-color 0.15s ease-in-out;
}
.nav-icon-btn:hover {
    background-color: #d45500;
}
.nav-icon-btn:focus-visible {
    outline: 2px solid #522d80;
    outline-offset: 2px;
}

/* Star (favorite) button */
.fav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    background: #fff;
    color: #999;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    user-select: none;
}
.fav-btn:hover {
    background: #f6f6f6;
}
.fav-btn:active {
    transform: translateY(1px);
}
.fav-btn:focus-visible {
    outline: 2px solid #522d80;
    outline-offset: 2px;
}
.fav-btn.fav {
    color: #F56600; /* Clemson Orange for favorited */
    border-color: #ffd4ad;
    background: #fff8f2;
}

/* Align icons and name nicely */
.lot-name-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}
/* Purple navigation glyph using SVG mask */
.nav-icon {
    width: 18px;
    height: 18px;
    display: block;
    background-color: #522d80; /* Clemson Purple */
    -webkit-mask: url('navigate-icon.svg') no-repeat center / contain;
    mask: url('navigate-icon.svg') no-repeat center / contain;
}
.lot-name-text {
    vertical-align: middle;
    cursor: pointer;
}
.lot-name-text:hover {
    text-decoration: underline;
}

/* Active/hover states for list rows */
tbody tr.active {
    background: #f2e9ff; /* subtle purple tint */
}
tbody tr.active .lot-name-cell {
    border-left: 4px solid #522d80;
}
tbody tr:hover {
    background: #fafafa;
}

/* Slightly larger touch target on mobile/tablet */
@media (max-width: 900px) {
    .nav-icon-btn { width: 32px; height: 32px; }
    .nav-icon { width: 20px; height: 20px; }
}

/* Use dynamic viewport height when supported to avoid mobile browser UI issues */
@supports (height: 100dvh) {
    body { height: 100dvh; }
}

/* Responsive layout for tablets/phones */
@media (max-width: 900px) {
    .container {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }

    #map, #dashboard {
        width: 100%;
    }

    /* Give the map a fixed viewport height chunk and let dashboard take the rest */
    #map {
        height: 55vh;
    }

    #dashboard {
        flex: 1;
        height: auto;
        -webkit-overflow-scrolling: touch;
    }

    header:not(.compact) {
        padding: 0.75rem 1rem;
    }

    h1 {
        font-size: 1.4rem;
    }

    /* Make table scroll horizontally instead of squishing columns */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    th, td {
        padding: 10px 12px;
    }

    .status-bar {
        height: 16px;
    }

    .fill {
        font-size: 0.75em;
    }

    /* Slightly larger zoom controls for touch */
    .leaflet-control-zoom {
        transform: scale(1.1);
        transform-origin: top left;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    h1 {
        font-size: 1.2rem;
    }
    .navigate-link {
        width: 100%;
        justify-content: center;
        padding: 10px 12px;
    }
}

/* Safe-area padding for devices with notches (iOS, etc.) */
:root {
    --safe-top: env(safe-area-inset-top);
    --safe-right: env(safe-area-inset-right);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
}

/* Increase header padding to respect safe areas */
header:not(.compact) {
    padding-top: calc(1rem + var(--safe-top));
    padding-right: calc(2rem + var(--safe-right));
    padding-left: calc(2rem + var(--safe-left));
}

/* On smaller screens adjust paddings proportionally and ensure bottom safe area */
@media (max-width: 900px) {
    header:not(.compact) {
        padding-top: calc(0.75rem + var(--safe-top));
        padding-right: calc(1rem + var(--safe-right));
        padding-left: calc(1rem + var(--safe-left));
    }
    body {
        padding-bottom: var(--safe-bottom);
        padding-left: max(0px, var(--safe-left));
        padding-right: max(0px, var(--safe-right));
    }
}

/* Live overlay for per-stall map */
.live-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.live-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.live-card {
    background: #fff;
    width: min(96vw, 900px);
    height: min(85vh, 560px);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.live-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
}
.live-title {
    font-weight: 700;
}
.live-close {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #555;
}
.live-map {
    flex: 1;
    min-height: 280px;
}
.live-legend {
    display: flex;
    gap: 12px;
    padding: 8px 12px;
    border-top: 1px solid #eee;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #555;
    font-size: 0.9rem;
}
.stall-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}
.stall-swatch.vacant { background: #66bb6a; }
.stall-swatch.occupied { background: #c62828; }

/* Stall icons */
.stall-divicon { }
.stall-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 1px rgba(0,0,0,0.3);
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.stall-icon.vacant { background: #66bb6a; }
.stall-icon.occupied { background: #c62828; }

/* Live spots button in popup */
.leaflet-popup-content .live-cta {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}
.leaflet-popup-content .live-spots-btn {
    padding: 6px 10px;
    background: #522d80; /* Clemson Purple */
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.leaflet-popup-content .live-spots-btn:hover {
    background: #3f2163;
}
