/* Right-side vertical audio meter */
.audio-meter {
    position: absolute;
    right: 0.7rem;
    /* moved lower by 7% from previous position */
    top: calc(3.2rem + 4%);
    width: 40px;
    height: calc((100% - 3.6rem) - 16%);
    z-index: 12;
    display: flex;
    align-items: stretch;
    pointer-events: none; /* non-interactive */
    background: rgba(0,0,0,0.5); /* black half-transparent background */
    border-radius: 0; /* boxy look */
    padding: 4px;
}
.audio-meter-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

:root {
    --primary-color: #3a7bd5;
    --secondary-color: #2a2335;
    --background-dark: #1a1a1a;
    --background-light: #2d2d2d;
    --text-light: #f0f0f0;
    --text-muted: #b0b0b0;
    --border-color: #3a3a3a;
    --success-color: #4CAF50;
    --warning-color: #FFC107;
    --error-color: #f44336;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-dark);
    color: var(--text-light);
    line-height: 1.6;
    min-height: 100vh;
}

header {
    background-color: var(--secondary-color);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: bold;
}

.logo-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
    display: inline-block;
}

.nav-buttons button {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 0.5rem;
    transition: all 0.2s ease;
}

/* Logout button variant: subtle outline but colored for emphasis */
.nav-buttons #logout-button {
    background-color: transparent;
    border-color: rgba(244,67,54,0.18);
    color: rgba(244,67,54,0.95);
}
.nav-buttons #logout-button:hover {
    background-color: rgba(244,67,54,0.06);
    transform: translateY(-1px);
    border-color: rgba(244,67,54,0.35);
}

.nav-buttons button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.nav-buttons button.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

main {
    padding: 1rem;
    max-width: 100%;
    margin: 0 auto;
}

.player-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-start; /* prevent inactive pane from stretching to match the taller pane */
}

@media (max-width: 1200px) {
    .player-container {
        flex-direction: column;
    }
}

.vod-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-start; /* keep VOD panes from stretching when the other is taller */
}

@media (max-width: 1200px) {
    .vod-container {
        flex-direction: column;
    }
}

.vod-grid-container {
    background: var(--background-light);
    border-radius: 8px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    flex: 1;
}

.server-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.server-title {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
    text-align: center;
}

.server-tabs {
    display: flex;
    margin-bottom: 0.5rem;
    background: var(--background-light);
    padding: 0.25rem;
    border-radius: 8px;
}

.server-tab {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.server-tab:hover {
    margin-top: 1rem; /* space from settings content */
    background-color: rgba(255, 255, 255, 0.1);
}

.server-tab.active {
    background-color: var(--primary-color);
}

.video-container {
    position: relative;
    width: 100%;
    background-color: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    flex-shrink: 0;
    margin-top: 0.5rem;
}

video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ttml-rendering-div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.media-status {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.5rem;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 0.5rem;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
}

.status-icon {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.status-active {
    background-color: var(--success-color);
    box-shadow: 0 0 5px var(--success-color);
}

.status-inactive {
    background-color: var(--error-color);
    box-shadow: 0 0 5px var(--error-color);
}

.audio-track-selector select {
    background-color: var(--background-light);
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem !important;
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.2s ease;
    width: auto !important;
    height: auto;
}

.audio-track-selector select:hover:not(:disabled) {
    border-color: var(--primary-color);
}

.audio-track-selector select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.channel-navigation {
    background: var(--background-light);
    border-radius: 8px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    flex: 1;
}

.vod-navigation {
    background: var(--background-light);
    border-radius: 8px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    flex: 1;
}

/* VOD cURL display and fetch UI */
.vod-curl-container {
    margin-top: 0.5rem;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.08);
    padding: 0.5rem;
    border-radius: 4px;
}
.vod-curl-text {
    font-family: "Courier New", Courier, monospace;
    font-size: 0.9rem;
    color: var(--text-light);
    background: rgba(0,0,0,0.6);
    padding: 0.5rem;
    border: 1px solid rgba(255,255,255,0.06);
    /* Fit to content: allow the pre to grow to the content size without scrolling */
    height: auto;
    max-height: none;
    overflow: visible;
    white-space: pre-wrap;
    word-break: break-all;
}
.vod-curl-response {
    font-family: "Courier New", Courier, monospace;
    font-size: 0.85rem;
    color: var(--text-light);
    background: rgba(0,0,0,0.8);
    padding: 0.6rem;
    border: 1px solid rgba(255,255,255,0.08);
    /* Fit to content: expand vertically to show headers without scrollbars */
    height: auto;
    max-height: none;
    overflow: visible;
    white-space: pre-wrap;
    word-break: break-word;
}
.vod-curl-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.vod-curl-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.group-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.group-tab {
    padding: 0.4rem 0.8rem;
    background-color: var(--background-dark);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.8rem;
}

.group-tab:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.group-tab.active {
    background-color: var(--primary-color);
}

.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr));
    gap: 0.25rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.25rem;
    scroll-behavior: smooth;
}

.channel-grid-container {
    background: var(--background-light);
    border-radius: 8px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    flex: 1;
}

.channels-grid::-webkit-scrollbar {
    width: 6px;
}

.channels-grid::-webkit-scrollbar-track {
    background: var(--background-dark);
    border-radius: 3px;
}

.channels-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.channel-item {
    text-align: center;
    padding: 0.5rem 0.25rem;
    background-color: var(--background-dark);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.channel-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.channel-item.active {
    background-color: var(--primary-color);
    font-weight: bold;
}

.settings-container {
    display: none;
    max-width: 800px;
    margin: 0 auto;
}

/* Login page styles */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 8px;
    padding: 1.25rem 1.25rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.login-brand { display:flex; align-items:center; gap:0.5rem; margin-bottom:0.75rem; flex-direction: column; justify-content: center; }
.login-title { font-size:1.25rem; font-weight:700; color:var(--primary-color); text-align:center }
.header-messages { width:100%; margin-top:0.25rem; }
.marquee-container { position: relative; width: 100%; overflow: hidden; display:flex; align-items:center; justify-content:center }
.marquee-text {
    display: inline-block;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding-left: 4px;
    padding-right: 4px;
    will-change: transform;
    text-align: center;
}
.marquee-text.scrolling { animation: marquee var(--marquee-duration, 10s) linear infinite; }

/* Fade edges to give the marquee a soft mask */
.marquee-container::before, .marquee-container::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; width: 28px;
    pointer-events: none;
}
.marquee-container::before { left: 0; background: linear-gradient(90deg, var(--background-dark) 0%, rgba(26,26,26,0) 100%); }
.marquee-container::after { right: 0; background: linear-gradient(270deg, var(--background-dark) 0%, rgba(26,26,26,0) 100%); }

@keyframes marquee {
    from { transform: translateX(var(--marquee-start, 100%)); }
    to { transform: translateX(var(--marquee-end, -100%)); }
}

/* Header fade animations for both login and main header */
@keyframes header-fade-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-6px); }
}
@keyframes header-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-out { animation: header-fade-out 0.45s ease forwards; }
.fade-in { animation: header-fade-in 0.45s ease forwards; }

#header-message { display:inline-block; min-width: 200px; }
.login-message { min-height: 1.5rem; margin-bottom:0.5rem; text-align:center }
.alert { padding:0.5rem; border-radius:4px; font-size:0.9rem; display:inline-block; text-align:left; min-width:200px }
.alert-animate { animation: alert-pulse 0.6s cubic-bezier(.2,.8,.2,1); }
@keyframes alert-pulse {
    0% { transform: translateY(-10px); opacity: 0; }
    60% { transform: translateY(6px); opacity: 1; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes alert-fadeout {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-6px); }
}
.alert-fadeout {
    animation: alert-fadeout 0.35s ease forwards;
}

/* Custom checkbox styling */
.alert-error { background: rgba(244,67,54,0.08); color: var(--error-color); border:1px solid rgba(244,67,54,0.12) }
.help-text { font-size:0.85rem; color:var(--text-muted); text-align:center }
.form-group { margin-bottom:0.65rem; display:flex; flex-direction:column }
.form-group label { margin-bottom:0.25rem; font-size:0.85rem; color:var(--text-muted) }
.form-group input { padding:0.6rem 0.75rem; border-radius:6px; border:1px solid var(--border-color); background:var(--background-dark); color:var(--text-light) }
.password-wrapper { display:flex; align-items:center }
.password-wrapper input { flex:1 }
.toggle-password { margin-left:0.5rem; background:transparent; border:1px solid var(--border-color); padding:0.45rem 0.6rem; border-radius:6px; color:var(--text-light); cursor:pointer }
.form-row { display:flex; align-items:center; justify-content:flex-start; gap:1rem; margin-bottom:0.5rem }
.remember-text { display:none }
.help-link { font-size:0.85rem; color:var(--primary-color); text-decoration:none; text-align:center }
.form-actions { display:flex; justify-content:flex-end }
/* Center the sign-in button inside the login card specifically */
.login-card .form-actions { justify-content: center; }
.login-btn { background:var(--primary-color); color:white; border:none; padding:0.6rem 1rem; border-radius:6px; cursor:pointer; font-weight:600 }
.login-btn[disabled] { opacity:0.6; cursor:not-allowed }
.login-footnote { margin-top:1.5rem; font-size:0.8rem; color:var(--text-muted); text-align:center }
.login-footnote-sub { margin-top:0.35rem; font-size:0.75rem; color:var(--text-muted); text-align:center; opacity:0.9 }


.settings-container.active {
    display: block;
}

.settings-section {
    background-color: var(--background-light);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

/* Slim footer */
.site-footer {
    /* thin blue top border using primary color */
    border-top: 2px solid var(--primary-color);
    /* not sticky: render as normal footer at end of document */
    position: static;
    padding: 0.45rem 1rem;
    text-align: center;
    font-size: 0.80rem;
    font-weight: 700; /* bold */
    color: var(--text-muted);
    background: rgba(26,26,26,0.90); /* 90% opacity */
    font-style: italic; /* make footer text italic */
    letter-spacing: 0.3px;
    text-transform: uppercase; /* enforce ALL CAPS */
}

@media (max-width: 600px) {
    .site-footer { font-size: 0.82rem; padding: 0.5rem 0.6rem; }
}

/* No sticky footer, no extra page padding required */

.settings-title {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

/* Horizontal segmented buttons: slightly separated, smaller buttons for compact layout */
.backup-buttons {
    display: flex;
    flex-direction: row;
    gap: 0.6rem; /* increased spacing between buttons */
    border-radius: 8px;
    overflow: visible;
    align-items: center;
}
.backup-buttons button {
    flex: 0 1 auto; /* do not force full-width; allow natural width */
    min-width: 100px; /* make buttons smaller */
    max-width: 160px;
    text-align: center;
    padding: 0.65rem 0.95rem;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    transition: background 0.12s ease, transform 0.12s ease;
    border-radius: 6px;
}
.backup-buttons button + button {
    /* no separator line—gap provides spacing */
    border-left: none;
}
.backup-buttons button:hover {
    background: color-mix(in srgb, var(--primary-color) 88%, black 12%);
    transform: translateY(-1px);
}

@media (max-width: 700px) {
    .backup-buttons {
        flex-direction: column;
        gap: 0.5rem;
        border-radius: 6px;
        overflow: visible;
        align-items: stretch;
    }
    .backup-buttons button {
        width: 100%;
        max-width: none;
        min-width: 0;
    }
    .backup-buttons button + button {
        border-top: none;
    }
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input, select {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--background-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-light);
    transition: border-color 0.2s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.url-structure {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.url-part {
    flex: 1;
}

.channel-override {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.channel-input {
    width: 100px;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

button:hover {
    filter: brightness(1.2);
    transform: translateY(-1px);
}

.buttons-row {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
}

#cancel-settings {
    background-color: transparent;
    border: 1px solid var(--border-color);
}

.save-indicator {
    margin-top: 1rem;
    position: fixed;
    top: 2%;
    left: 85%;
    padding: 1rem;
    border-radius: 4px;
    background-color: var(--success-color);
    display: none;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
