@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;500;600;700&family=Varela+Round&display=swap');

/* ============================================================
   米粉地圖 Design System
   Palette: #585CA6 · #F2CB05 · #F2BB13 · #F29F05 · #DBD5DB
   ============================================================ */
:root {
    --primary: #585CA6;          /* 靛藍紫 - 主色、按鈕、連結 */
    --primary-hover: #474A8C;
    --primary-light: #EEEEF7;
    --accent: #F29F05;           /* 琥珀橙 - CTA、重點 */
    --accent-hover: #D98C04;
    --accent-light: #FFF8E6;
    --gold: #F2CB05;             /* 金黃 - 標記、badge */
    --gold-mid: #F2BB13;         /* 中金 - hover、漸層 */
    --neutral: #DBD5DB;          /* 暖灰 - 邊框、分隔 */

    --bg: #FAFAFA;
    --surface: #FFFFFF;
    --text: #1A1A1A;
    --text-secondary: #4A4A4A;
    --text-muted: #7A7A7A;
    --border: #DBD5DB;
    --border-light: #ECEAEC;

    --success: #16A34A;
    --warning: #F29F05;
    --error: #DC2626;

    --font-heading: 'Varela Round', sans-serif;
    --font-body: 'Nunito Sans', sans-serif;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --shadow: 0 2px 12px rgba(88, 92, 166, 0.08);
    --shadow-lg: 0 8px 24px rgba(88, 92, 166, 0.12);
    --max-width: 720px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[x-cloak] { display: none !important; }

body {
    font-family: var(--font-body);
    font-size: var(--font-size-base, 17px);
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow);
    z-index: 1000;
    min-height: 56px;
    gap: 8px;
}

.title {
    font-family: var(--font-heading);
    font-size: 18px;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.back-link:hover { background: var(--primary-light); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    text-decoration: none;
    min-height: 48px;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 3px 12px rgba(242, 159, 5, 0.3);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--primary-light); border-color: var(--primary); }

/* --- Map (Homepage) --- */

.locate-btn {
    position: absolute;
    bottom: 140px;
    left: 16px;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 2px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: 22px;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.locate-btn:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: scale(1.05); }

.gps-notice {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 14px;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}

/* --- Leaflet Popup --- */
.leaflet-popup-content-wrapper { border-radius: var(--radius) !important; box-shadow: var(--shadow-lg) !important; }
.leaflet-popup-content { margin: 0 !important; font-size: 16px !important; line-height: 1.6 !important; }
.map-popup { padding: 16px; }
.map-popup strong { font-family: var(--font-heading); font-size: 18px; display: block; margin-bottom: 6px; color: var(--primary); }
.map-popup a { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; font-weight: 600; }
.map-popup a:hover { text-decoration: underline; }

/* --- Page Container (Detail + Form) --- */
.detail-container,
.form-container {
    width: 100%;
    max-width: var(--max-width);
    margin: 32px auto;
    padding: 32px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

/* --- Detail Page --- */
.event-title {
    font-family: var(--font-heading);
    font-size: 28px;
    color: var(--text);
    margin-bottom: 20px;
    line-height: 1.3;
}

.event-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    padding: 14px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
}

.event-description {
    margin: 20px 0;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    line-height: 1.8;
}

.event-map {
    width: 100%;
    height: 260px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin: 20px 0;
    border: 2px solid var(--border);
}

.event-actions {
    display: flex;
    gap: 12px;
    margin: 24px 0;
}
.event-actions .btn { flex: 1; }

.event-meta { font-size: 14px; color: var(--text-muted); text-align: center; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}
.status-confirmed { background: #E8F5EE; color: var(--success); }
.status-ai_approved { background: var(--accent-light); color: #8B6914; }

.notice {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin: 12px 0;
    font-size: 15px;
    font-weight: 500;
}
.notice-warning { background: var(--accent-light); color: #8B6914; border: 1px solid var(--gold); }
.notice-error { background: #FEF2F2; color: var(--error); border: 1px solid #FECACA; }

/* --- Form --- */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    font-family: var(--font-body);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(88, 92, 166, 0.12);
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-muted); }

.form-map {
    width: 100%;
    height: 320px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 2px solid var(--border);
    margin-top: 8px;
}

.form-map-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
}
.form-actions .btn { flex: 1; }

.hint { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

/* --- Photo Upload --- */
.photo-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    margin-top: 8px;
    background: var(--bg);
}
.photo-upload-area:hover { border-color: var(--primary); background: var(--primary-light); }
.photo-upload-placeholder { color: var(--text-muted); font-size: 16px; line-height: 2; }
.photo-upload-placeholder small { font-size: 13px; }

.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.photo-preview-item { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; }
.photo-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-remove-btn {
    position: absolute; top: 6px; right: 6px;
    width: 26px; height: 26px;
    border-radius: var(--radius-full);
    background: rgba(0,0,0,0.6); color: #fff;
    border: none; font-size: 13px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.photo-add-more {
    aspect-ratio: 1;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; color: var(--text-muted); cursor: pointer;
}
.photo-add-more:hover { border-color: var(--primary); color: var(--primary); }

/* --- Photo Carousel --- */
.photo-carousel { margin: 20px 0; }
.carousel-main {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #1a1a1a;
}
.carousel-slide {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.4s ease;
}
.carousel-slide.carousel-active { opacity: 1; }
.carousel-prev, .carousel-next {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; border-radius: var(--radius-full);
    background: rgba(255,255,255,0.85); border: none; font-size: 22px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow); z-index: 2;
}
.carousel-prev { left: 12px; }
.carousel-next { right: 12px; }
.carousel-verify {
    position: absolute; top: 12px; left: 12px; z-index: 2;
    font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: var(--radius-full);
}
.carousel-counter {
    position: absolute; bottom: 12px; right: 12px; z-index: 2;
    font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: var(--radius-full);
    background: rgba(0,0,0,0.5); color: #fff;
}
.verify-yes { background: rgba(232,245,238,0.95); color: var(--success); }
.verify-pending { background: rgba(255,248,230,0.95); color: #8B6914; }
.carousel-thumbs {
    display: flex; gap: 8px; margin-top: 10px;
    overflow-x: auto; padding: 4px 0;
}
.carousel-thumbs::-webkit-scrollbar { display: none; }
.carousel-thumbs img {
    width: 56px; height: 56px; object-fit: cover; border-radius: 8px;
    cursor: pointer; border: 2px solid transparent; opacity: 0.5;
    transition: all 0.15s; flex-shrink: 0;
}
.carousel-thumbs img:hover { opacity: 0.8; }
.carousel-thumbs .thumb-active { border-color: var(--primary); opacity: 1; }

/* --- Main Layout (Sidebar + Map) --- */
.main-layout {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebar (desktop) */
.sidebar {
    width: 340px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-filter {
    display: flex;
    gap: 6px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg);
}
.filter-btn {
    flex: 1;
    padding: 8px 4px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.12s;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.sidebar-item {
    display: block;
    padding: 12px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: background 0.1s;
    margin-bottom: 4px;
}
.sidebar-item:hover { background: var(--primary-light); }
.sidebar-item-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}
.sidebar-item-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    color: var(--text-muted);
}
.sidebar-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Mobile cards (horizontal scroll at bottom of map) */
.mobile-cards {
    display: none;
}

/* Map container */
.map-container { flex: 1; position: relative; min-height: 0; display: flex; flex-direction: column; }
#map { flex: 1; width: 100%; min-height: 300px; }

/* Mobile filter bar - ONLY visible on mobile */
.mobile-filter {
    display: none !important;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    gap: 10px;
    flex-direction: column;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.mobile-search {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
}
.mobile-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(88, 92, 166, 0.1);
    background: var(--surface);
}
.mobile-filter-btns {
    display: flex;
    gap: 8px;
}
.mobile-filter-btns .filter-btn {
    flex: 1;
    font-size: 14px;
    padding: 10px 4px;
    font-weight: 600;
}
.date-picker-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.date-picker-row input[type="date"] {
    flex: 1;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font-body);
}

/* View toggle (segmented control) */
.view-toggle {
    display: flex;
    background: var(--border-light);
    border-radius: var(--radius);
    padding: 3px;
    gap: 0;
}
.view-toggle-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 9px;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
}
.view-toggle-active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.filter-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.filter-icon-active {
    background: var(--primary);
    border-color: var(--primary);
}

@media (max-width: 768px) {
    .sidebar { display: none !important; }
    .mobile-filter { display: flex !important; }
    .mobile-cards {
        display: flex;
        position: absolute;
        bottom: 16px;
        left: 0;
        right: 0;
        z-index: 1000;
        gap: 10px;
        padding: 0 12px;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-cards::-webkit-scrollbar { display: none; }
    .mobile-card {
        flex-shrink: 0;
        width: 240px;
        padding: 14px;
        background: var(--surface);
        border-radius: var(--radius);
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--border-light);
        text-decoration: none;
        color: var(--text);
        scroll-snap-align: start;
    }
    .mobile-card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
    .mobile-card-meta { font-size: 13px; color: var(--text-muted); }
    .mobile-card-time { font-size: 13px; color: var(--primary); font-weight: 600; margin-top: 4px; }

    .mobile-list {
        flex: 1;
        overflow-y: auto;
        padding: 8px 12px;
        background: var(--bg);
    }
    .mobile-list-count {
        font-size: 13px;
        color: var(--text-muted);
        padding: 8px 4px;
    }
    .mobile-list-item {
        display: block;
        padding: 12px;
        background: var(--surface);
        border: 1px solid var(--border-light);
        border-radius: var(--radius);
        margin-bottom: 8px;
        text-decoration: none;
        color: var(--text);
    }
    .mobile-list-item:active { background: var(--primary-light); }
    .mobile-list-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
    .mobile-list-meta { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-muted); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .detail-container,
    .form-container {
        margin: 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
        padding: 20px;
    }
    .event-actions,
    .form-actions { flex-direction: column; }
}

/* --- Focus --- */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* --- List Page --- */
.list-page { max-width: 900px; margin: 0 auto; padding: 20px; }
.list-filters { margin-bottom: 16px; }
.list-search {
    width: 100%; padding: 12px 16px; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 15px; font-family: var(--font-body);
    background: var(--surface); color: var(--text); margin-bottom: 10px;
}
.list-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(88,92,166,0.1); }
.list-filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.list-select, .list-date {
    flex: 1; min-width: 120px; padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 14px; font-family: var(--font-body);
    background: var(--surface); color: var(--text);
}
.list-summary {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; margin-bottom: 12px; font-size: 14px; color: var(--text-muted);
}
.list-grid { display: flex; flex-direction: column; gap: 8px; }
.list-card {
    display: block; padding: 14px 16px; background: var(--surface);
    border: 1px solid var(--border-light); border-radius: var(--radius);
    text-decoration: none; color: var(--text); transition: all 0.1s;
}
.list-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.list-card-status { float: right; }
.list-card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.list-card-meta { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-muted); }

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary: #7B7FCC;
        --primary-hover: #9598D9;
        --primary-light: #2A2A3E;
        --accent: #F2BB13;
        --accent-hover: #F2CB05;
        --accent-light: #3D3520;
        --neutral: #3A3A3A;
        --bg: #1A1A2E;
        --surface: #252540;
        --text: #EAEAEA;
        --text-secondary: #B8B8B8;
        --text-muted: #888888;
        --border: #3A3A50;
        --border-light: #2E2E45;
        --success: #4ADE80;
        --warning: #F2CB05;
        --error: #F87171;
        --shadow: 0 2px 12px rgba(0,0,0,0.3);
        --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    }
}
[data-theme="dark"] {
    --primary: #7B7FCC;
    --primary-hover: #9598D9;
    --primary-light: #2A2A3E;
    --accent: #F2BB13;
    --accent-hover: #F2CB05;
    --accent-light: #3D3520;
    --neutral: #3A3A3A;
    --bg: #1A1A2E;
    --surface: #252540;
    --text: #EAEAEA;
    --text-secondary: #B8B8B8;
    --text-muted: #888888;
    --border: #3A3A50;
    --border-light: #2E2E45;
    --success: #4ADE80;
    --warning: #F2CB05;
    --error: #F87171;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Font Size Modes --- */
html[data-size="large"], html[data-size="large"] body { font-size: 20px !important; }
html[data-size="large"] .btn { min-height: 52px; }
html[data-size="large"] .filter-btn { font-size: 16px; }
html[data-size="large"] .mobile-search { font-size: 17px; }

html[data-size="xlarge"], html[data-size="xlarge"] body { font-size: 24px !important; }
html[data-size="xlarge"] .btn { min-height: 58px; font-size: 20px; padding: 16px 28px; }
html[data-size="xlarge"] .filter-btn { font-size: 18px; padding: 14px 10px; }
html[data-size="xlarge"] .mobile-search { font-size: 20px; padding: 16px 18px; }
html[data-size="xlarge"] .sidebar-item-title { font-size: 20px; }
html[data-size="xlarge"] .mobile-card-title { font-size: 19px; }
html[data-size="xlarge"] .title { font-size: 22px; }
html[data-size="xlarge"] .info-item { font-size: 20px; }
html[data-size="xlarge"] .map-popup strong { font-size: 20px; }

.size-toggle {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-family: var(--font-body);
}

.settings-group {
    display: flex;
    gap: 4px;
}

@media (max-width: 400px) {
    .settings-group { display: none; }
    .title { font-size: 18px !important; }
}
