:root {
    --bg: #e8eef5;
    --bg-accent: #d3deeb;
    --surface: #ffffff;
    --text: #152033;
    --muted: #5a6a80;
    --border: #c5d0de;
    --accent: #0b5fff;
    --accent-hover: #0948c7;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --ok: #1a7f4b;
    --warn: #a36b00;
    --sidebar-w: 220px;
    --top-h: 56px;
    --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--text);
    background:
        linear-gradient(160deg, var(--bg-accent) 0%, transparent 45%),
        linear-gradient(0deg, #f4f7fb, var(--bg));
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--top-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.topbar__brand a { color: var(--text); text-decoration: none; }

.topbar__status { margin-left: .5rem; }
.topbar__user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: calc(100vh - var(--top-h));
}

.sidebar {
    background: rgba(255,255,255,.72);
    border-right: 1px solid var(--border);
    padding: 1rem .75rem;
    position: sticky;
    top: var(--top-h);
    align-self: start;
    height: calc(100vh - var(--top-h));
    overflow-y: auto;
}

.side-nav { display: flex; flex-direction: column; gap: .65rem; }
.side-nav__group { display: flex; flex-direction: column; gap: .25rem; }
.side-nav__label {
    display: block;
    padding: .2rem .7rem .05rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}
.side-nav a {
    display: block;
    padding: .55rem .7rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}
.side-nav a:hover { background: #eef3f9; }
.side-nav a.is-active {
    background: #e7efff;
    color: var(--accent);
    font-weight: 600;
}
.side-nav__advanced {
    margin: .1rem 0 0;
    border-radius: 8px;
}
.side-nav__advanced > summary {
    list-style: none;
    cursor: pointer;
    padding: .45rem .7rem;
    border-radius: 8px;
    font-size: .85rem;
    color: var(--muted);
    user-select: none;
}
.side-nav__advanced > summary::-webkit-details-marker { display: none; }
.side-nav__advanced > summary::before {
    content: '▸ ';
    font-size: .75rem;
}
.side-nav__advanced[open] > summary::before { content: '▾ '; }
.side-nav__advanced > summary:hover { background: #eef3f9; }
.side-nav__advanced a { margin-left: .35rem; }

.content { padding: 1.25rem 1.5rem 2.5rem; max-width: 960px; }
.content:has(.page--wide) { max-width: 1200px; }

.page-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin: 0 0 1.25rem;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .25rem;
}

.table-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    max-width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.data-table th,
.data-table td {
    padding: .7rem .85rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: #f3f6fa;
    white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table__title {
    font-weight: 600;
    word-break: break-word;
}
.data-table__meta {
    margin-top: .2rem;
    font-size: .8rem;
    font-weight: 400;
}
.data-table__row--expired td { opacity: .72; }
.mono-id {
    font-family: ui-monospace, Consolas, monospace;
    font-size: .8rem;
}

.section-title {
    margin: 1.75rem 0 .75rem;
    font-size: 1.1rem;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .85rem;
    margin: 1rem 0 1.5rem;
}
.status-card {
    display: block;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    transition: border-color .15s ease, transform .15s ease;
}
.status-card:hover {
    border-color: #9eb6d9;
    text-decoration: none;
    transform: translateY(-1px);
}
.status-card h2 {
    margin: 0 0 .45rem;
    font-size: .85rem;
    font-weight: 650;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.status-card__value {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    word-break: break-word;
}
.status-card .muted { margin: .35rem 0 0; font-size: .88rem; }
.status-card.is-loading { opacity: .92; }
.live-pulse {
    animation: live-pulse 1.2s ease-in-out infinite;
}
@keyframes live-pulse {
    0%, 100% { opacity: .45; }
    50% { opacity: 1; }
}

.meter {
    height: 10px;
    border-radius: 999px;
    background: #e3eaf3;
    overflow: hidden;
    margin: .85rem 0 1.25rem;
}
.meter > span {
    display: block;
    height: 100%;
    background: var(--accent);
}

.show-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .75rem;
}
.show-timeline__clip {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    padding: .85rem 1rem;
}
.show-timeline__clip-head {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
}
.show-timeline__pos {
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: .8rem;
    font-weight: 700;
    background: #e7efff;
    color: var(--accent);
}
.show-timeline__cues {
    list-style: none;
    margin: .7rem 0 0 2.5rem;
    padding: .55rem .7rem;
    border-left: 2px solid #c5d0de;
    display: grid;
    gap: .35rem;
}
.show-timeline__cues li {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem .65rem;
    align-items: center;
    font-size: .9rem;
}
.show-timeline__cue-title {
    font-weight: 600;
}

.page h1 { margin: 0 0 .35rem; font-size: clamp(1.5rem, 3vw, 1.9rem); }
.lead { margin: 0 0 1.25rem; color: var(--muted); }

.notice {
    padding: 1rem 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 1.25rem;
}
.notice p { margin: .4rem 0 0; color: var(--muted); }
.notice--info { border-color: #9eb6d9; background: #f3f7fc; }

.meta {
    display: grid;
    gap: .75rem;
    margin: 0;
}
.meta > div {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: .5rem;
    padding: .65rem .8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; font-weight: 600; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .25rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 650;
    border: 1px solid var(--border);
    background: #f4f6f9;
    color: var(--muted);
}
.badge--unknown::before {
    content: "";
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--warn);
}

.pill {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .15rem .45rem;
    border-radius: 6px;
    background: #eef2f7;
    color: var(--muted);
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    padding: .55rem .9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn:hover { background: #f3f6fa; text-decoration: none; }
.btn--primary {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; }

.muted { color: var(--muted); }

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1rem;
}
.auth-wrap { width: min(420px, 100%); }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px rgba(21, 32, 51, .06);
}
.auth-card h1 { margin: 0 0 .25rem; }
.stack { display: grid; gap: .85rem; margin-top: 1rem; }
.field { display: grid; gap: .35rem; font-size: .92rem; }
.field input,
.field select,
.field textarea {
    padding: .65rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    width: 100%;
}
.field textarea {
    min-height: 5rem;
    resize: vertical;
}
.alert {
    margin-top: 1rem;
    padding: .7rem .8rem;
    border-radius: 8px;
}
.alert--danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #f0b8b3;
}

.codeblock {
    margin: .5rem 0 0;
    padding: .85rem 1rem;
    background: #152033;
    color: #e8eef4;
    border-radius: 10px;
    overflow: auto;
    font-size: .8rem;
    line-height: 1.4;
    max-height: 420px;
}

.badge--ok {
    color: var(--ok);
    border-color: #9dceb3;
    background: #eefaf3;
}
.badge--ok::before {
    content: "";
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ok);
}
.badge--err {
    color: var(--danger);
    border-color: #f0b8b3;
    background: var(--danger-bg);
}
.badge--err::before {
    content: "";
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--danger);
}
.badge--warn {
    color: #9a6b00;
    border-color: #e6c98a;
    background: #fff8e8;
}

.content-cycle-steps {
    margin: 0;
    padding-left: 1.25rem;
    font-size: .9rem;
    line-height: 1.5;
}
.content-cycle-steps li { margin-bottom: .65rem; }
.content-cycle-steps__head {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
}
.content-cycle-steps__msg { margin-top: .15rem; }
.content-cycle-highlights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: .75rem;
}
.content-cycle-highlight {
    padding: .7rem .8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f7f9fc;
    font-size: .92rem;
}
.content-cycle-highlight__label {
    font-size: .72rem;
    font-weight: 650;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: .35rem;
}
.content-cycle-titles {
    margin: .45rem 0 0;
    padding-left: 1.1rem;
    font-size: .85rem;
}

.genre-sim-band {
    display: inline-block;
    min-width: 9rem;
    padding: .22rem .5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 650;
}
.genre-sim--very-close { background: #e7f7ed; color: #146c3b; border-color: #91cdaa; }
.genre-sim--close { background: #edf7e4; color: #3f681e; border-color: #b8d79d; }
.genre-sim--related { background: #fff7d9; color: #735c00; border-color: #e7d477; }
.genre-sim--weak { background: #fff0dc; color: #875214; border-color: #e9bf85; }
.genre-sim--distant { background: #f8e9e8; color: #8a302b; border-color: #e2aaa6; }

.sidebar-toggle {
    display: none;
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex: 0 0 auto;
    font-size: 1.15rem;
    line-height: 1;
}

.sidebar-backdrop {
    display: none;
}

.playlist-slot {
    display: grid;
    grid-template-columns: 10rem 1fr minmax(14rem, 1.6fr) auto;
    gap: .5rem .65rem;
    align-items: end;
    padding: .65rem .75rem;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: #f7fafc;
}
.playlist-slot[data-type="trailer_auto"] {
    grid-template-columns: 10rem 1fr auto;
    background: #f3f7ff;
}
.playlist-slot__cues {
    grid-column: 1 / -1;
    margin-top: .15rem;
    padding-top: .35rem;
    border-top: 1px dashed var(--border);
}
.playlist-slot__cues > .muted {
    margin: 0 0 .35rem;
    font-size: .82rem;
}
.playlist-slot__cpl-wrap {
    display: grid;
    gap: .35rem;
}
.playlist-slot__cpl-wrap .slot-cpl-filter {
    max-width: 12rem;
}
.playlist-insert {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .4rem;
    padding: .25rem 0;
}
.playlist-insert__line {
    flex: 1;
    height: 1px;
    background: var(--border);
    opacity: .7;
}
.playlist-insert__btn {
    font-size: .8rem;
    padding: .2rem .55rem;
    white-space: nowrap;
}
.cue-editor { display: grid; gap: .45rem; margin-top: .35rem; }
.cue-editor__row {
    display: grid;
    grid-template-columns: 1.4fr 7rem 1fr auto;
    gap: .45rem;
    align-items: end;
}
@media (max-width: 900px) {
    .playlist-slot,
    .playlist-slot[data-type="trailer_auto"],
    .cue-editor__row { grid-template-columns: 1fr; }

    .shell { grid-template-columns: 1fr; }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: var(--top-h) 0 0 0;
        z-index: 24;
        background: rgba(21, 32, 51, .42);
        border: 0;
        padding: 0;
        margin: 0;
        cursor: pointer;
    }
    .sidebar-backdrop[hidden] { display: none !important; }

    .sidebar {
        display: block;
        position: fixed;
        top: var(--top-h);
        left: 0;
        bottom: 0;
        width: min(300px, 88vw);
        z-index: 26;
        transform: translateX(-105%);
        transition: transform .2s ease;
        box-shadow: 8px 0 28px rgba(21, 32, 51, .18);
        background: #fff;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    .sidebar.is-open { transform: translateX(0); }
    body.nav-open { overflow: hidden; }

    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }

    .topbar {
        padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
        gap: .5rem;
    }
    .topbar__status { margin-left: 0; }
    .topbar__name { display: none; }
    .topbar__role { display: none; }
    .topbar__user .btn { padding: .45rem .65rem; font-size: .88rem; }

    .content {
        padding: 1rem .85rem calc(2rem + env(safe-area-inset-bottom, 0px));
        max-width: none;
    }
    .content:has(.page--wide) { max-width: none; }

    .page-tabs {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--bg, #f5f7fb);
        padding: .35rem 0;
        margin-bottom: .85rem;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .page-tabs .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }
    .page-head > div[style*="display:flex"],
    .page-head form {
        width: 100%;
    }

    .btn {
        min-height: 42px;
        padding: .6rem .85rem;
    }
    .field input,
    .field select,
    .field textarea {
        min-height: 42px;
        font-size: 16px; /* iOS — bez zoomu při focusu */
        max-width: 100%;
    }

    form[style*="display:flex"],
    .page-head + form,
    .toolbar {
        flex-wrap: wrap !important;
        gap: .6rem !important;
        align-items: stretch !important;
    }
    form[style*="display:flex"] .field,
    form[style*="display:flex"] .btn,
    form[style*="display:flex"] > label {
        flex: 1 1 100%;
        min-width: 0;
    }

    .status-grid {
        grid-template-columns: 1fr;
        gap: .65rem;
    }
    .status-card__value { font-size: 1.1rem; }

    .meta > div {
        grid-template-columns: 1fr;
        gap: .2rem;
    }

    .table-wrap {
        margin-left: -.25rem;
        margin-right: -.25rem;
        border-radius: 8px;
    }
    .data-table {
        font-size: .82rem;
        min-width: 640px;
    }
    .data-table th,
    .data-table td {
        padding: .55rem .6rem;
    }
    /* Sticky první sloupec — lepší orientace při scrollu doprava */
    .data-table th:first-child,
    .data-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: var(--surface);
        box-shadow: 2px 0 0 var(--border);
    }
    .data-table th:first-child {
        background: #f3f6fa;
        z-index: 2;
    }

    .side-nav__label {
        position: sticky;
        top: 0;
        z-index: 1;
        background: var(--surface, #fff);
        padding-top: .45rem;
        padding-bottom: .2rem;
    }
    .side-nav a,
    .side-nav__advanced > summary {
        padding: .7rem .85rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .show-timeline__cues { margin-left: 1rem; }

    .notice, .alert, .auth-card { max-width: 100%; }
}

@media (max-width: 480px) {
    .topbar__status .badge {
        max-width: 7.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .page h1 { font-size: 1.35rem; }
    .lead { font-size: .92rem; }
    .data-table { min-width: 560px; }
}

@media (hover: none) and (pointer: coarse) {
    a, .btn, .side-nav a, .status-card {
        -webkit-tap-highlight-color: rgba(11, 95, 255, .12);
    }
}
