/* ==========================================================================
   MAME TV — theme clair, sobre.
   Surface plate, hairlines, une seule couleur d'accent. Pas de decor gratuit.
   ========================================================================== */

:root {
    color-scheme: light;

    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-soft: #e8e8ed;
    --line: #d2d2d7;
    --hairline: #e5e5ea;

    --ink: #1d1d1f;
    --ink-secondary: #6e6e73;
    --ink-tertiary: #86868b;

    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-soft: rgba(0, 113, 227, 0.1);
    --live: #e30000;
    --live-soft: rgba(227, 0, 0, 0.08);
    --ok: #1d7a3e;
    --ok-soft: rgba(29, 122, 62, 0.1);

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);

    --r-panel: 18px;
    --r-card: 14px;
    --r-input: 10px;
    --r-pill: 999px;

    --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    --speed: 180ms;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    scroll-behavior: smooth;
    /* La topbar full-bleed depasse de la largeur du viewport (scrollbar
       verticale incluse dans 100vw) : on coupe sans casser position:sticky. */
    overflow-x: clip;
}

::selection {
    background: rgba(0, 113, 227, 0.18);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Inter, Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

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

/* Chrome */

.shell {
    width: min(1320px, calc(100% - 40px));
    margin: 0 auto;
    padding: 0 0 64px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 56px;
    margin: 0 calc(50% - 50vw) 28px;
    padding: 8px max(20px, calc(50vw - 660px));
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid var(--hairline);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 190px;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 15px;
    font-weight: 650;
}

.brand small {
    color: var(--ink-secondary);
    font-size: 11.5px;
}

.brand small,
.muted,
.small {
    color: var(--ink-secondary);
}

.nav {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface-soft);
    border-radius: var(--r-pill);
}

.nav a {
    padding: 6px 14px;
    border-radius: var(--r-pill);
    color: var(--ink);
    font-size: 13px;
    font-weight: 550;
    text-decoration: none;
    transition: background var(--speed) var(--ease);
}

.nav a:hover {
    background: rgba(255, 255, 255, 0.9);
}

.top-status {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    min-width: 140px;
    color: var(--ink-secondary);
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.top-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.compact-button {
    min-height: 34px;
    padding: 0 13px;
    font-size: 13px;
}

/* Points d'etat */

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--ink-tertiary);
}

.dot-live {
    background: var(--live);
}

.dot-ok {
    background: var(--ok);
}

.dot-live {
    animation: blink 2.4s var(--ease) infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* Typographie */

.eyebrow,
.panel-kicker {
    margin: 0 0 8px;
    color: var(--ink-tertiary);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 14px;
    font-size: clamp(34px, 5vw, 56px);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.02em;
}

h2 {
    margin-bottom: 10px;
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -0.012em;
}

h3 {
    font-weight: 600;
}

.lead {
    max-width: 620px;
    color: var(--ink-secondary);
    font-size: 18px;
    line-height: 1.55;
}

.hero-actions,
.stream-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Boutons */

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--r-pill);
    font: inherit;
    font-size: 14px;
    font-weight: 550;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background var(--speed) var(--ease),
        color var(--speed) var(--ease),
        border-color var(--speed) var(--ease),
        transform var(--speed) var(--ease);
}

.button:active,
button:active {
    transform: scale(0.97);
}

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

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

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

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

.button-danger {
    color: var(--live);
    background: var(--surface);
    border-color: var(--line);
}

.button-danger:hover {
    border-color: var(--live);
    background: var(--live-soft);
}

.icon-button {
    width: 40px;
    padding: 0;
    color: var(--ink);
    background: var(--surface);
    border-color: var(--line);
}

/* Surfaces */

.panel,
.workspace,
.metric {
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-panel);
}

.panel p {
    color: var(--ink-secondary);
    line-height: 1.55;
}

.section-grid,
.control-grid,
.admin-layout,
.player-layout,
.auth-layout,
.tv-layout {
    display: grid;
    gap: 16px;
}

.admin-layout {
    gap: 20px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.section-heading.compact h1,
.section-heading.compact h2 {
    margin-bottom: 0;
    font-size: 26px;
}

.control-grid {
    grid-template-columns: minmax(320px, 0.9fr) minmax(280px, 0.65fr) minmax(280px, 0.65fr);
    align-items: start;
}

/* Formulaires */

label {
    display: block;
    margin: 14px 0 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-input);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    transition: border-color var(--speed) var(--ease),
        box-shadow var(--speed) var(--ease);
}

input::placeholder {
    color: var(--ink-tertiary);
}

select {
    cursor: pointer;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

.message-slot {
    min-height: 50px;
    margin-top: 12px;
}

.alert {
    padding: 11px 14px;
    border-radius: var(--r-input);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid;
}

.alert-success {
    color: var(--ok);
    background: var(--ok-soft);
    border-color: rgba(29, 122, 62, 0.25);
}

.alert-error {
    color: #b3261e;
    background: var(--live-soft);
    border-color: rgba(227, 0, 0, 0.25);
}

.alert-info {
    color: #1a56a8;
    background: var(--accent-soft);
    border-color: rgba(0, 113, 227, 0.25);
}

.copy-row,
.health-lines div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--hairline);
}

.copy-row:last-child,
.health-lines div:last-child {
    border-bottom: 0;
}

.copy-row span,
.health-lines span {
    color: var(--ink-secondary);
}

code,
.mono {
    font-family: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

code {
    padding: 3px 6px;
    border-radius: 6px;
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 12.5px;
}

/* Listes */

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

.stream-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    transition: background var(--speed) var(--ease);
}

.stream-row:hover {
    background: var(--bg);
}

.stream-row strong,
.stream-row span {
    display: block;
}

.stream-row span {
    margin-top: 3px;
    color: var(--ink-secondary);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 110px;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: var(--r-card);
    color: var(--ink-secondary);
    text-align: center;
}

.log-view {
    min-height: 220px;
    max-height: 400px;
    overflow: auto;
    margin: 0;
    padding: 15px 17px;
    border-radius: var(--r-card);
    border: 1px solid var(--line);
    background: #1d1d1f;
    color: #d6d6da;
    font-family: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Player */

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

.player-main {
    min-width: 0;
}

.video-shell {
    position: relative;
    overflow: hidden;
    background: #000;
    border-radius: var(--r-panel);
    border: 1px solid var(--line);
}

.video-js {
    width: 100%;
    min-height: min(64vh, 700px);
}

.offline-cover {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    gap: 8px;
    align-content: center;
    background: #0a0a0a;
    color: #fff;
    text-align: center;
}

.offline-cover strong {
    font-size: 24px;
    font-weight: 650;
    letter-spacing: -0.015em;
}

.offline-cover span {
    color: rgba(255, 255, 255, 0.6);
}

.side-rail {
    display: grid;
    gap: 14px;
}

.status-panel strong,
.status-panel span {
    display: block;
}

.status-panel strong {
    margin-bottom: 6px;
    font-size: 24px;
    font-weight: 650;
    letter-spacing: -0.015em;
}

.status-panel span:last-child {
    color: var(--ink-secondary);
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.metric {
    padding: 15px;
}

.metric span,
.metric strong {
    display: block;
}

.metric span {
    margin-bottom: 5px;
    color: var(--ink-tertiary);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.metric strong {
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

/* Auth */

.auth-layout {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 460px);
    align-items: center;
    min-height: 600px;
}

.auth-copy {
    padding: clamp(20px, 4vw, 56px);
}

/* Front TV */

.tv-layout {
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: start;
}

.tv-main {
    min-width: 0;
}

.tv-heading h1 {
    font-size: clamp(28px, 3.5vw, 40px);
}

.watch-stage {
    position: relative;
    min-height: min(60vh, 660px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-panel);
    background: #000;
}

.watch-stage .video-js,
.youtube-frame {
    width: 100%;
    height: min(60vh, 660px);
    min-height: 400px;
}

.youtube-frame {
    display: block;
    border: 0;
}

.empty-player {
    display: grid;
    place-items: center;
    align-content: center;
    min-height: min(60vh, 660px);
    color: #fff;
    background: #0a0a0a;
}

.empty-player strong {
    font-size: 38px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.empty-player span {
    color: rgba(255, 255, 255, 0.6);
}

.watch-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 13px 0 16px;
}

.content-rail {
    position: sticky;
    top: 72px;
    display: grid;
    gap: 14px;
}

.content-list {
    display: grid;
    gap: 8px;
}

.content-item {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    min-height: 72px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    transition: background var(--speed) var(--ease),
        border-color var(--speed) var(--ease);
}

.content-item:hover {
    border-color: var(--ink-tertiary);
}

.content-item:active {
    background: var(--bg);
}

.content-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.content-thumb {
    display: block;
    width: 112px;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 8px;
    background: var(--surface-soft);
}

.content-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.live-thumb {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: #fff;
    background: #1d1d1f;
}

.live-thumb span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 650;
    font-size: 12px;
    letter-spacing: 0.1em;
}

.live-thumb span::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--live);
}

.content-copy {
    display: grid;
    align-content: center;
    gap: 5px;
    min-width: 0;
}

.content-copy strong {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    text-overflow: ellipsis;
}

.content-copy small {
    color: var(--ink-secondary);
    font-size: 12px;
}

/* Commentaires */

.inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin-bottom: 14px;
}

.inline-form input {
    margin: 0;
}

.comment-list {
    display: grid;
    gap: 8px;
}

.comment {
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
}

.comment p {
    margin: 5px 0;
    color: var(--ink);
}

.comment small {
    color: var(--ink-secondary);
}

.compact-empty {
    min-height: 68px;
    padding: 14px;
}

.submit-panel form + form {
    margin-top: 14px;
}

/* Regie admin */

.admin-catalog-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
    margin: 14px 0;
}

.admin-content-list {
    margin-top: 12px;
}

.admin-content-item {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
}

/* Studio */

.studio-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}

.studio-main,
.studio-side {
    display: grid;
    gap: 14px;
}

.studio-side {
    position: sticky;
    top: 72px;
}

.studio-list {
    margin-top: 12px;
}

.studio-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
    transition: background var(--speed) var(--ease);
}

.studio-item:hover {
    background: var(--bg);
}

.studio-item strong,
.studio-item small {
    display: block;
}

.studio-item small {
    margin-top: 4px;
    color: var(--ink-secondary);
    font-size: 12px;
}

.studio-item p {
    margin: 7px 0 0;
    color: var(--ink-secondary);
    line-height: 1.45;
}

/* Mode demo */

.demo-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 620px;
    margin-top: 16px;
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
}

.demo-banner strong {
    display: block;
    margin-bottom: 3px;
    font-size: 13.5px;
    font-weight: 600;
}

.demo-banner p {
    margin: 0;
    color: var(--ink-secondary);
    font-size: 13px;
}

.chip-demo {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    margin-top: 2px;
    padding: 3px 9px;
    border: 1px solid var(--accent);
    border-radius: var(--r-pill);
    color: var(--accent);
    background: var(--surface);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

/* Scrollbars */

.log-view::-webkit-scrollbar,
body::-webkit-scrollbar {
    width: 10px;
}

.log-view::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: content-box;
}

.log-view::-webkit-scrollbar-track {
    background: transparent;
}

body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.22);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: content-box;
}

body::-webkit-scrollbar-track {
    background: transparent;
}

/* Responsive */

@media (max-width: 980px) {
    .player-layout,
    .auth-layout,
    .tv-layout,
    .studio-layout {
        grid-template-columns: 1fr;
    }

    .control-grid {
        grid-template-columns: 1fr;
    }

    .content-rail,
    .studio-side {
        position: static;
    }
}

@media (max-width: 720px) {
    .shell {
        width: min(100% - 24px, 1320px);
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        padding: 10px 16px 14px;
    }

    .section-heading,
    .stream-row {
        align-items: stretch;
        flex-direction: column;
    }

    .brand,
    .top-status {
        min-width: 0;
    }

    .nav {
        width: 100%;
    }

    .nav a {
        flex: 1;
        text-align: center;
    }

    .panel,
    .workspace {
        padding: 16px;
    }

    .lead {
        font-size: 16px;
    }

    .stream-actions {
        width: 100%;
    }

    .stream-actions .button {
        flex: 1;
    }

    .top-actions,
    .watch-actions,
    .inline-form {
        align-items: stretch;
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .content-item {
        grid-template-columns: 92px minmax(0, 1fr);
    }

    .content-thumb {
        width: 92px;
    }

    .admin-catalog-grid {
        grid-template-columns: 1fr;
    }

    .watch-stage .video-js,
    .youtube-frame,
    .empty-player {
        min-height: 260px;
        height: 300px;
    }
}

/* Accessibilite */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .dot-live {
        animation: none;
    }

    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: more) {
    :root {
        --line: #86868b;
        --hairline: #a1a1a6;
        --ink-secondary: #3a3a3c;
    }
}
