/* ===========================
   CSS Variables
   =========================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --border-dark: #212529;
    --accent: #0d6efd;
    --accent-hover: #0b5ed7;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --transition: 0.15s ease;
}

/* ===========================
   Reset & Base
   =========================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-secondary);
    min-height: 100vh;
}

/* ===========================
   App Layout
   =========================== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 32px;
}

.app-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

.status-dot.connected {
    background: var(--success);
}

.main {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 24px;
}

/* ===========================
   Panel & Cards
   =========================== */
.panel {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 600px;
}

.setup-panel {
    padding: 32px;
}

.panel-header {
    text-align: center;
    margin-bottom: 32px;
}

.panel-header h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
}

/* ===========================
   Role Cards
   =========================== */
.role-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.role-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
}

.role-card:hover {
    border-color: var(--text-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.role-card.selected {
    border-color: var(--accent);
    background: #f0f7ff;
}

.role-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.role-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.role-desc {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

/* ===========================
   Setup Forms
   =========================== */
.setup-form {
    animation: slideIn 0.2s ease;
}

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

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

.form-section label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-group {
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* ===========================
   Driver Card
   =========================== */
.driver-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.driver-avatar {
    font-size: 28px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
}

.driver-details {
    flex: 1;
}

.driver-name {
    font-weight: 600;
    margin-bottom: 2px;
}

.driver-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
}

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

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

.btn-primary:hover:not(:disabled) {
    background: #333;
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
}

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

.btn-success:hover:not(:disabled) {
    background: #157347;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: #bb2d3b;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-lg {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 16px;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-secondary);
}

/* ===========================
   Inputs
   =========================== */
input,
select {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

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

.select-lg {
    padding: 14px 16px;
    font-size: 15px;
}

/* ===========================
   Status Text
   =========================== */
.status-text {
    text-align: center;
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-text.error {
    color: var(--danger);
}

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

/* ===========================
   Dashboard Layout
   =========================== */
.dashboard {
    display: flex;
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - 80px);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.sidebar {
    width: 200px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.session-badge {
    padding: 16px;
    background: var(--text-primary);
    color: var(--bg-primary);
    border-radius: var(--radius-md);
    text-align: center;
    margin-bottom: 24px;
}

.badge-role {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.badge-id {
    font-size: 13px;
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg-tertiary);
}

.nav-item.active {
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

.nav-icon {
    font-size: 18px;
}

.nav-label {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.nav-badge {
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* ===========================
   Content Area
   =========================== */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.view {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.view.active {
    display: flex;
}

/* ===========================
   Chat View
   =========================== */
.chat-view {
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.5;
    white-space: pre-wrap;
    animation: fadeIn 0.2s ease;
}

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

.message.user {
    background: var(--text-primary);
    color: var(--bg-primary);
    align-self: flex-end;
    border-bottom-right-radius: var(--radius-sm);
}

.message.agent {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    align-self: flex-start;
    border-bottom-left-radius: var(--radius-sm);
}

.message.system {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    align-self: center;
    font-size: 13px;
    max-width: 90%;
}

.message.error {
    background: #f8d7da;
    border: 1px solid var(--danger);
    color: #842029;
}

.message.typing {
    background: var(--bg-secondary);
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    align-self: flex-start;
}

.typing-dots::after {
    content: "";
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%,
    20% {
        content: ".";
    }
    40% {
        content: "..";
    }
    60%,
    100% {
        content: "...";
    }
}

/* ===========================
   Chat Input
   =========================== */
.chat-input {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.chat-input input {
    flex: 1;
}

.btn-voice {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.btn-voice:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-voice.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.waveform-container {
    display: none;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.waveform-container.active {
    display: flex;
}

.waveform {
    flex: 1;
    height: 44px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.recording-indicator {
    width: 12px;
    height: 12px;
    background: var(--danger);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* ===========================
   Cases View
   =========================== */
.cases-view {
    padding: 24px;
    overflow-y: auto;
}

.cases-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.cases-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.cases-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.case-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
}

.case-card:hover {
    border-color: var(--text-secondary);
    box-shadow: var(--shadow-md);
}

.case-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.case-type {
    display: flex;
    align-items: center;
    gap: 8px;
}

.case-type-icon {
    font-size: 20px;
}

.case-type-label {
    font-weight: 600;
    text-transform: capitalize;
}

.case-status {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 4px;
    background: #fff3cd;
    color: #856404;
}

.case-status.approved {
    background: #d1e7dd;
    color: #0f5132;
}

.case-id-row {
    font-family: monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.case-meta {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.case-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.case-suggestion-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===========================
   Suggestion Cards
   =========================== */
.suggestion-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.suggestion-card.recommended {
    border-color: var(--success);
    background: #f0fff4;
}

.suggestion-score {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    background: var(--bg-tertiary);
}

.suggestion-score.high {
    background: #d1e7dd;
    color: var(--success);
}

.suggestion-score.medium {
    background: #fff3cd;
    color: #856404;
}

.suggestion-score.low {
    background: #f8d7da;
    color: var(--danger);
}

.suggestion-details {
    flex: 1;
}

.suggestion-type {
    font-weight: 600;
    margin-bottom: 2px;
    text-transform: capitalize;
}

.suggestion-reason {
    font-size: 13px;
    color: var(--text-secondary);
}

.suggestion-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 8px;
    background: var(--success);
    color: white;
    border-radius: 4px;
}

/* ===========================
   Empty State
   =========================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 15px;
}

/* ===========================
   Modal
   =========================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.btn-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.modal-section {
    margin-bottom: 24px;
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.modal-suggestion {
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.modal-suggestion:last-child {
    margin-bottom: 0;
}

.modal-suggestion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.modal-suggestion-type {
    font-weight: 600;
    text-transform: capitalize;
}

.modal-suggestion-score {
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.modal-suggestion-reason {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
}

.score-breakdown {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.score-factor {
    text-align: center;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.score-factor-value {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.score-factor-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    margin-top: 16px;
}

.modal-actions .btn {
    flex: 1;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .main {
        padding: 16px;
    }

    .role-cards {
        grid-template-columns: 1fr;
    }

    .dashboard {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 80px);
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        padding: 12px;
        gap: 12px;
        overflow-x: auto;
    }

    .session-badge {
        margin-bottom: 0;
        padding: 12px;
        white-space: nowrap;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 8px;
    }

    .nav-item {
        padding: 10px 14px;
    }

    .sidebar-footer {
        padding-top: 0;
        border-top: none;
        margin-left: auto;
    }

    .chat-messages {
        padding: 16px;
        min-height: 300px;
    }

    .message {
        max-width: 90%;
    }

    .chat-input {
        padding: 12px 16px;
    }
}
