:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-soft: #eef3f2;
    --text: #17201d;
    --muted: #61716b;
    --line: #dbe3e1;
    --primary: #0f766e;
    --primary-dark: #0b5f58;
    --accent: #d97706;
    --danger: #b42318;
    --success: #127c45;
    --warning: #9a6700;
    --shadow: 0 16px 40px rgba(23, 32, 29, 0.08);
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 68px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand,
.topnav,
.topnav form {
    display: flex;
    align-items: center;
}

.brand {
    gap: 10px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background:
        linear-gradient(135deg, var(--primary), #43a047 55%, var(--accent));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.topnav {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topnav a,
.nav-button {
    min-height: 38px;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
}

.topnav a:hover,
.topnav a.is-active,
.nav-button:hover {
    background: var(--surface-soft);
    color: var(--text);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 56px;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.page-heading h1,
.empty-state h1,
.empty-state h2,
.form-panel h2,
.panel-heading h2,
.stream-card h2 {
    margin: 0;
    letter-spacing: 0;
}

.page-heading h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    line-height: 1.05;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary-dark);
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

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

.button-secondary {
    background: #173c38;
    color: #fff;
}

.button-ghost,
.button-small {
    background: var(--surface);
    border-color: var(--line);
    color: var(--text);
}

.button-danger {
    background: #fff4f2;
    border-color: #f2b8b2;
    color: var(--danger);
}

.button-small {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.88rem;
}

.notice {
    margin-bottom: 18px;
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-weight: 700;
}

.notice-success {
    border-color: #aad7bf;
    background: #effaf3;
    color: var(--success);
}

.notice-warning {
    border-color: #e6c673;
    background: #fff8e6;
    color: var(--warning);
}

.notice-error {
    border-color: #f2b8b2;
    background: #fff4f2;
    color: var(--danger);
}

.stream-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.stream-card,
.stat-card,
.table-panel,
.form-panel,
.auth-panel,
.meta-panel,
.install-panel,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stream-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 252px;
    overflow: hidden;
    padding: 0 0 18px;
}

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

.stream-card p {
    margin: 0;
    color: var(--muted);
}

.stream-card .button {
    margin-top: auto;
}

.stream-card h2,
.stream-card p,
.stream-card-head,
.stream-meta,
.stream-card .button {
    margin-left: 18px;
    margin-right: 18px;
}

.stream-preview {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #101816;
    text-decoration: none;
}

.stream-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 180ms ease;
}

.stream-preview:hover img {
    transform: scale(1.025);
}

.stream-preview-icon {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 24px rgba(16, 24, 22, 0.22);
}

.stream-preview-icon::before {
    position: absolute;
    top: 50%;
    left: 54%;
    width: 0;
    height: 0;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-left: 14px solid var(--primary-dark);
    content: "";
    transform: translate(-50%, -50%);
}

.stream-card-head,
.stream-meta,
.panel-heading,
.cell-actions,
.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stream-card-head,
.stream-meta,
.panel-heading {
    justify-content: space-between;
}

.muted,
.row-subtitle {
    color: var(--muted);
}

.row-subtitle {
    display: block;
    max-width: 420px;
    margin-top: 3px;
    overflow: hidden;
    font-size: 0.86rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 900;
}

.badge-live {
    background: #e9f8ef;
    color: var(--success);
}

.badge-scheduled {
    background: #fff8e6;
    color: var(--warning);
}

.badge-draft {
    background: #eef3f2;
    color: var(--muted);
}

.badge-offline {
    background: #fff4f2;
    color: var(--danger);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-weight: 800;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 2.1rem;
    line-height: 1;
}

.table-panel,
.form-panel,
.auth-panel,
.install-panel {
    padding: 18px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}

th,
td {
    padding: 13px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

.cell-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    min-width: 280px;
}

.cell-actions form {
    margin: 0;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 170px 170px auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 10px 12px;
    outline: none;
}

textarea {
    min-height: 118px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.span-two {
    grid-column: 1 / -1;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

.field-error {
    color: var(--danger);
    font-size: 0.86rem;
    font-weight: 800;
}

.editor-layout {
    display: grid;
    gap: 18px;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    justify-content: flex-end;
    padding: 14px 0 0;
    background: linear-gradient(to top, var(--bg) 70%, rgba(245, 247, 248, 0));
}

.auth-panel {
    width: min(460px, 100%);
    margin: 0 auto;
}

.empty-state {
    display: grid;
    justify-items: start;
    gap: 14px;
    padding: 30px;
}

.empty-state.compact {
    box-shadow: none;
}

.player-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.player-surface {
    display: grid;
    min-height: 420px;
    overflow: hidden;
    background: #101816;
    border-radius: 8px;
    box-shadow: var(--shadow);
    place-items: center;
}

.player-surface video,
.player-surface iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    background: #101816;
}

.player-surface audio {
    width: min(760px, calc(100% - 40px));
}

.meta-panel {
    display: grid;
    gap: 16px;
    padding: 18px;
}

.meta-panel > div {
    display: grid;
    gap: 5px;
}

.meta-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.meta-block p {
    margin: 0;
    color: var(--muted);
}

.install-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.install-shell {
    width: min(680px, 100%);
}

.config-list {
    display: grid;
    gap: 10px;
    margin: 0 0 20px;
}

.config-list div {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.config-list dt {
    color: var(--muted);
    font-weight: 900;
}

.config-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 880px) {
    .topbar,
    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar {
        position: static;
        padding: 16px;
    }

    .topnav {
        justify-content: flex-start;
    }

    .stats-grid,
    .player-layout,
    .two-columns,
    .filter-bar {
        grid-template-columns: 1fr;
    }

    .player-surface {
        min-height: 260px;
    }

    .span-two {
        grid-column: auto;
    }
}

@media (max-width: 560px) {
    .shell {
        width: min(100% - 20px, 1180px);
        padding-top: 22px;
    }

    .page-heading h1 {
        font-size: 2rem;
    }

    .button {
        width: 100%;
    }

    .topnav,
    .form-actions,
    .cell-actions {
        width: 100%;
    }

    .cell-actions {
        justify-content: flex-start;
    }
}
