/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
}

header h1 {
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
    align-items: start;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 20px;
}

.panel-link {
    font-size: 0.9rem;
    color: #4f46e5;
    text-decoration: none;
    font-weight: 600;
}

.panel-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.landing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.landing-card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    text-decoration: none;
    color: #111827;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.landing-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
}

.landing-card h2 {
    margin-bottom: 10px;
    color: #4f46e5;
}

@media (max-width: 968px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Control Panel */
.control-panel {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.control-panel h2 {
    margin-bottom: 20px;
    color: #667eea;
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.3s;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.3s;
}

.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.3s;
    resize: vertical;
    min-height: 90px;
}

.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #888;
    font-size: 0.85rem;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 87, 108, 0.4);
}

.btn-secondary {
    background: #e5e7eb;
    color: #333;
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(148, 163, 184, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    font-size: 0.9rem;
}

/* Status Bar */
.status-bar {
    background: #f5f5f5;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.status-item:last-child {
    margin-bottom: 0;
}

.status-label {
    font-weight: 600;
    color: #666;
    font-size: 0.9rem;
}

.status-value {
    color: #333;
    font-size: 0.9rem;
}

.monitor-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.meter {
    flex: 1;
    height: 12px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0%;
    background: #10b981;
    transition: width 0.1s linear;
}

.capture-id-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.capture-id-row input {
    flex: 1;
}

.divider {
    height: 1px;
    background: #ececec;
    margin: 25px 0;
}

.viewer-card {
    background: #f8f9ff;
    border: 1px solid #e1e5ff;
    border-radius: 12px;
    padding: 20px;
}

.viewer-card h3 {
    margin-bottom: 10px;
    color: #4f46e5;
    font-size: 1.2rem;
}

.viewer-card p {
    margin-bottom: 15px;
    color: #666;
    font-size: 0.95rem;
}

.session-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.session-card {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    padding: 14px;
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.06);
}

.session-title {
    font-weight: 700;
    margin-bottom: 6px;
    color: #111827;
}

.session-meta {
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 8px;
}

.session-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.badge {
    background: #eef2ff;
    color: #4338ca;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 999px;
    font-weight: 600;
}

.badge-alt {
    background: #ecfdf3;
    color: #047857;
}

.badge-muted {
    background: #f3f4f6;
    color: #4b5563;
}

.session-actions {
    display: flex;
    gap: 8px;
}

.session-empty {
    text-align: center;
    color: #6b7280;
    font-style: italic;
    padding: 20px;
}

.is-hidden {
    display: none;
}

/* Caption Panel */
.caption-panel {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    min-height: 500px;
}

.caption-panel h2 {
    margin-bottom: 20px;
    color: #667eea;
    font-size: 1.5rem;
}

/* Current Caption */
.caption-current {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    padding: 30px;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
}

.caption-current p {
    font-size: 1.8rem;
    line-height: 1.5;
    text-align: center;
    margin: 0;
}

.caption-placeholder {
    opacity: 0.7;
    font-style: italic;
    font-size: 1.3rem !important;
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

/* Caption History */
.caption-history-container h3 {
    margin-bottom: 15px;
    color: #555;
    font-size: 1.2rem;
}

.caption-history {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.caption-history::-webkit-scrollbar {
    width: 8px;
}

.caption-history::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.caption-history::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.caption-history::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.caption-item {
    background: #f9f9f9;
    border-left: 4px solid #667eea;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    transition: all 0.3s;
    animation: slideIn 0.3s ease-out;
}

.caption-item:hover {
    background: #f0f0f0;
    transform: translateX(5px);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.caption-item-text {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 5px;
}

.caption-item-meta {
    font-size: 0.85rem;
    color: #888;
}

/* Empty State */
.caption-history-empty {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 40px 20px;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

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

/* Auth Page */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    width: min(520px, 100%);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 22px;
    padding: 36px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
}

.auth-header {
    margin-bottom: 24px;
}

.auth-eyebrow {
    font-size: 0.8rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: rgba(79, 70, 229, 0.8);
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-header h1 {
    font-size: 2.2rem;
    color: #111827;
    margin-bottom: 10px;
}

.auth-subtitle {
    color: #4b5563;
    font-size: 1rem;
}

.auth-domain {
    display: inline-block;
    font-weight: 700;
    color: #4338ca;
}

.auth-form label {
    display: block;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.auth-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 2px solid #e5e7eb;
    font-size: 1rem;
    margin-bottom: 16px;
    transition: border-color 0.2s ease;
}

.auth-input:focus {
    outline: none;
    border-color: #667eea;
}

.auth-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.auth-note {
    font-size: 0.9rem;
    color: #6b7280;
}

.auth-error {
    background: #fee2e2;
    color: #991b1b;
    border-radius: 10px;
    padding: 12px 14px;
    font-weight: 600;
    margin-bottom: 16px;
}

.auth-warning {
    background: #fffbeb;
    color: #92400e;
    border-radius: 10px;
    padding: 14px;
    font-weight: 600;
}

/* Listener Experience */
body.listen-page {
    --listener-bg: #ffffff;
    --listener-text: #000000;
    --listener-border: #d1d5db;
    --listener-muted: #4b5563;
    --listener-panel: #ffffff;
    --listener-caption-scale: 1;
    background: var(--listener-bg);
    color: var(--listener-text);
    min-height: 100vh;
    padding: 0;
    touch-action: manipulation;
}

body.listen-page.theme-light {
    --listener-bg: #ffffff;
    --listener-text: #000000;
    --listener-border: #d1d5db;
    --listener-muted: #4b5563;
    --listener-panel: #ffffff;
}

body.listen-page.theme-dark {
    --listener-bg: #000000;
    --listener-text: #ffffff;
    --listener-border: #4b5563;
    --listener-muted: #d1d5db;
    --listener-panel: #000000;
}

body.listen-page .is-hidden {
    display: none !important;
}

.listen-root {
    min-height: 100vh;
    background: var(--listener-bg);
    color: var(--listener-text);
    padding: 24px;
    padding-bottom: 110px;
}

.join-screen {
    min-height: calc(100vh - 150px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.join-card {
    width: min(760px, 100%);
    border: 1px solid var(--listener-border);
    background: var(--listener-panel);
    border-radius: 14px;
    padding: 24px;
}

.join-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.8rem;
    margin-bottom: 10px;
    color: var(--listener-muted);
    font-weight: 700;
}

.join-card h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    color: var(--listener-text);
}

.join-subtitle {
    color: var(--listener-muted);
    margin-bottom: 20px;
}

.join-card .panel-actions {
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.join-grid {
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
}

body.listen-page .form-group label {
    color: var(--listener-text);
}

body.listen-page .form-group input,
body.listen-page .form-group select {
    background: var(--listener-panel);
    color: var(--listener-text);
    border: 1px solid var(--listener-border);
}

body.listen-page .form-group small {
    color: var(--listener-muted);
}

body.listen-page .btn {
    flex: 0 0 auto;
    border: 1px solid var(--listener-border);
    border-radius: 10px;
    padding: 10px 16px;
    background: var(--listener-panel);
    color: var(--listener-text);
    box-shadow: none;
    transform: none;
    text-decoration: none;
}

body.listen-page .btn:hover:not(:disabled) {
    box-shadow: none;
    transform: none;
    opacity: 0.85;
}

body.listen-page .btn-primary {
    background: var(--listener-text);
    color: var(--listener-bg);
}

body.listen-page .btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

body.listen-page .btn-secondary {
    background: var(--listener-panel);
    color: var(--listener-text);
}

.join-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.join-message {
    min-height: 20px;
    color: var(--listener-muted);
    font-size: 0.9rem;
}

.join-message-error {
    color: #b91c1c;
}

/* Dashboard */
body.dashboard-page {
    min-height: 100vh;
}

.dashboard-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dashboard-topbar {
    background: white;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.dashboard-refresh-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-updated {
    font-size: 0.9rem;
    color: #4b5563;
}

.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.dashboard-stat-card {
    background: white;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    padding: 18px;
}

.dashboard-stat-card h2 {
    font-size: 0.95rem;
    color: #4b5563;
    margin-bottom: 8px;
}

.dashboard-stat-value {
    font-size: 2rem;
    line-height: 1.1;
    color: #111827;
    font-weight: 700;
}

.dashboard-panel {
    background: white;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    padding: 20px;
}

.dashboard-count-label {
    font-size: 0.95rem;
    color: #4b5563;
}

.dashboard-session-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dashboard-session-card {
    border: 1px solid #e5e7eb;
    box-shadow: none;
}

.dashboard-language-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.viewer-screen {
    width: min(900px, 100%);
    margin: 0 auto;
}

.caption-stream {
    border-top: 1px solid var(--listener-border);
}

.caption-empty {
    color: var(--listener-muted);
    padding: 18px 0;
    font-size: calc(1rem * var(--listener-caption-scale));
}

.caption-line {
    border-bottom: 1px solid var(--listener-border);
    padding: 12px 0;
}

.caption-line-text {
    margin: 0;
    font-size: calc(1.2rem * var(--listener-caption-scale));
    line-height: 1.45;
    color: var(--listener-text);
}

.caption-line-meta {
    display: block;
    margin-top: 6px;
    color: var(--listener-muted);
    font-size: 0.75rem;
}

.listener-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid var(--listener-border);
    background: var(--listener-panel);
    color: var(--listener-text);
}

.banner-header {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.banner-session {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.banner-label {
    font-size: 0.75rem;
    color: var(--listener-muted);
}

#banner-session-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.banner-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.banner-controls-hidden {
    display: none;
}

.banner-controls label {
    font-size: 0.85rem;
    color: var(--listener-muted);
}

.banner-controls select {
    background: var(--listener-panel);
    color: var(--listener-text);
    border: 1px solid var(--listener-border);
    border-radius: 8px;
    padding: 8px 10px;
}

.text-size-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.font-size-btn {
    min-width: 48px;
    padding: 8px 10px;
}

.font-size-value {
    min-width: 62px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--listener-text);
}

.drawer-toggle {
    white-space: nowrap;
}

@media (max-width: 800px) {
    .listen-root {
        padding: 16px;
        padding-bottom: 150px;
    }

    .join-card {
        padding: 18px;
    }

    .join-card h1 {
        font-size: 1.6rem;
    }

    .join-actions {
        flex-direction: column;
    }

    .dashboard-topbar,
    .dashboard-refresh-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-refresh-controls .btn {
        width: 100%;
    }

    .listener-banner {
        gap: 10px;
        padding: 10px 14px;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
    }

    .listener-banner.drawer-collapsed {
        gap: 0;
    }

    .banner-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .banner-controls select,
    .banner-controls button {
        width: 100%;
    }

    .banner-controls label {
        margin-top: 6px;
    }

    .text-size-controls {
        width: 100%;
    }

    .text-size-controls button {
        width: auto;
        flex: 0 0 70px;
    }

    .font-size-value {
        flex: 1;
        text-align: center;
    }

    #banner-session-name {
        max-width: 100%;
    }
}

@media (min-width: 801px) {
    .drawer-toggle {
        display: none !important;
    }

    .listener-banner {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .banner-header {
        width: auto;
        flex: 0 0 auto;
    }

    .banner-controls {
        width: auto;
    }
}
