/**
 * UI Components Library
 * Consistent button styles and interactive elements
 */

/* ===========================================
   BUTTON COMPONENT SYSTEM
   =========================================== */

/* Base Button Styles */
.btn {
    padding: 0.6rem 1.2rem;
    border: 2px solid;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.05s ease-out;
    letter-spacing: 0.5px;
    box-shadow: var(--shadow-base);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    outline: none;
}

/* Primary Button (Blue Theme) */
.btn--primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.btn--primary:hover {
    background: white;
    color: var(--color-primary);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-primary);
}

.btn--primary:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-base);
}

/* Primary Button Active State */
.btn--primary.btn--active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

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

/* Secondary Button (Outline) */
.btn--secondary {
    background: white;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn--secondary.btn--active,
.btn--secondary:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-primary);
}

.btn--secondary.btn--active,
.btn--secondary:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-base);
}

/* Danger Button (Red Theme) */
.btn--danger {
    background: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}

.btn--danger:hover {
    background: var(--color-danger-dark);
    border-color: var(--color-danger-dark);
    box-shadow: var(--shadow-danger);
}

.btn--danger:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-base);
}

/* Icon Button Modifiers */
.btn__icon {
    font-size: 1.1rem;
    transition: all 0.05s ease-out;
}

/* Favorite Toggle Specific Styles */
.btn--favorite .btn__icon--empty {
    color: var(--color-neutral-light);
}

.btn--favorite.btn--active .btn__icon--filled {
    color: var(--color-favorite-star);
}

.btn--favorite:hover .btn__icon {
    color: var(--color-favorite-star);
}

/* Small Button Variant */
.btn--sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Large Button Variant */
.btn--lg {
    padding: 0.8rem 1.6rem;
    font-size: 1rem;
}

/* ===========================================
   SELECT COMPONENT
   =========================================== */

.select {
    padding: 0.6rem 1rem 0.6rem 0.8rem;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    background: white;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23667eea' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    appearance: none;
    font-size: 0.9rem;
    color: var(--color-neutral-500);
    transition: all 0.05s ease-out;
    cursor: pointer;
    box-shadow: var(--shadow-base);
}

.select:hover,
.select:focus {
    border-color: var(--color-primary-hover);
    box-shadow: var(--shadow-primary-light);
    outline: none;
}

.select:active {
    transform: scale(0.99);
}

/* ===========================================
   TOGGLE COMPONENTS
   =========================================== */

.toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.toggle__icon {
    transition: all 0.05s ease-out;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* ===========================================
   FAVORITE TOGGLE BUTTON
   =========================================== */

.favorite-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Default state - gray star */
.favorite-toggle-btn[data-state="all"] .btn__icon {
    color: var(--color-neutral-400);
}

/* Favorites state - golden star */
.favorite-toggle-btn[data-state="favorites"] .btn__icon {
    color: var(--color-favorite-star);
    /* Golden star */
    text-shadow: 0 1px 2px var(--color-favorite-glow-medium);
    animation: starPulse 0.1s ease;
}

/* Star animation when toggling to favorites */
@keyframes starPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* Icon transition */
.favorite-toggle-btn .btn__icon {
    font-size: 1rem;
    /* Match other header control icons */
}

/* Override for header controls - ensure consistent sizing */
.controls .favorite-toggle-btn .btn__icon {
    font-size: 1rem !important;
    /* Force consistent size in header */
}

/* ===========================================
   PLACE TOGGLE BUTTON
   =========================================== */

.place-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-start;
    text-align: left;
    width: 100%;
    min-height: 42px;
    box-sizing: border-box;
    overflow: hidden;
    /* Prevent text overflow */
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Fix: make button area fully tappable on touch devices */
    -webkit-tap-highlight-color: rgba(139, 92, 246, 0.15);
    touch-action: manipulation;
    cursor: pointer;
    /* Remove pointer-events from children to ensure button gets the event */
}

.place-toggle-btn * {
    pointer-events: none;
}

/* Place toggles in the filter should fit their grid container */
.place-checkboxes .place-toggle-btn {
    width: 100% !important;
    /* Override header control fixed width */
    min-width: unset !important;
    /* Remove min-width constraints */
    max-width: 100%;
    /* Ensure they don't exceed container */
    font-size: 0.8rem;
    /* Smaller font to ensure text fits */
    padding: 0.5rem 0.6rem;
    /* Good padding for multi-line text */
    line-height: 1.3;
    /* Better line height for readability */
    min-height: 42px;
    /* Minimum height for single-line text */
    height: 100%;
    /* Fill the grid cell height */
    align-items: flex-start;
    /* Align content to top */
    align-self: stretch;
    /* Stretch to match tallest button in row */
}

/* Ensure text takes remaining space and allows wrapping */
.place-checkboxes .place-toggle-btn .btn__text {
    flex: 1;
    min-width: 0;
    /* Allow text to shrink */
    white-space: normal;
    /* Allow text wrapping by default */
    word-break: break-word;
    /* Break long words if needed */
    text-align: left;
    padding-top: 0.1rem;
    /* Slight top padding for better icon alignment */
}

/* Icon positioning for multi-line buttons */
.place-checkboxes .place-toggle-btn .btn__icon {
    align-self: flex-start;
    /* Keep icon at top */
    margin-top: 0.1rem;
    /* Fine-tune icon position */
}

/* Active state - green checkmark */
.place-toggle-btn[data-state="active"] .btn__icon {
    color: var(--color-success);
    /* Green checkmark */
}

/* Inactive state - red X */
.place-toggle-btn[data-state="inactive"] {
    background: var(--color-neutral-100);
    color: var(--color-neutral-400);
    border-color: var(--color-neutral-200);
}

.place-toggle-btn[data-state="inactive"] .btn__icon {
    color: var(--color-danger);
    /* Red X */
}

/* Icon transition */
.place-toggle-btn .btn__icon {
    font-size: 0.9rem;
    min-width: 1rem;
}

/* ===========================================
   HEADER CONTROLS CONSISTENCY
   =========================================== */

/* Ensure all header control buttons are the same size */
.controls .btn {
    /* min-width: 120px; */
    /* width: 120px; Fixed width to prevent size changes */
    height: 44px;
    /* Fixed height for perfect alignment */
    justify-content: center;
    gap: 0.5rem;
    text-align: center;
    box-sizing: border-box;
    align-items: center;
    /* Ensure vertical centering */
}

/* Normalize all icon sizes in header controls */
.controls .btn .btn__icon {
    font-size: 1rem;
    /* Consistent icon size */
    line-height: 1;
    display: inline-block;
    width: 1rem;
    text-align: center;
}

/* Day filter button specific styling */
.day-filter-btn .btn__icon {
    color: var(--color-neutral-500);
}

.day-filter-btn:hover .btn__icon {
    color: var(--color-neutral-600);
}

/* ===========================================
   FAVORITES CONTROLS (STACKED)
   =========================================== */

.favorites-controls {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: stretch;
}

.favorites-controls .btn {
    min-width: 90px;
    height: 32px;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 500;
    justify-content: center;
    text-align: center;
}

.favorites-controls .btn .btn__icon {
    font-size: 0.85rem;
    width: 0.85rem;
}

/* Make clear button slightly more subtle */
#clearFavoritesBtn {
    opacity: 0.9;
}

#clearFavoritesBtn:hover {
    opacity: 1;
}

/* ===========================================
   RESPONSIVE BUTTON IMPROVEMENTS
   =========================================== */

@media (max-width: 768px) {
    .btn {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        justify-content: center;
    }
    
    .btn__icon {
        flex-shrink: 0;
    }
}

@media (max-width: 480px) {
    .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
        gap: 0.3rem;
        min-width: 0;
    }
    
    .btn__icon {
        font-size: 0.8rem;
    }
    
    .btn--sm {
        padding: 0.25rem 0.4rem;
        font-size: 0.65rem;
    }
}

/* ===========================================
   FAVORITES CONTROLS RESPONSIVE HANDLING
   =========================================== */

.favorites-controls {
    display: flex;
    gap: 0.1rem;
    /* align-items: center; */
}

@media (max-width: 768px) {
    .favorites-controls {
        width: 100%;
        justify-content: center;
        order: 3;
        gap: 0rem;
    }
    
    .favorites-controls .btn {
        flex: 1;
        max-width: 120px;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .favorites-controls {
        gap: 0.4rem;
        margin-top: 0.5rem;
    }
    
    .favorites-controls .btn {
        min-width: 70px;
        max-width: 100px;
        font-size: 1rem;
        height: 30px;
    }
}

/* ===========================================
   SIDEBAR AND HAMBURGER STYLES
   =========================================== */

.hamburger {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 1201;
    width: 44px;
    height: 44px;
    background: #fff;
    border: none;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.hamburger-stripes {
    display: block;
    width: 26px;
    height: 3px;
    background: #8b5cf6;
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(.4,2,.6,1);
}

.hamburger.active .hamburger-stripes:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
}

.hamburger.active .hamburger-stripes:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-stripes:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
}

.sidebar {
    position: fixed;
    top: 80px;
    left: 0;
    height: 100vh;
    width: 320px;
    max-width: 40vw;
    min-width: 220px;
    background: var(--color-surface-primary);
    backdrop-filter: blur(10px);
    box-shadow: 2px 0 16px rgba(0,0,0,0.12);
    z-index: 1202;
    transform: translateX(-100%);
    /* opacity: 0; */
    pointer-events: none;
    transition: transform 0.25s ease-out, opacity 0.2s ease-out;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.sidebar.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-100%);
}

.sidebar.dragging {
    transition: none !important;
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
}

.sidebar-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: #8b5cf6;
    cursor: pointer;
    margin-right: 8px;
}

.sidebar-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
}

.sidebar-controls .btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 1rem;
    justify-content: flex-start;
}

.sidebar .favorites-controls {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin-top: 8px;
}

.sidebar .favorites-controls .btn {
    flex: 1;
    min-width: 0;
}

.sidebar-overlay {
    position: fixed;
    top: 80px; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.18);
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in;
}

.sidebar-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 600px) {
    .sidebar {
        width: 55vw;
        max-width: 96vw;
        min-width: 0;
    }
}

/* Place filter in sidebar (legacy, for backward compatibility) */
#placeFilter {
    display: none;
    position: absolute;
    z-index: 1300;
    min-width: 160px;
    max-width: 210px;
    width: auto;
    max-width: 90vw;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 1.5px 4px rgba(139,92,246,0.08);
    border-radius: 12px;
    padding: 16px 12px 12px 12px;
    margin-top: 8px;
    margin-left: 0;
    transition: opacity 0.18s cubic-bezier(.4,2,.6,1), transform 0.18s cubic-bezier(.4,2,.6,1);
    opacity: 0;
    pointer-events: none;
}

#placeFilter.modal--visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0px) scale(1);
}

#placeFilter .place-filter-content {
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
}

#placeFilter .place-checkboxes {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    width: 100%;
    align-items: flex-start;
}

@media (max-width: 400px) {
    #placeFilter .place-checkboxes {
        grid-template-columns: 1fr;
    }
}

#placeFilter .filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
    width: 100%;
}

@media (max-width: 600px) {
    #placeFilter {
        min-width: 120px;
        max-width: 96vw;
        width: 96vw;
    }
}

/* ===========================================
   EXISTING COMPONENTS CONTINUE BELOW
   =========================================== */


.header-content {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0px 18px 0 80px; /* leave space for hamburger */
    min-height: 56px;
}

.header-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #8b5cf6;
    margin: 0;
}

.timestamp-text {
    font-size: 1rem;
    color: #666;
    margin-left: 24px;
    white-space: nowrap;
}

@media (max-width: 600px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25em;
  }
  .header-title,
  #dataTimestamp {
    margin-left: 0px;
    font-size: 1.1rem;
  }
}

/* ===========================================
   PLACE FILTER MODAL
   =========================================== */

.place-filter-modal {
    position: absolute;
    z-index: 1202;
    min-width: 160px;
    max-width: 210px;
    width: auto;
    max-height: 80vh;
    min-height: 340px;
    height: 60vh;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 1.5px 6px rgba(139,92,246,0.10);
    padding: 18px 18px 12px 18px;
    display: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s cubic-bezier(.4,0,.2,1), transform 0.22s cubic-bezier(.4,0,.2,1);
    transform: translateY(8px) scale(0.98);
    overflow-y: auto;
    box-sizing: border-box;
}

.place-filter-modal.modal--visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

@media (max-width: 600px) {
    .place-filter-modal {
        min-width: 120px;
        max-width: 96vw;
        width: 96vw;
        min-height: 220px;
        height: 60vh;
        left: 0 !important;
        right: 0;
        margin: 0 auto;
    }
}

.place-filter-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

.place-checkboxes {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
}

@media (max-width: 400px) {
    .place-checkboxes {
        grid-template-columns: 1fr;
    }
}

.filter-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}
