/* === Dashboard Layout === */
.dashboard {
    position: relative;
    padding: var(--space-10) 0 var(--space-16);
    min-height: calc(100vh - 80px);
    isolation: isolate;
}

.dashboard::before {
    content: '';
    position: absolute;
    top: -180px;
    left: -120px;
    width: 480px;
    height: 480px;
    background: radial-gradient(circle at 30% 30%, rgba(0, 210, 255, 0.18), transparent 65%);
    opacity: 0.9;
    z-index: -1;
}

.dashboard::after {
    content: '';
    position: absolute;
    bottom: -200px;
    right: -160px;
    width: 520px;
    height: 520px;
    background: radial-gradient(circle at 70% 70%, rgba(58, 123, 213, 0.18), transparent 65%);
    opacity: 0.9;
    z-index: -1;
}

.dashboard .container {
    position: relative;
    z-index: 1;
}

/* === Header === */
.dashboard-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-6);
    margin-bottom: var(--space-8);
    padding: var(--space-6);
    border-radius: var(--radius-2xl);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.dashboard-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top left, rgba(0, 210, 255, 0.15), transparent 55%);
    opacity: 0.7;
    pointer-events: none;
}

.dashboard-header>* {
    position: relative;
    z-index: 1;
}

.dashboard-title {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    flex-wrap: wrap;
}

.title-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.dashboard-kicker {
    font-size: var(--font-size-xs);
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.dashboard-title h1 {
    font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.call-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    background: rgba(0, 210, 255, 0.12);
    border: 1px solid rgba(0, 210, 255, 0.35);
    box-shadow: 0 0 24px rgba(0, 210, 255, 0.15);
    font-size: var(--font-size-xs);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.call-badge-label {
    font-size: 0.6rem;
    letter-spacing: 0.25em;
    color: var(--text-muted);
    font-family: var(--font-sans);
}

.call-badge-value {
    color: var(--text-primary);
}

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

.dashboard-actions .btn {
    padding: var(--space-2) var(--space-5);
    font-size: var(--font-size-sm);
}

.btn-compact {
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    border-radius: var(--radius-full);
}

/* === Unbound State === */
.unbound-warning {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: var(--radius-xl);
    padding: var(--space-4);
    margin-bottom: var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.15);
}

.unbound-warning-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    color: var(--color-warning);
}

.unbound-warning-text h3 {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-1);
}

.unbound-warning-text p {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* === Main Grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 320px;
    grid-template-rows: auto auto auto;
    grid-template-areas:
        "status transcript tools"
        "booking transcript tools"
        "tech tech tech";
    gap: var(--space-5);
    min-height: 600px;
    align-items: stretch;
}

.status-panel {
    grid-area: status;
}

.transcript-panel {
    grid-area: transcript;
    /* Span both rows and match tools panel height */
    display: flex;
    flex-direction: column;
}

.booking-panel {
    grid-area: booking;
}

.tools-panel {
    grid-area: tools;
    /* Span both rows and match transcript panel height */
    display: flex;
    flex-direction: column;
}

.tech-panel {
    grid-area: tech;
}

/* === Panel Styles === */
.panel {
    position: relative;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-2xl);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(16px);
    min-height: 0;
}

.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
    opacity: 0.6;
}

.panel:hover {
    border-color: var(--glass-border-hover);
    box-shadow: var(--shadow-lg);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
    gap: var(--space-3);
}

.panel-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.28em;
    color: var(--text-muted);
}

.panel-content {
    flex: 1;
    padding: var(--space-5);
    overflow-y: auto;
    overflow-x: hidden;
}

/* === Status Panel === */
.status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.status-item+.status-item {
    margin-top: var(--space-2);
}

.status-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.22em;
}

.status-value {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
}

.status-value.online {
    color: var(--color-success);
}

.status-mono {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
}

/* === Transcript Panel === */
.transcript-panel .panel-content {
    padding: 0;
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex shrinking */
}

.transcript-panel .chat-container {
    flex: 1;
    min-height: 300px;
    max-height: none;
    padding: var(--space-5);
    background: radial-gradient(circle at top, rgba(0, 210, 255, 0.08), transparent 45%);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Ensure tools panel content also stretches */
.tools-panel .panel-content {
    flex: 1;
    min-height: 0; /* Allow flex shrinking */
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    overflow: hidden;
}

.transcript-panel .chat-bubble {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.transcript-panel .chat-bubble--assistant {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
}

.transcript-panel .chat-bubble--user {
    box-shadow: 0 8px 24px rgba(0, 210, 255, 0.2);
}

/* === Booking Table === */
.booking-table {
    width: 100%;
    font-size: var(--font-size-sm);
    border-collapse: collapse;
}

.booking-table th {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    background: rgba(255, 255, 255, 0.03);
    font-weight: var(--font-weight-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.22em;
}

.booking-table td {
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.booking-table tbody tr:first-child td {
    border-top: none;
}

.booking-key {
    font-family: var(--font-mono);
    color: var(--accent-primary);
}

.booking-value {
    color: var(--text-primary);
}

.booking-code {
    font-size: var(--font-size-xs);
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    display: inline-block;
}

.booking-empty {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-6);
}

.booking-items-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.booking-item {
    padding: var(--space-1) var(--space-2);
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: 0.65rem;
    font-weight: var(--font-weight-semibold);
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--color-success);
}

.badge-muted {
    background: rgba(128, 128, 128, 0.2);
    color: var(--text-muted);
}

.new-row {
    animation: highlightRow 0.4s ease;
}

/* === Available Tools === */
.available-tools {
    padding: var(--space-4);
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-lg);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    margin-bottom: var(--space-4);
}

.available-tools-header {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.28em;
    margin-bottom: var(--space-2);
}

.available-tools-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.available-tools-list li {
    font-size: 0.65rem;
    padding: var(--space-1) var(--space-2);
    background: rgba(0, 210, 255, 0.12);
    border: 1px solid rgba(0, 210, 255, 0.25);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* === Tool Timeline === */
.tool-timeline {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding-left: var(--space-4);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.tool-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 8px;
    width: 2px;
    background: linear-gradient(180deg, rgba(0, 210, 255, 0.4), rgba(58, 123, 213, 0.1));
    opacity: 0.6;
}

.tool-item {
    position: relative;
    padding-left: var(--space-4);
}

.tool-item::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 16px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 0 8px rgba(0, 210, 255, 0.3);
}

/* === Metrics Bar === */
.metrics-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
    padding: var(--space-5);
    background: linear-gradient(135deg, rgba(0, 210, 255, 0.12), rgba(58, 123, 213, 0.12));
    border: 1px solid rgba(0, 210, 255, 0.3);
    border-radius: var(--radius-2xl);
    margin-top: var(--space-6);
    box-shadow: var(--shadow-md);
}

.metric-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.2em;
    color: var(--text-secondary);
}

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

.metric-value {
    font-weight: var(--font-weight-bold);
    font-family: var(--font-mono);
    font-size: var(--font-size-lg);
}

.metric-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
    text-align: center;
    gap: var(--space-3);
}

.empty-state-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.2em;
    color: var(--text-muted);
}

/* === Empty Dashboard === */
.dashboard-empty {
    text-align: center;
}

.dashboard-empty-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.dashboard-empty-content p {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.dashboard-empty-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
    margin-top: var(--space-2);
}

/* === Tech Panel === */
.tech-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.tech-errors-wrap {
    margin-top: var(--space-4);
}

.tech-errors {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-error);
    margin-top: var(--space-2);
    max-height: 100px;
    overflow-y: auto;
}

.tech-errors-empty {
    color: var(--text-muted);
}

/* D4: Tech Log Entry Styles */
.tech-log-entry {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    padding: var(--space-1) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tech-log-entry:last-child {
    border-bottom: none;
}

.tech-log-time {
    color: var(--text-muted);
    margin-right: var(--space-1);
}

.tech-log-icon {
    margin-right: var(--space-1);
}

.tech-log-error {
    color: var(--color-error);
}

.tech-log-success {
    color: var(--color-success);
}

.tech-log-warning {
    color: var(--color-warning);
}

.tech-log-info {
    color: var(--text-secondary);
}

/* === Scene Code Popup === */
.code-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.code-popup-overlay.visible {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.code-popup {
    background: var(--color-bg-primary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-2xl);
    padding: var(--space-8);
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.code-popup-close-x {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 16px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.code-popup-close-x:hover {
    background: var(--glass-bg-hover);
    color: var(--text-primary);
}

.code-popup-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.code-popup-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-6);
}

.code-popup-code {
    font-family: var(--font-mono);
    font-size: var(--font-size-4xl);
    font-weight: var(--font-weight-bold);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.4em;
    margin-bottom: var(--space-4);
}

.code-popup-info {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-6);
    line-height: var(--line-height-relaxed);
}

.code-popup-timer {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}

.code-popup-close {
    padding: var(--space-3) var(--space-6);
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.code-popup-close:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* === Animations === */
@keyframes dashRise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes dashFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .dashboard-header {
        animation: dashFade 0.6s ease both;
    }

    .panel {
        opacity: 0;
        transform: translateY(14px);
        animation: dashRise 0.6s ease forwards;
    }

    .status-panel {
        animation-delay: 0.05s;
    }

    .transcript-panel {
        animation-delay: 0.1s;
    }

    .booking-panel {
        animation-delay: 0.15s;
    }

    .tools-panel {
        animation-delay: 0.2s;
    }

    .tech-panel {
        animation-delay: 0.25s;
    }

    .metrics-bar {
        opacity: 0;
        transform: translateY(12px);
        animation: dashRise 0.6s ease 0.3s forwards;
    }
}

/* === Responsive === */
@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "status transcript"
            "booking transcript"
            "tools tools"
            "tech tech";
    }
}

@media (max-width: 960px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "status"
            "transcript"
            "booking"
            "tools"
            "tech";
    }

    .transcript-panel .chat-container {
        min-height: 420px;
    }
}

@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-4);
    }

    .dashboard-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .metrics-bar {
        grid-template-columns: 1fr;
    }

    .call-badge {
        font-size: 0.6rem;
    }

    .booking-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 480px) {
    .code-popup {
        width: 90%;
        padding: var(--space-6);
    }
}
