:root {
    --primary-blue: #3f51b5;
    --primary-blue-dark: #32408f;
    --bg-light: #f5f5f5;
    --bg-white: #ffffff;
    --text-dark: #212121;
    --text-muted: #757575;
    --border-color: #e0e0e0;
    --tag-inactive-bg: #e0e0e0;
    --tag-inactive-text: #424242;
    --success: #2e7d32;
    --font: 'Inter', 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-light);
    color: var(--text-dark);
    font-family: var(--font);
}

button, input { font-family: var(--font); }
a { color: var(--primary-blue); }
img { max-width: 100%; display: block; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 8px; }

/* ---------------------------------------------------------------- */
/* Top bar                                                            */
/* ---------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-h);
    background: var(--primary-blue);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.icon-btn {
    background: transparent;
    border: none;
    color: inherit;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }
.icon-btn svg { width: 20px; height: 20px; }

.sidebar-toggle { display: none; }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.brand-check {
    width: 22px;
    height: 22px;
    background: #fff;
    color: var(--primary-blue);
    border-radius: 50%;
    padding: 3px;
    box-sizing: content-box;
}

.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

/* ---------------------------------------------------------------- */
/* Shell / sidebar                                                    */
/* ---------------------------------------------------------------- */
.app-shell {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    height: calc(100vh - var(--topbar-h));
    position: sticky;
    top: var(--topbar-h);
    overflow-y: auto;
    padding: 6px 0 20px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    background: transparent;
    border: none;
    text-align: left;
    padding: 11px 18px;
    font-size: 0.92rem;
    color: var(--text-dark);
    cursor: pointer;
    font-weight: 500;
    transition: background .12s;
}
.sidebar-item:hover { background: #f0f1fb; }
.sidebar-item.active-route { color: var(--primary-blue); }
.sidebar-item .sidebar-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
}
.sidebar-icon.home-icon { color: var(--text-muted); background: transparent; }
.sidebar-icon.home-icon svg { width: 22px; height: 22px; }

.franchise-list { border-top: 1px solid var(--border-color); margin-top: 4px; padding-top: 4px; }

.sidebar-item.disabled {
    cursor: default;
    opacity: 0.5;
}
.sidebar-item.disabled:hover { background: transparent; }
.sidebar-item .soon-tag {
    margin-left: auto;
    font-size: 0.62rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* Content                                                            */
/* ---------------------------------------------------------------- */
.content { flex: 1; min-width: 0; padding: 24px 32px 60px; }

.home-view { display: none; max-width: 1100px; }
.home-view.active-view { display: block; }
.home-heading { font-size: 1.5rem; font-weight: 600; margin: 0 0 4px; color: var(--text-dark); }
.home-sub { font-size: 0.88rem; color: var(--text-muted); margin: 0 0 22px; }
.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.home-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 18px;
    cursor: pointer;
    text-align: left;
    transition: box-shadow .15s, border-color .15s, transform .15s;
}
.home-card:hover { border-color: var(--primary-blue); box-shadow: 0 4px 16px rgba(0,0,0,0.08); transform: translateY(-2px); }
.home-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.home-card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-dark); line-height: 1.3; }
.home-card-count { font-size: 0.78rem; color: var(--text-muted); }

#franchiseView { display: block; }
#franchiseView.hidden-view { display: none; }

.content-header { max-width: 900px; }

.franchise-title-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}
.franchise-glyph {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.franchise-title-row h1 { font-size: 1.5rem; font-weight: 600; margin: 0; color: var(--text-dark); }

.search-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
#searchInput {
    flex: 1;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    padding: 10px 4px;
    font-size: 0.95rem;
    color: var(--text-dark);
}
#searchInput:focus { outline: none; border-bottom-color: var(--primary-blue); }
#searchInput::placeholder { color: #9e9e9e; }

.config-btn { color: var(--text-muted); }
.config-btn:hover { background: #ececec; }

.tabs {
    display: flex;
    gap: 28px;
    border-bottom: 1px solid var(--border-color);
    margin-top: 6px;
}
.tab {
    background: none;
    border: none;
    padding: 12px 2px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text-dark); }
.tab.active { color: var(--primary-blue); border-bottom-color: var(--primary-blue); font-weight: 600; }

.progress-meter {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 18px;
    margin-top: 16px;
}
.progress-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.progress-meta strong { color: var(--text-dark); font-weight: 700; }
.progress-track {
    height: 8px;
    background: var(--bg-light);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.progress-fill {
    height: 100%;
    background: var(--primary-blue);
    border-radius: 999px;
    width: 0%;
    transition: width .4s cubic-bezier(.4,0,.2,1);
}

.api-banner { max-width: 900px; margin-top: 14px; }
.api-banner-inner {
    background: #fff8e1;
    border: 1px solid #ffe082;
    color: #8d6200;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.82rem;
    line-height: 1.5;
}
.api-banner code { background: rgba(0,0,0,0.06); padding: 1px 6px; border-radius: 4px; font-size: 0.78rem; }

/* ---------------------------------------------------------------- */
/* Timeline list                                                      */
/* ---------------------------------------------------------------- */
.timeline-wrap { max-width: 900px; margin-top: 10px; }

.timeline { position: relative; }

.timeline-row {
    position: relative;
    display: grid;
    grid-template-columns: 46px 20px 34px 1fr 24px;
    align-items: start;
    column-gap: 12px;
    padding: 10px 0;
    cursor: pointer;
}

.timeline-row::before {
    content: '';
    position: absolute;
    left: 68px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--text-dark);
    z-index: 0;
}
.timeline-row:first-child::before { top: 18px; }
.timeline-row:last-child::before { bottom: calc(100% - 18px); }

.row-year {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding-top: 6px;
    text-align: right;
    white-space: nowrap;
}

.row-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-dark);
    margin: 12px auto 0;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.row-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eceef7;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
}
.row-icon img { width: 100%; height: 100%; object-fit: cover; }

.row-body { min-width: 0; }
.row-title { font-size: 0.95rem; font-weight: 500; color: var(--text-dark); line-height: 1.3; }
.row-title .upcoming-flag { color: var(--primary-blue); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; margin-left: 6px; }
.row-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.row-check {
    width: 20px;
    height: 20px;
    border: 2px solid #9e9e9e;
    border-radius: 3px;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: all .12s;
}
.row-check:hover { border-color: var(--primary-blue); }
.row-check svg { width: 14px; height: 14px; opacity: 0; color: #fff; transition: opacity .12s; }
.timeline-row.watched .row-check { background: var(--success); border-color: var(--success); }
.timeline-row.watched .row-check svg { opacity: 1; }
.timeline-row.watched .row-title { color: #616161; }

.timeline-row.upcoming { cursor: default; }
.timeline-row.upcoming .row-check { opacity: 0.35; cursor: not-allowed; }

/* expand accordion */
.row-detail {
    grid-column: 3 / 4;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
    font-size: 0.86rem;
    color: #424242;
    line-height: 1.55;
}
.timeline-row.expanded .row-detail { max-height: 400px; padding-top: 8px; }
.row-detail-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    text-decoration: none;
}
.chip-btn.trailer { background: #212121; color: #fff; border-color: #212121; }
.chip-btn svg { width: 14px; height: 14px; }

.results-meta { font-size: 0.78rem; color: var(--text-muted); margin: 12px 0 6px; }
.empty-state { padding: 60px 10px; text-align: center; color: var(--text-muted); }
.empty-state h3 { color: var(--text-dark); margin-bottom: 6px; }

/* ---------------------------------------------------------------- */
/* Config modal                                                       */
/* ---------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.config-modal {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 520px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    transform: translateY(10px);
    transition: transform .2s;
}
.modal-overlay.open .config-modal { transform: translateY(0); }

.config-modal h2 { font-size: 1.1rem; font-weight: 600; margin: 0; padding: 20px 24px 4px; }
.config-scroll { overflow-y: auto; padding: 4px 24px 8px; }

.config-section { padding: 12px 0; border-bottom: 1px solid #f0f0f0; }
.config-label { display: block; font-size: 0.85rem; color: var(--text-dark); margin-bottom: 8px; font-weight: 500; }
.config-label.block { margin-bottom: 10px; }

.help-text { font-size: 0.86rem; line-height: 1.6; color: #424242; margin: 0; }
.help-text a { color: var(--primary-blue); font-weight: 600; text-decoration: none; }
.help-text a:hover { text-decoration: underline; }

.radio-opt {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 22px;
    font-size: 0.88rem;
    color: var(--text-dark);
    cursor: pointer;
    position: relative;
}
.radio-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #9e9e9e;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.radio-dot::after {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--primary-blue);
    transform: scale(0);
    transition: transform .1s;
}
.radio-opt input:checked ~ .radio-dot { border-color: var(--primary-blue); }
.radio-opt input:checked ~ .radio-dot::after { transform: scale(1); }

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-pill {
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--tag-inactive-bg);
    color: var(--tag-inactive-text);
    transition: all .12s;
}
.filter-pill.active { background: var(--primary-blue); color: #fff; }

.config-footer { padding: 14px 24px 20px; }
.btn-close {
    background: var(--tag-inactive-bg);
    border: none;
    border-radius: 4px;
    padding: 10px 22px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
}
.btn-close:hover { background: #d5d5d5; }

/* ---------------------------------------------------------------- */
/* Responsive                                                        */
/* ---------------------------------------------------------------- */
@media (max-width: 860px) {
    .sidebar-toggle { display: flex; }
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--topbar-h);
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .2s;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 18px 16px 60px; }
    .brand span { display: none; }
}

@media (max-width: 480px) {
    .timeline-row { grid-template-columns: 34px 16px 28px 1fr 22px; column-gap: 8px; }
    .timeline-row::before { left: 50px; }
    .row-year { font-size: 0.68rem; }
}
