:root {
    color-scheme: light dark;
    --bg: linear-gradient(160deg, #38d9e8 0%, #1e8fe8 100%);
    --nav-bg: rgba(255, 255, 255, 0.9);
    --nav-solid: #fff;
    --title: #0d2238;
    --surface: #fff;
    --text: #13253a;
    --muted: #5b6b7d;
    --line: #d7e1ec;
    --field: #fff;
    --accent: #006fd6;
    --accent-hover: #0059ad;
    --on-accent: #fff;
    --secondary: #e8eef5;
    --secondary-hover: #d5e0ec;
    --ok: #1a7f37;
    --ok-bg: #dafbe1;
    --error: #c62828;
    --shadow: 0 10px 30px rgba(0, 45, 90, 0.18);
    --backdrop: rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: linear-gradient(160deg, #0b1624 0%, #102338 100%);
        --nav-bg: rgba(10, 20, 32, 0.92);
        --nav-solid: #0a1420;
        --title: #e6edf7;
        --surface: #16263a;
        --text: #e6edf7;
        --muted: #93a4bd;
        --line: #2a3d55;
        --field: #0f1c2c;
        --accent: #38bdf8;
        --accent-hover: #7dd3fc;
        --on-accent: #062033;
        --secondary: #22364f;
        --secondary-hover: #2c4563;
        --ok: #4ade80;
        --ok-bg: #12351f;
        --error: #f87171;
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
        --backdrop: rgba(0, 0, 0, 0.65);
    }
}

[hidden] {
    display: none !important;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    user-select: none;
}

a {
    color: var(--accent);
}

#title {
    font-size: clamp(2rem, 1.2rem + 3.5vw, 3.4rem);
    text-align: center;
    color: var(--title);
    margin: 16px 16px 20px;
}

.back {
    max-width: 1200px;
    margin: 0 auto -8px;
    padding: 22px 16px 0;
}

.back a {
    font-weight: 600;
    text-decoration: none;
}

.back a:hover {
    text-decoration: underline;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dashboard {
    display: grid;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

.wide {
    grid-column: 1 / -1;
}

.card-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

@media (min-width: 900px) {
    .dashboard {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.card h2 {
    margin: 0;
    font-size: 1.2rem;
}

.toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 16px;
}

.spacer {
    flex: 1;
}

@media (max-width: 600px) {
    .toolbar select {
        flex: 1 1 60%;
    }
}

.hint, .empty, .status {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.status:empty {
    display: none;
}

.status.error {
    color: var(--error);
}

.status.success {
    color: var(--ok);
}

label {
    font-weight: 600;
    font-size: 0.9rem;
}

input, select {
    font: inherit;
    color: var(--text);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    padding: 0;
    accent-color: var(--accent);
}

input[type="file"]::file-selector-button {
    font: inherit;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    margin-right: 10px;
    background: var(--secondary);
    color: var(--text);
    cursor: pointer;
}

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

.button {
    font: inherit;
    font-weight: 700;
    color: var(--on-accent);
    background: var(--accent);
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

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

.button.secondary {
    color: var(--text);
    background: var(--secondary);
}

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

.button.danger {
    color: #fff;
    background: #c62828;
}

.button.danger:hover {
    background: #a91f1f;
}

.button.small {
    padding: 6px 12px;
    font-size: 0.9rem;
}

.button:disabled {
    opacity: 0.6;
    cursor: wait;
}

.pill {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--secondary);
    color: var(--muted);
}

.pill.online {
    background: var(--ok-bg);
    color: var(--ok);
}

.field-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

.dialog {
    border: none;
    border-radius: 14px;
    padding: 0;
    width: min(100% - 32px, 440px);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.dialog::backdrop {
    background: var(--backdrop);
}

.dialog form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
}

.dialog h2 {
    margin: 0;
    font-size: 1.2rem;
}

.dialog label, .form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form .button {
    align-self: flex-start;
}

.card-link {
    color: var(--text);
    text-decoration: none;
    transition: box-shadow 0.2s ease;
}

.card-link:hover {
    box-shadow: var(--shadow), 0 0 0 2px var(--accent);
}

.card-link .card-header .hint {
    color: var(--accent);
    font-weight: 600;
}

.dialog-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 480px) {
    .dialog-buttons .button {
        flex: 1;
    }

    .dialog-buttons .spacer {
        display: none;
    }
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 20px;
}

.media-item {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.media-content {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
}

.media-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
}

.media-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.player {
    display: block;
    width: 100%;
    max-height: 80vh;
    background: #000;
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.auth {
    min-height: 100vh;
    box-sizing: border-box;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.auth .brand {
    margin: 0;
    font-size: 2.3rem;
    font-weight: 800;
    color: var(--title);
}

.auth .card {
    width: min(100%, 400px);
    box-sizing: border-box;
    gap: 14px;
}

.auth h1 {
    margin: 0;
    font-size: 1.6rem;
}

.auth form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth form .button {
    margin-top: 4px;
}

.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.95rem;
}
