/* ==========================================================================
   ManifestRelay - Token-Driven Design System
   Target: WCAG 2.2 AA | Fully Mobile Responsive (320px - 2560px)
   ========================================================================== */

:root {
    /* --- Typography Tokens --- */
    --font-family-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-family-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    --font-size-xs: 11px;
    --font-size-sm: 12px;
    --font-size-md: 13px;
    --font-size-lg: 14px; /* base */
    --font-size-xl: 15px;
    --font-size-2xl: 16px;
    --font-size-3xl: 22px;
    
    --font-weight-regular: 400;
    --font-weight-base: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --font-line-height-base: 21.7px;

    /* --- Color Palette Tokens --- */
    --color-text-primary: #888888;
    --color-text-secondary: #ffffff;
    --color-text-tertiary: #cccccc;
    --color-border-strong: #faff69; /* Neon Yellow Accent */
    --color-border-default: #2a2a2a;
    --color-surface-base: #000000;
    --color-surface-muted: #1a1a1a;
    --color-surface-strong: #0a0a0a;

    /* --- Extended Semantic Status Colors --- */
    --color-success-bg: rgba(34, 197, 94, 0.12);
    --color-success-text: #4ade80;
    --color-success-border: #22c55e;
    --color-error-bg: rgba(239, 68, 68, 0.12);
    --color-error-text: #f87171;
    --color-error-border: #ef4444;
    --color-warning-bg: rgba(234, 179, 8, 0.12);
    --color-warning-text: #facc15;
    --color-warning-border: #eab308;

    /* --- Spacing Scale Tokens --- */
    --space-1: 6px;
    --space-2: 8px;
    --space-3: 10px;
    --space-4: 12px;
    --space-5: 14px;
    --space-6: 16px;
    --space-7: 18px;
    --space-8: 20px;

    /* --- Radius Tokens --- */
    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius-full: 9999px;

    /* --- Shadow & Motion Tokens --- */
    --shadow-1: rgba(250, 255, 105, 0.15) 0px 0px 20px 0px;
    --shadow-glow-sm: 0 0 10px rgba(250, 255, 105, 0.2);
    --shadow-glow-lg: 0 0 24px rgba(250, 255, 105, 0.35);
    --motion-duration-instant: 200ms;
    --motion-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Base Reset & Accessibility --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    background-color: var(--color-surface-base);
    color: var(--color-text-primary);
    font-family: var(--font-family-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    background-color: var(--color-surface-base);
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-base);
    line-height: var(--font-line-height-base);
    overflow-x: hidden;
}

/* Mandatory WCAG Focus-Visible Rules for Interactive Controls */
button:focus-visible,
a:focus-visible,
input[type="checkbox"]:focus-visible,
.btn-close:focus-visible,
.btn-filter:focus-visible,
.tab-btn:focus-visible {
    outline: 2px solid var(--color-border-strong) !important;
    outline-offset: 2px !important;
    box-shadow: var(--shadow-glow-sm) !important;
}

/* --- Layout Container --- */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-7);
}

/* --- Header Section --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-6);
    padding: var(--space-6);
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

.logo-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-xs);
    background: var(--color-surface-muted);
    border: 1px solid var(--color-border-strong);
    color: var(--color-border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-1);
}

.logo-icon svg {
    width: 22px;
    height: 22px;
}

.brand h1 {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-secondary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    margin-top: 2px;
}

.brand-link {
    color: var(--color-border-strong);
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    transition: color var(--motion-duration-instant) var(--motion-ease);
}

.brand-link:hover {
    text-decoration: underline;
    color: #ffffff;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

/* --- Buttons System --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    min-height: 42px;
    font-family: var(--font-family-primary);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-xs);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--motion-duration-instant) var(--motion-ease);
    user-select: none;
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* Primary Button: Solid Neon Yellow with Dark Text */
.btn-primary {
    background-color: var(--color-border-strong);
    color: #000000;
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-1);
}

.btn-primary:hover {
    background-color: #ffffff;
    border-color: #ffffff;
    box-shadow: var(--shadow-glow-lg);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    opacity: 0.9;
}

/* Secondary Button: Muted Surface with Default Border */
.btn-secondary {
    background-color: var(--color-surface-muted);
    color: var(--color-text-secondary);
    border-color: var(--color-border-default);
}

.btn-secondary:hover {
    border-color: var(--color-border-strong);
    color: var(--color-border-strong);
    background-color: #222222;
    box-shadow: var(--shadow-glow-sm);
}

.btn-secondary:active {
    background-color: var(--color-surface-strong);
}

.btn-sm {
    min-height: 34px;
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
}

.btn-block {
    width: 100%;
}

.btn:disabled, .btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none !important;
}

/* --- Stats Overview Bar --- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-5);
}

.stat-card {
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    padding: var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-5);
    transition: border-color var(--motion-duration-instant) var(--motion-ease);
}

.stat-card:hover {
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-glow-sm);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-surface-muted);
    border: 1px solid var(--color-border-default);
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.running {
    color: var(--color-border-strong);
    border-color: var(--color-border-strong);
    background-color: rgba(250, 255, 105, 0.08);
}

.stat-icon.total {
    color: var(--color-text-secondary);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 26px;
    font-weight: var(--font-weight-bold);
    color: var(--color-text-secondary);
    line-height: 1.1;
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* --- Main Content & Section Title --- */
.main-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
    flex-wrap: wrap;
}

.section-title h2 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-secondary);
}

.search-box {
    position: relative;
    width: 100%;
    max-width: 360px;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-primary);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.search-icon svg {
    width: 16px;
    height: 16px;
}

.search-box input {
    width: 100%;
    padding: var(--space-3) var(--space-4) var(--space-3) 42px !important;
    min-height: 40px;
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-xs);
    color: var(--color-text-secondary);
    font-family: var(--font-family-primary);
    font-size: var(--font-size-md);
    outline: none !important;
    box-shadow: none !important;
    transition: all var(--motion-duration-instant) var(--motion-ease);
}

.search-box input:focus,
.search-box input:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    border-color: var(--color-border-strong) !important;
    background-color: var(--color-surface-muted);
}

.search-box input::placeholder {
    color: var(--color-text-primary);
}

/* --- Stream Cards Grid --- */
.streams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-6);
}

.stream-card {
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    transition: all var(--motion-duration-instant) var(--motion-ease);
    position: relative;
    overflow: hidden;
}

.stream-card:hover {
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-1);
    transform: translateY(-2px);
}

.stream-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.stream-name {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    line-height: 1.3;
    word-break: break-word;
}

.stream-id-badge {
    font-family: var(--font-family-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-primary);
    background-color: var(--color-surface-muted);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--color-border-default);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.card-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    line-height: 1.3;
    word-break: break-word;
}

/* Status Badges */
.status-badge, .badge-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.status-badge.running, .badge-status.running {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border: 1px solid var(--color-success-border);
}

.status-badge.stopped, .badge-status.stopped {
    background-color: var(--color-surface-muted);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
}

.status-badge.connecting, .badge-status.connecting {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
    border: 1px solid var(--color-warning-border);
}

.status-badge.error, .badge-status.error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    border: 1px solid var(--color-error-border);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: currentColor;
}

.status-badge.running .status-dot, .badge-status.running .status-dot {
    box-shadow: 0 0 8px currentColor;
    animation: pulseDot 1.8s infinite;
}

@keyframes pulseDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

/* Stream Details List */
.card-body, .stream-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    background-color: var(--color-surface-muted);
    border: 1px solid var(--color-border-default);
    padding: var(--space-4);
    border-radius: var(--radius-xs);
}

.info-row, .detail-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
}

.info-label, .detail-label {
    color: var(--color-text-primary);
    white-space: nowrap;
}

.info-value, .detail-value {
    color: var(--color-text-secondary);
    font-family: var(--font-family-mono);
    text-align: right;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* Stream Action Bar */
.card-actions, .stream-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: auto;
}

.card-actions .btn, .stream-actions .btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    min-height: 36px;
    font-size: var(--font-size-xs);
}

.btn-success {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border-color: var(--color-success-border);
}

.btn-success:hover {
    background-color: var(--color-success-border);
    color: #000000;
}

.btn-danger {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    border-color: var(--color-error-border);
}

.btn-danger:hover {
    background-color: var(--color-error-border);
    color: #ffffff;
}

/* --- Empty State --- */
.empty-state {
    background-color: var(--color-surface-strong);
    border: 1px dashed var(--color-border-default);
    border-radius: var(--radius-sm);
    padding: 60px var(--space-6);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--color-surface-muted);
    border: 1px solid var(--color-border-strong);
    color: var(--color-border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-1);
}

.empty-icon svg {
    width: 32px;
    height: 32px;
}

.empty-state h3 {
    font-size: var(--font-size-2xl);
    color: var(--color-text-secondary);
}

.empty-state p {
    color: var(--color-text-primary);
    max-width: 400px;
}

/* --- Modal Overlay & Dialog Card --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    overflow-y: auto;
}

.modal-card {
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-glow-lg);
    animation: modalSlideUp 0.25s var(--motion-ease);
    overflow: hidden;
}

.modal-large {
    max-width: 900px;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-6);
    border-bottom: 1px solid var(--color-border-default);
    background-color: var(--color-surface-muted);
}

.modal-header h3 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-secondary);
}

.modal-sub {
    font-size: var(--font-size-xs);
    color: var(--color-text-primary);
    margin-top: 2px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--color-text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 var(--space-2);
    line-height: 1;
    border-radius: 4px;
    transition: color var(--motion-duration-instant) var(--motion-ease);
}

.btn-close:hover {
    color: var(--color-border-strong);
}

/* Modal Tabs Navigation */
.modal-tabs {
    display: flex;
    background-color: var(--color-surface-base);
    border-bottom: 1px solid var(--color-border-default);
    padding: 0 var(--space-6);
    gap: var(--space-2);
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-primary);
    padding: var(--space-4) var(--space-4);
    font-family: var(--font-family-primary);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    transition: all var(--motion-duration-instant) var(--motion-ease);
}

.tab-btn svg {
    width: 16px;
    height: 16px;
}

.tab-btn:hover {
    color: var(--color-text-secondary);
}

.tab-btn.active {
    color: var(--color-border-strong);
    border-bottom-color: var(--color-border-strong);
}

/* Form Styles inside Modals */
#stream-form,
#change-pwd-form {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    width: 100%;
}

.tab-content,
.modal-body {
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

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

.form-group label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-tertiary);
    margin-bottom: 0;
    line-height: 1.2;
}

.form-help-text {
    font-size: var(--font-size-xs);
    color: var(--color-text-primary);
    margin-top: 4px;
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select.form-select,
.search-box input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    min-height: 42px;
    background-color: var(--color-surface-base);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-xs);
    color: var(--color-text-secondary);
    font-family: var(--font-family-primary);
    font-size: var(--font-size-lg);
    outline: none !important;
    box-shadow: none !important;
    transition: border-color var(--motion-duration-instant) var(--motion-ease);
}

input[type="text"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
textarea:hover,
select.form-select:hover,
.search-box input:hover {
    border-color: #444444;
}

input[type="text"]:focus,
input[type="text"]:focus-visible,
input[type="password"]:focus,
input[type="password"]:focus-visible,
input[type="number"]:focus,
input[type="number"]:focus-visible,
textarea:focus,
textarea:focus-visible,
select.form-select:focus,
select.form-select:focus-visible,
.search-box input:focus,
.search-box input:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    border-color: var(--color-border-strong) !important;
    background-color: var(--color-surface-muted);
}

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

.input-with-button {
    display: flex;
    gap: var(--space-3);
}

.input-with-button input {
    flex: 1;
}

.form-section-divider {
    display: flex;
    align-items: center;
    margin: var(--space-3) 0;
    color: var(--color-border-strong);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.form-section-divider::after {
    content: '';
    flex: 1;
    margin-left: var(--space-4);
    height: 1px;
    background-color: var(--color-border-default);
}

.transcode-options-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
    background-color: var(--color-surface-muted);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-xs);
    transition: opacity var(--motion-duration-instant) var(--motion-ease);
}

.transcode-options-group.disabled {
    opacity: 0.45;
}

.transcode-notice {
    font-size: var(--font-size-xs);
    color: var(--color-warning-text);
    background-color: var(--color-warning-bg);
    border: 1px solid var(--color-warning-border);
    padding: var(--space-2) var(--space-3);
    border-radius: 4px;
}

.checkbox-group {
    margin-top: var(--space-2);
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-border-strong);
    cursor: pointer;
}

.modal-footer {
    padding: var(--space-5) var(--space-6);
    border-top: 1px solid var(--color-border-default);
    background-color: var(--color-surface-muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-4);
}

/* Error Badges */
.fetch-error-badge, .auth-error-badge {
    padding: var(--space-3) var(--space-4);
    background-color: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error-text);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-xs);
    margin-top: var(--space-2);
}

/* --- Terminal Log Modal --- */
.log-controls {
    padding: var(--space-4) var(--space-6);
    background-color: var(--color-surface-base);
    border-bottom: 1px solid var(--color-border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.log-filters {
    display: flex;
    gap: var(--space-2);
}

.btn-filter {
    background-color: var(--color-surface-muted);
    border: 1px solid var(--color-border-default);
    color: var(--color-text-primary);
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--motion-duration-instant) var(--motion-ease);
}

.btn-filter:hover {
    color: var(--color-text-secondary);
    border-color: #555555;
}

.btn-filter.active {
    background-color: var(--color-border-strong);
    color: #000000;
    border-color: var(--color-border-strong);
}

.terminal-container {
    background-color: #0c0d10;
    color: #cccccc;
    font-family: 'Consolas', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: var(--space-4);
    height: 440px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid #1e293b;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
}

.log-line {
    word-break: break-all;
    font-family: inherit;
    white-space: pre-wrap;
}

/* PowerShell Color Palette */
.ps-timestamp {
    color: #38bdf8;
    font-weight: 500;
}

.ps-badge, .ps-tag {
    display: inline-block;
    font-weight: 700;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}

.ps-badge.ffmpeg, .ps-tag.ps-ffmpeg {
    background-color: rgba(56, 189, 248, 0.18);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.ps-badge.system, .ps-tag.ps-system {
    background-color: rgba(192, 132, 252, 0.18);
    color: #c084fc;
    border: 1px solid rgba(192, 132, 252, 0.3);
}

.ps-badge.error, .ps-tag.ps-error {
    background-color: rgba(248, 113, 113, 0.2);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.35);
}

.ps-badge.warning, .ps-tag.ps-warn {
    background-color: rgba(250, 204, 21, 0.18);
    color: #facc15;
    border: 1px solid rgba(250, 204, 21, 0.3);
}

.ps-tag.ps-info {
    background-color: rgba(52, 211, 153, 0.18);
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.ps-url {
    color: #facc15;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ps-hex {
    color: #f472b6;
    font-weight: 600;
}

.ps-status-running {
    color: #4ade80;
    font-weight: 700;
}

.ps-status-error {
    color: #f87171;
    font-weight: 700;
}

.ps-status-success {
    color: #34d399;
    font-weight: 700;
}

.ps-action {
    color: #60a5fa;
    font-weight: 600;
}

.ps-metric {
    color: #fb923c;
    font-weight: 600;
}

/* --- Security Authentication Overlay --- */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.auth-card {
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 420px;
    padding: var(--space-8);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-5);
    box-shadow: var(--shadow-glow-lg);
    animation: modalSlideUp 0.3s var(--motion-ease);
}

.auth-icon-wrapper {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(250, 255, 105, 0.1);
    border: 1px solid var(--color-border-strong);
    color: var(--color-border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-1);
}

.auth-icon-wrapper svg {
    width: 28px;
    height: 28px;
}

.auth-card h2 {
    font-size: 24px;
    font-weight: var(--font-weight-bold);
    color: var(--color-text-secondary);
}

.auth-desc {
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    margin-top: -6px;
}

#auth-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.password-input-wrapper {
    position: relative;
    width: 100%;
}

.password-input-wrapper input {
    padding-right: 44px;
}

.btn-toggle-pwd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color var(--motion-duration-instant) var(--motion-ease);
}

.btn-toggle-pwd:hover {
    color: var(--color-border-strong);
}

.btn-toggle-pwd svg {
    width: 18px;
    height: 18px;
}

.auth-footer {
    color: var(--color-text-primary);
    font-size: var(--font-size-xs);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    background-color: var(--color-surface-strong);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-xs);
    padding: var(--space-4) var(--space-6);
    color: var(--color-text-secondary);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    animation: toastIn 0.3s var(--motion-ease);
    pointer-events: auto;
    max-width: 380px;
}

.toast svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast-success {
    border-color: var(--color-border-strong);
    color: var(--color-border-strong);
}

.toast-warning {
    border-color: var(--color-warning-border);
    color: var(--color-warning-text);
}

.toast-error {
    border-color: var(--color-error-border);
    color: var(--color-error-text);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* --- Mobile Responsiveness (320px - 768px) --- */
@media (max-width: 768px) {
    .app-container {
        padding: var(--space-4);
        gap: var(--space-5);
    }

    .app-header {
        flex-direction: column;
        align-items: stretch;
        padding: var(--space-5);
        gap: var(--space-4);
    }

    .brand {
        flex-direction: row;
    }

    .brand h1 {
        font-size: var(--font-size-2xl);
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }

    .header-actions .btn-primary {
        grid-column: 1 / -1;
    }

    .stats-bar {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }

    .stat-card {
        padding: var(--space-4);
        gap: var(--space-3);
    }

    .stat-icon {
        width: 38px;
        height: 38px;
    }

    .stat-value {
        font-size: 20px;
    }

    .section-title {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: 100%;
    }

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

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal-overlay {
        padding: var(--space-3);
        z-index: 2500;
    }

    .modal-card {
        max-height: 92vh;
        border-radius: var(--radius-sm);
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: var(--space-3);
        padding: var(--space-4);
    }

    .modal-footer .btn {
        width: 100%;
    }

    .toast-container {
        left: var(--space-4);
        right: var(--space-4);
        bottom: 82px !important;
    }

    .toast {
        max-width: 100%;
    }
}

/* --- Mobile Bottom Action Bar (Native App-Like UI) --- */
.mobile-bottom-bar {
    display: none;
}

@media (max-width: 768px) {
    .header-actions {
        display: none !important;
    }

    .app-container {
        padding-bottom: 90px;
    }

    .mobile-bottom-bar {
        display: flex;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 72px;
        background-color: rgba(10, 10, 10, 0.94);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--color-border-default);
        z-index: 1500;
        padding: 6px 12px;
        box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.6);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        background: none;
        border: none;
        color: var(--color-text-primary);
        font-family: var(--font-family-primary);
        font-size: var(--font-size-xs);
        font-weight: var(--font-weight-semibold);
        padding: 6px 4px;
        border-radius: var(--radius-xs);
        cursor: pointer;
        transition: all var(--motion-duration-instant) var(--motion-ease);
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-btn svg {
        width: 22px;
        height: 22px;
        transition: transform var(--motion-duration-instant) var(--motion-ease);
    }

    .mobile-nav-btn:hover, .mobile-nav-btn:active {
        color: var(--color-border-strong);
    }

    .mobile-nav-btn:active svg {
        transform: scale(0.92);
    }

    .mobile-nav-btn.primary {
        color: var(--color-border-strong);
    }

    .mobile-nav-btn.primary svg {
        background-color: var(--color-border-strong);
        color: #000000;
        padding: 4px;
        border-radius: 50%;
        width: 28px;
        height: 28px;
        box-shadow: var(--shadow-1);
    }
}
