/* ==========================================================================
   Timeline Viewer — Web Application Stylesheet
   Matches the desktop Timeline Viewer palette, layout, and interactions
   while providing responsive desktop & mobile support.
   ========================================================================== */

:root,
[data-theme="light"] {
    --bg-app: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-surface-hover: #FAFAFC;
    --bg-subtle: #F1F5F9;
    --bg-input: #F1F5F9;
    --bg-input-focus: #FFFFFF;
    --bg-notes: #F8FAFC;
    --bg-only-btn: #E2E8F0;
    --bg-only-btn-hover: #2563EB;
    --bg-year-badge: linear-gradient(90deg, #1E293B 0%, #334155 100%);

    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-muted: #475569;
    --text-faint: #64748B;
    --text-only-btn: #334155;
    --text-only-btn-hover: #FFFFFF;

    --border-color: #E2E8F0;
    --border-strong: #CBD5E1;
    --border-hover: #94A3B8;
    --border-focus: #2563EB;
    --year-line: #CBD5E1;
    --year-badge-border: transparent;

    --accent-primary: #2563EB;
    --accent-hover: #1D4ED8;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
    --shadow-card-hover: 0 4px 12px rgba(15, 23, 42, 0.08);

    --scrollbar-track: #F1F5F9;
    --scrollbar-thumb: #CBD5E1;
    --scrollbar-thumb-hover: #94A3B8;
}

[data-theme="dark"] {
    --bg-app: #0F172A;
    --bg-surface: #1E293B;
    --bg-surface-hover: #243248;
    --bg-subtle: #334155;
    --bg-input: #0F172A;
    --bg-input-focus: #0F172A;
    --bg-notes: #0F172A;
    --bg-only-btn: #334155;
    --bg-only-btn-hover: #3B82F6;
    --bg-year-badge: linear-gradient(90deg, #1E3A8A 0%, #2563EB 100%);

    --text-primary: #F8FAFC;
    --text-secondary: #E2E8F0;
    --text-muted: #94A3B8;
    --text-faint: #64748B;
    --text-only-btn: #CBD5E1;
    --text-only-btn-hover: #FFFFFF;

    --border-color: #334155;
    --border-strong: #475569;
    --border-hover: #64748B;
    --border-focus: #3B82F6;
    --year-line: #334155;
    --year-badge-border: #3B82F6;

    --accent-primary: #3B82F6;
    --accent-hover: #60A5FA;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 6px 16px rgba(0, 0, 0, 0.35);

    --scrollbar-track: #0F172A;
    --scrollbar-thumb: #334155;
    --scrollbar-thumb-hover: #475569;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* ==========================================================================
   App Shell Layout
   ========================================================================== */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   Top Toolbar & Search Area
   ========================================================================== */
.top-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 12px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 16px;
    flex-shrink: 0;
    z-index: 20;
    box-shadow: var(--shadow-sm);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 4px;
    flex-shrink: 0;
}

.app-brand h1 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    white-space: nowrap;
}

.mobile-filter-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-app);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    font-size: 13px;
    color: var(--text-faint);
    pointer-events: none;
}

.search-input {
    width: 100%;
    background-color: var(--bg-input);
    border: 1.5px solid var(--border-strong);
    border-radius: 8px;
    padding: 8px 34px 8px 34px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-input::placeholder {
    color: var(--text-faint);
}

.search-input:focus {
    outline: none;
    background-color: var(--bg-input-focus);
    border-color: var(--border-focus);
}

.clear-input-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-faint);
    font-size: 14px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.clear-input-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.stats-badge {
    background-color: var(--bg-input);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 100%;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background-color: var(--bg-app);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.action-btn:hover:not(:disabled) {
    background-color: var(--bg-subtle);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0.5px);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ==========================================================================
   Main Split Workspace (Left Filter Pane + Right Timeline)
   ========================================================================== */
.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Left Filter Panel */
.filter-panel {
    width: 310px;
    min-width: 250px;
    max-width: 380px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px 14px;
    gap: 12px;
    user-select: none;
}

.filter-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 4px 2px 2px 2px;
}

.filter-btn-row {
    display: flex;
    gap: 6px;
}

.filter-btn-row .action-btn {
    flex: 1;
    justify-content: center;
    padding: 5px 8px;
    font-size: 11px;
}

.location-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.location-search-input {
    width: 100%;
    background-color: var(--bg-app);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 5px 26px 5px 10px;
    font-size: 11.5px;
    font-family: inherit;
    color: var(--text-primary);
}

.location-search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    background-color: var(--bg-input-focus);
}

.filter-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 6px;
    border-radius: 5px;
    transition: background-color 0.1s ease;
}

.filter-row:hover {
    background-color: var(--bg-subtle);
}

.filter-icon {
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
}

.filter-label {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1;
    min-width: 0;
    font-size: 12.5px;
    color: var(--text-secondary);
    cursor: pointer;
}

.filter-label:hover {
    color: var(--text-primary);
}

.filter-checkbox {
    width: 15px;
    height: 15px;
    accent-color: var(--accent-primary);
    cursor: pointer;
    flex-shrink: 0;
}

.filter-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-count {
    color: var(--text-faint);
    font-size: 11.5px;
    flex-shrink: 0;
}

.only-btn {
    opacity: 0;
    pointer-events: none;
    background-color: var(--bg-only-btn);
    color: var(--text-only-btn);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.filter-row:hover .only-btn,
.only-btn:focus-visible {
    opacity: 1;
    pointer-events: auto;
}

.only-btn:hover {
    background-color: var(--bg-only-btn-hover);
    color: var(--text-only-btn-hover);
    border-color: var(--accent-hover);
}

.filter-divider {
    border: none;
    height: 1px;
    background-color: var(--border-color);
    margin: 4px 0;
}

/* ==========================================================================
   Right Timeline Scroll Area
   ========================================================================== */
.timeline-scroll-area {
    flex: 1;
    overflow-y: auto;
    background-color: var(--bg-app);
    padding: 16px 24px 36px 24px;
    outline: none;
}

.timeline-canvas {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Year Boundary Marker */
.year-marker {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 14px 0 6px 0;
}

.year-line {
    flex: 1;
    height: 2px;
    background-color: var(--year-line);
    border-radius: 1px;
}

.year-badge {
    background: var(--bg-year-badge);
    color: #FFFFFF;
    font-size: 13.5px;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid var(--year-badge-border);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

/* Event Card */
.event-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--card-accent, var(--accent-primary));
    border-radius: 8px;
    padding: 13px 16px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    cursor: pointer;
    box-shadow: var(--shadow-card);
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.event-card:hover {
    background-color: var(--bg-surface-hover);
    border-top-color: var(--border-hover);
    border-right-color: var(--border-hover);
    border-bottom-color: var(--border-hover);
    box-shadow: var(--shadow-card-hover);
}

.event-card-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.event-date {
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 600;
}

.category-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2.5px 9px;
    border-radius: 999px;
    border: 1px solid transparent;
    line-height: 1.3;
}

.event-location {
    margin-left: auto;
    color: var(--text-faint);
    font-size: 12px;
    font-weight: 500;
}

.event-description {
    color: var(--text-primary);
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.4;
    word-break: break-word;
}

/* Expandable Notes Drawer */
.notes-container {
    display: none;
    background-color: var(--bg-notes);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 4px;
    flex-direction: column;
    gap: 4px;
    cursor: text;
}

.event-card.expanded .notes-container {
    display: flex;
}

.notes-header {
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.notes-text {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.event-card-footer {
    display: flex;
    align-items: center;
}

.expand-toggle-btn {
    background: transparent;
    border: none;
    color: var(--accent-primary);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    padding: 2px 0;
    cursor: pointer;
}

.expand-toggle-btn:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Empty & Error States */
.empty-state-box {
    text-align: center;
    padding: 64px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.empty-state-icon {
    font-size: 40px;
    line-height: 1;
}

.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
}

.empty-state-hint {
    font-size: 13px;
    color: var(--text-faint);
    max-width: 440px;
}

/* ==========================================================================
   Bottom Status Bar
   ========================================================================== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-surface);
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    padding: 6px 16px;
    font-size: 12px;
    flex-shrink: 0;
}

.status-shortcuts {
    color: var(--text-faint);
    font-size: 11.5px;
}

/* ==========================================================================
   Responsive Design (Tablet & Mobile)
   ========================================================================== */
.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 25;
}

@media (max-width: 900px) {
    .top-bar {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }

    .mobile-filter-toggle {
        display: inline-flex;
    }

    .search-wrapper {
        order: 2;
        width: 100%;
        flex-basis: 100%;
    }

    .toolbar-actions {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
    }

    .toolbar-actions .action-btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    .stats-badge {
        order: 4;
        width: 100%;
        text-align: center;
        white-space: normal;
    }

    .filter-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 30;
        width: 300px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .filter-panel.open {
        transform: translateX(0);
    }

    .drawer-backdrop.open {
        display: block;
    }

    .only-btn {
        opacity: 1;
        pointer-events: auto;
    }

    .timeline-scroll-area {
        padding: 12px 12px 28px 12px;
    }

    .status-shortcuts {
        display: none;
    }
}
