:root {
    color-scheme: dark;
    --bg: #0b0e14;
    --panel: #131821;
    --panel-hover: #18202c;
    --border: #293242;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --accent: #38bdf8;
    --accent-strong: #2563eb;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 12px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.hidden { display: none !important; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.gradient-text {
    color: var(--accent);
    background: linear-gradient(135deg, #67e8f9, #3b82f6);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-layout {
    min-height: 100vh;
    padding: 32px 20px;
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(100%, 430px);
    padding: 36px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: 1.75rem; }
h2 { margin-bottom: 4px; font-size: 1.25rem; }

.eyebrow {
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.supporting-text, .section-description, .form-note {
    color: var(--muted);
}

.supporting-text { margin-bottom: 28px; }
.section-description { margin: 4px 0 0; font-size: 0.9rem; }
.form-note { margin: -4px 0 20px; font-size: 0.82rem; }

.period-fieldset {
    margin: 0 0 20px;
    padding: 0;
    border: 0;
}

.period-fieldset legend { margin-bottom: 7px; color: #d1d5db; font-size: 0.9rem; }
.period-fieldset .form-note { margin: 0 0 12px; }

.period-row {
    position: relative;
    margin-bottom: 12px;
    padding: 14px 44px 4px 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    background: #0e131b;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.period-row label { color: var(--muted); font-size: 0.78rem; }
.period-row label span { color: #6b7280; }
.period-row input { margin-top: 4px; }
.period-row label:nth-child(3) { grid-column: 1 / -1; }

.remove-period {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 0;
    font-size: 1.4rem;
}

.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 7px; color: #d1d5db; font-size: 0.9rem; }

input, select {
    width: 100%;
    padding: 11px 13px;
    color: var(--text);
    background: #0e131b;
    border: 1px solid var(--border);
    border-radius: 8px;
}

input:focus, select:focus, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.form-error {
    margin: 0 0 16px;
    color: #fecaca;
    font-size: 0.9rem;
}

.btn-primary, .button-secondary, .nav-button, .action-btn {
    border: 0;
    border-radius: 8px;
    font-weight: 650;
}

.btn-primary {
    width: 100%;
    padding: 12px 16px;
    color: white;
    background: linear-gradient(135deg, #0284c7, var(--accent-strong));
}

.btn-primary:hover { filter: brightness(1.1); }

.button-secondary {
    padding: 9px 13px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
}

.button-secondary:hover { background: var(--panel-hover); }

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(11, 14, 20, 0.96);
    border-bottom: 1px solid var(--border);
}

.header-content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 18px 24px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.header-content h1 { margin: 0; font-size: 1.35rem; }
.account-email { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }
.header-actions { display: flex; gap: 8px; }

.app-nav {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 22px;
}

.nav-button {
    padding: 10px 2px 11px;
    color: var(--muted);
    background: transparent;
    border-bottom: 2px solid transparent;
    border-radius: 0;
}

.nav-button.active { color: var(--text); border-bottom-color: var(--accent); }

.container {
    width: min(100%, 1048px);
    margin: 0 auto;
    padding: 32px 24px 64px;
}

.app-message {
    margin: 0 0 20px;
    padding: 12px 14px;
    color: #d1fae5;
    background: #064e3b;
    border-radius: 8px;
}

.app-message.error { color: #fee2e2; background: #7f1d1d; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 34px;
}

.stat-card { padding: 26px; }
.stat-title { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-value { margin: 8px 0 0; font-size: clamp(2rem, 6vw, 3rem); font-weight: 750; }

.list-section { margin-top: 8px; }
.section-header {
    margin-bottom: 16px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
}

.section-header h2 { display: flex; align-items: center; gap: 9px; }

.badge {
    min-width: 25px;
    padding: 2px 7px;
    color: #082f49;
    background: var(--accent);
    border-radius: 999px;
    font-size: 0.75rem;
    text-align: center;
}

.sync-actions { display: flex; align-items: center; gap: 12px; }
.sync-status { color: var(--muted); font-size: 0.8rem; }

.movie-list { display: grid; gap: 10px; }

.movie-item {
    min-height: 74px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.movie-item:hover { background: var(--panel-hover); }
.movie-info { min-width: 0; }
.movie-title { font-weight: 650; overflow-wrap: anywhere; }
.movie-title a { color: var(--text); text-decoration: none; }
.movie-title a:hover { color: var(--accent); text-decoration: underline; }
.movie-date { margin-top: 3px; color: var(--muted); font-size: 0.82rem; }
.movie-actions { display: flex; gap: 8px; flex-shrink: 0; }

.action-btn { padding: 8px 11px; }
.btn-alist { color: #d1fae5; background: #065f46; }
.btn-alist:hover { background: #047857; }
.btn-not { color: #fee2e2; background: #7f1d1d; }
.btn-not:hover { background: #991b1b; }

.status-select { width: auto; min-width: 132px; flex-shrink: 0; }
.status-a_list { border-color: #047857; }
.status-not_a_list { border-color: #991b1b; }
.status-excluded { border-color: #6b7280; }
.status-unreviewed { border-color: #a16207; }

.empty-state { padding: 34px; color: var(--muted); text-align: center; }

.history-header { align-items: center; }
.history-filters { width: min(100%, 460px); display: grid; grid-template-columns: minmax(150px, 1fr) 180px; gap: 10px; }

.data-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.data-card { padding: 24px; }
.data-card:first-child { grid-column: 1 / -1; }
.data-card .section-description { margin-bottom: 20px; }
.data-form { display: grid; gap: 12px; }
.data-form label { color: #d1d5db; font-size: 0.88rem; }
.button-link { display: inline-block; color: var(--text); text-decoration: none; }

.import-preview {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.import-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.import-counts div { padding: 12px 8px; background: #0e131b; border-radius: 8px; text-align: center; }
.import-counts strong, .import-counts span { display: block; }
.import-counts strong { font-size: 1.3rem; }
.import-counts span { color: var(--muted); font-size: 0.72rem; }

.import-samples { margin: 16px 0; display: grid; gap: 6px; }
.import-samples div { display: flex; justify-content: space-between; gap: 16px; font-size: 0.82rem; }
.import-samples div span:last-child { color: var(--muted); text-align: right; }

.danger-card { border-color: #7f1d1d; }
.danger-eyebrow { color: var(--danger); }
.button-danger {
    padding: 10px 13px;
    color: #fee2e2;
    background: #7f1d1d;
    border: 1px solid #991b1b;
    border-radius: 8px;
    font-weight: 650;
}
.button-danger:hover { background: #991b1b; }
.danger-card .data-form { margin-top: 14px; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    padding: 20px;
    display: none;
    place-items: center;
    background: rgba(0, 0, 0, 0.72);
}

.modal.active { display: grid; }
.modal-content { width: min(100%, 460px); max-height: calc(100vh - 40px); padding: 28px; overflow-y: auto; }
.modal-header { margin-bottom: 22px; display: flex; justify-content: space-between; align-items: start; }
.modal-header h2 { margin: 0; }
.close-modal { padding: 0 4px; color: var(--muted); background: transparent; border: 0; font-size: 1.8rem; line-height: 1; }

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    background: rgba(11, 14, 20, 0.72);
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 680px) {
    .auth-card { padding: 26px; }
    .header-content { align-items: flex-start; }
    .header-actions { flex-direction: column; }
    .container { padding: 24px 16px 48px; }
    .stats-grid { grid-template-columns: 1fr; }
    .section-header, .history-header { align-items: stretch; flex-direction: column; }
    .sync-actions { justify-content: space-between; }
    .history-filters { width: 100%; grid-template-columns: 1fr; }
    .data-grid { grid-template-columns: 1fr; }
    .data-card:first-child { grid-column: auto; }
    .import-counts { grid-template-columns: repeat(2, 1fr); }
    .period-row { grid-template-columns: 1fr; }
    .period-row label:nth-child(3) { grid-column: auto; }
    .movie-item { align-items: flex-start; flex-direction: column; }
    .movie-actions, .status-select { width: 100%; }
    .action-btn { flex: 1; }
}
