/* ============================================
   Theatracker — Modern Visual Overhaul
   Inspired by Vercel / Linear / Raycast
   ============================================ */

/* --- Design Tokens --- */
:root {
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --transition: 150ms ease;
}

[data-theme="dark"] {
    --page-bg: #09090b;
    --card-bg: #111113;
    --card-border: rgba(255, 255, 255, 0.07);
    --card-hover-border: rgba(255, 255, 255, 0.14);
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    --pill-bg: rgba(255, 255, 255, 0.06);
    --pill-color: #e4e4e7;
    --pill-secondary: #71717a;
    --pill-hover-bg: rgba(255, 255, 255, 0.10);
    --nav-bg: rgba(9, 9, 11, 0.8);
    --nav-border: rgba(255, 255, 255, 0.07);
    --nav-hover-bg: rgba(255, 255, 255, 0.08);
    --link-color: #60a5fa;
    --link-hover: #93c5fd;
    --btn-primary-bg: #3b82f6;
    --btn-primary-hover: #2563eb;
    --btn-primary-text: #fff;
    --btn-outline-border: rgba(255, 255, 255, 0.12);
    --btn-outline-hover-bg: rgba(255, 255, 255, 0.06);
    --card-shadow: none;
    --card-hover-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --input-bg: #18181b;
    --input-border: rgba(255, 255, 255, 0.1);
    --separator: rgba(255, 255, 255, 0.06);
    --badge-error: #ef4444;
    --pico-background-color: var(--page-bg);
    --pico-color: var(--text-primary);
    --pico-muted-color: var(--text-secondary);
    --pico-muted-border-color: var(--card-border);
}

[data-theme="light"] {
    --page-bg: #fafafa;
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.07);
    --card-hover-border: rgba(0, 0, 0, 0.13);
    --text-primary: #09090b;
    --text-secondary: #71717a;
    --text-muted: #a1a1aa;
    --pill-bg: rgba(0, 0, 0, 0.04);
    --pill-color: #18181b;
    --pill-secondary: #71717a;
    --pill-hover-bg: rgba(0, 0, 0, 0.07);
    --nav-bg: rgba(250, 250, 250, 0.8);
    --nav-border: rgba(0, 0, 0, 0.07);
    --nav-hover-bg: rgba(0, 0, 0, 0.05);
    --link-color: #2563eb;
    --link-hover: #1d4ed8;
    --btn-primary-bg: #2563eb;
    --btn-primary-hover: #1d4ed8;
    --btn-primary-text: #fff;
    --btn-outline-border: rgba(0, 0, 0, 0.12);
    --btn-outline-hover-bg: rgba(0, 0, 0, 0.04);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    --card-hover-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --input-bg: #ffffff;
    --input-border: rgba(0, 0, 0, 0.12);
    --separator: rgba(0, 0, 0, 0.06);
    --badge-error: #dc2626;
    --pico-background-color: var(--page-bg);
    --pico-color: var(--text-primary);
    --pico-muted-color: var(--text-secondary);
    --pico-muted-border-color: var(--card-border);
}

/* --- Global Theme Transition --- */
*, *::before, *::after {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* --- Global Overrides --- */
html {
    background: var(--page-bg);
}

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-primary);
    background: var(--page-bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--link-color);
    transition: color var(--transition);
}
a:hover {
    color: var(--link-hover);
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

small {
    color: var(--text-secondary);
}

/* --- Navigation --- */
nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--nav-border);
    padding: 0.625rem 0;
    margin-bottom: 2rem;
}
nav ul {
    flex-wrap: wrap;
}
nav li a {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: color var(--transition), background var(--transition);
}
nav li a:hover {
    color: var(--text-primary);
    background: var(--nav-hover-bg);
}
nav li strong {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

/* Brand icon */
.brand-icon {
    width: 1.5rem;
    height: 1.5rem;
    vertical-align: -0.2em;
    margin-right: 0.3rem;
}
[data-theme="dark"] .brand-icon {
    filter: invert(1) brightness(0.85);
}
[data-theme="light"] .brand-icon {
    opacity: 0.75;
}

/* --- Cards (articles) --- */
article {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
article:hover {
    border-color: var(--card-hover-border);
    box-shadow: var(--card-hover-shadow);
}
article header {
    padding: 0;
    margin-bottom: 1.5rem;
    border-bottom: none;
    background: none;
}

/* --- Movie Card (Today page) --- */
.movie-card {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}
.movie-card .poster {
    width: 64px;
    min-width: 64px;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.movie-card .info {
    flex: 1;
    min-width: 0;
}
.movie-card .info > a {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
}
.movie-card .info > small {
    color: var(--text-muted);
    margin-left: 0.25rem;
}

/* --- Pill Grid --- */
.pill-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* --- Showtime Pills --- */
.showtime-pill {
    display: flex;
    flex-direction: column;
    gap: 0.2em;
    padding: 0.6em 0.9em;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    background: var(--pill-bg);
    color: var(--pill-color);
    border: 1px solid var(--card-border);
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
    text-decoration: none;
}
.showtime-pill:hover {
    background: var(--pill-hover-bg);
    border-color: var(--card-hover-border);
    transform: translateY(-1px);
}
a.showtime-pill {
    cursor: pointer;
    color: var(--pill-color);
    text-decoration: none;
}
a.showtime-pill:hover {
    color: var(--pill-color);
}
.showtime-pill .pill-time {
    display: flex;
    align-items: baseline;
    gap: 0.4em;
}
.showtime-pill .pill-time strong {
    font-size: 1rem;
    font-weight: 600;
}
.showtime-pill .pill-time small {
    color: var(--pill-secondary);
    font-size: 0.75rem;
}
.showtime-pill .pill-details {
    color: var(--pill-secondary);
    font-size: 0.78rem;
    line-height: 1.3;
}

/* --- Buttons --- */
button, [type="submit"] {
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    cursor: pointer;
}
button:hover, [type="submit"]:hover {
    filter: brightness(1.1);
}
button:active, [type="submit"]:active {
    filter: brightness(0.95);
}
button[disabled], .scrape-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Button groups */
.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.btn-group button {
    margin: 0;
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
    height: 32px;
}

/* --- Tables --- */
table {
    border-collapse: collapse;
    width: 100%;
}
table th {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--separator);
}
th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
}
th.sortable:hover {
    color: var(--text-primary);
}
table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--separator);
    color: var(--text-secondary);
}
table tr:last-child td {
    border-bottom: none;
}

/* --- Poster Images --- */
.poster-thumb {
    width: 36px;
    border-radius: var(--radius-sm);
    vertical-align: middle;
}
.poster-large {
    width: 150px;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* --- Showtime Rows (Movie Detail) --- */
.showtime-row {
    display: flex;
    gap: 1.25rem;
    align-items: baseline;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--separator);
}
.showtime-row:last-child {
    border-bottom: none;
}
.showtime-row-time {
    min-width: 11rem;
    white-space: nowrap;
    font-weight: 500;
    color: var(--text-primary);
}
.showtime-row-time small {
    color: var(--text-muted);
    font-weight: 400;
}
.showtime-row-details {
    flex: 1;
}
.showtime-row-details a {
    font-weight: 500;
    margin-right: 0.4em;
}
.showtime-row-details small {
    color: var(--text-muted);
}

/* --- Filter Sections --- */
details {
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 0;
    margin-bottom: 1.25rem;
    background: var(--card-bg);
}
details summary {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.75rem 1rem;
    cursor: pointer;
    color: var(--text-secondary);
}
details[open] summary {
    border-bottom: 1px solid var(--separator);
}
details fieldset {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    padding: 0.75rem 1rem;
    border: none;
    margin: 0;
}
details fieldset legend {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}
details fieldset label {
    font-size: 0.85rem;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* --- Inputs --- */
input[type="search"],
input[type="text"],
input[type="url"] {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: border-color var(--transition);
}
input[type="search"]:focus,
input[type="text"]:focus,
input[type="url"]:focus {
    border-color: var(--link-color);
    outline: none;
}

/* --- Error Badge & Tooltip --- */
.error-badge-wrap {
    position: relative;
    display: inline-block;
}
.error-badge {
    color: var(--badge-error);
    cursor: help;
}
.error-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: normal;
    width: max-content;
    max-width: 350px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 50;
    pointer-events: none;
}
.error-badge-wrap:hover .error-tooltip {
    display: block;
}

/* --- Movie Detail Header --- */
.movie-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5em;
}
.movie-detail-info {
    flex: 1;
    min-width: 0;
}
.movie-detail-synopsis {
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}
.movie-detail-synopsis-mobile {
    display: none;
}

/* --- Synopsis --- */
article > p {
    color: var(--text-secondary);
    line-height: 1.7;
}


/* --- Status Widget --- */
.status-section h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

/* --- Scraping Indicator --- */
.scraping-indicator {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    vertical-align: -0.1em;
    margin-left: 0.4em;
    border: 2px solid var(--text-muted);
    border-top-color: var(--link-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Scrape Banner --- */
#scrape-banner:not(:empty) {
    background: var(--pill-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* --- Loading States --- */
[aria-busy="true"] {
    min-height: 4rem;
    text-align: center;
}
[aria-busy="true"]::before {
    display: block;
    margin: 0 auto;
}

/* --- Hamburger & Sidebar (Mobile) --- */
.hamburger, .sidebar, .sidebar-overlay {
    display: none;
}

.hamburger {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    box-shadow: none;
    height: auto;
}
.hamburger:hover {
    box-shadow: none;
    transform: translateY(-50%);
    color: var(--text-primary);
    filter: none;
}

.sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100%;
    background: var(--card-bg);
    border-left: 1px solid var(--card-border);
    z-index: 1001;
    transition: right 0.25s ease;
    padding: 1.5rem;
    overflow-y: auto;
}
.sidebar.open {
    right: 0;
}
.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 2rem 0 0 0;
}
.sidebar ul li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--separator);
}
.sidebar ul li:last-child {
    border-bottom: none;
}
.sidebar ul li a {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    display: block;
    padding: 0.3rem 0;
}
.sidebar ul li a:hover {
    opacity: 0.7;
}
.sidebar-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    box-shadow: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    height: auto;
}
.sidebar-close:hover {
    box-shadow: none;
    transform: none;
    color: var(--text-primary);
}
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* --- Movie Toolbar (filters button, sits before sort bar in partial) --- */
.movie-toolbar {
    margin-bottom: 0.75rem;
}
.movie-toolbar .movie-sort-btn svg {
    vertical-align: -0.15em;
    margin-right: 0.2em;
}

/* --- Filters Dropdown (full-width below toolbar) --- */
.filters-dropdown {
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 0;
    margin-bottom: 1rem;
    background: var(--card-bg);
}
.filters-dropdown:not([open]) {
    display: none;
}
.filters-dropdown fieldset {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    padding: 0.5rem 0.75rem;
    border: none;
    margin: 0;
}
.filters-dropdown fieldset legend {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
.filters-dropdown fieldset label {
    font-size: 0.8rem;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* --- Date Range Picker --- */
.date-range-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.25rem;
}
.date-range-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
/* Wrapper clips the native calendar icon off the right edge */
.date-input-wrap {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.date-input-wrap:hover {
    border-color: var(--card-hover-border);
}
.date-input-wrap input[type="date"] {
    font-size: 0.8rem;
    padding: 0.35rem 0.4rem;
    margin-bottom: 0;
    height: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    /* Push native icon off-screen by making input wider than wrapper */
    width: calc(100% + 3rem);
}
.date-input-wrap input[type="date"]:focus {
    outline: none;
    box-shadow: none;
}
/* Custom icon positioned exactly where we want it */
.date-input-wrap .date-icon {
    position: absolute;
    right: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.85rem;
    height: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* --- Movie List Cards --- */
.movie-sort-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.movie-sort-btn {
    background: var(--pill-bg);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    height: auto;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.movie-sort-btn.active {
    color: var(--text-primary);
    border-color: var(--card-hover-border);
}
.movie-sort-btn:hover {
    filter: none;
    color: var(--text-primary);
    border-color: var(--card-hover-border);
}

.movie-list-cards {
    display: flex;
    flex-direction: column;
}
.movie-card-link {
    text-decoration: none;
    color: inherit;
}
.movie-card-link:hover {
    color: inherit;
}
.movie-card-link:hover .movie-list-card {
    background: var(--pill-hover-bg);
}
.movie-list-card {
    display: flex;
    gap: 1rem;
    align-items: center;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--separator);
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.movie-list-card-poster {
    width: 44px;
    min-width: 44px;
    border-radius: var(--radius-sm);
}
.movie-list-card-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.movie-list-card-title {
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
}
.movie-list-card-title small {
    color: var(--text-muted);
    font-weight: 400;
}
.movie-list-card-cinemas {
    color: var(--text-secondary);
    line-height: 1.3;
}
.movie-list-card-meta {
    text-align: right;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.movie-list-card-meta small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    nav {
        position: sticky;
    }
    .hamburger {
        display: block;
        position: absolute;
        right: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
    }
    .nav-links-desktop {
        display: none;
    }
    .sidebar, .sidebar-overlay {
        display: block;
    }

    .movie-card .poster { width: 50px; min-width: 50px; }
    .movie-card .info > a { font-size: 0.95rem; }

    .pill-grid {
        grid-template-columns: 1fr;
    }
    .showtime-pill { font-size: 0.82rem; }

    .btn-group { flex-direction: column; }
    .btn-group button { width: 100%; }

    .movie-detail-synopsis-desktop { display: none; }
    .movie-detail-synopsis-mobile { display: block; font-size: 0.78rem; }

    .movie-list-card { flex-wrap: wrap; }
    .movie-list-card-meta {
        text-align: left;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem 0.5rem;
        width: 100%;
        padding-left: calc(44px + 1rem);
        white-space: normal;
        font-size: 0.8rem;
    }

    table { display: block; overflow-x: auto; }

    .poster-large { width: 90px; }

    .showtime-row {
        flex-direction: column;
        gap: 0.15rem;
    }
    .showtime-row-time { min-width: auto; }

    /* On mobile/tablet, use native date inputs instead of the desktop icon trick */
    .date-input-wrap {
        overflow: visible;
        border: none;
    }
    .date-input-wrap input[type="date"] {
        width: auto;
        border: 1px solid var(--card-border);
        border-radius: var(--radius-sm);
    }
    .date-input-wrap .date-icon {
        display: none;
    }

    .container { padding-left: 1rem; padding-right: 1rem; }

    nav li a { font-size: 0.8rem; padding: 0.35rem 0.5rem; }
}
