/*
 * IVR Call Visualizer — Stylesheet
 * Adapted from HCLTech ICC Realtime UI
 */

/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0066cc;
    --success-color: #4CAF50;
    --danger-color: #d32f2f;
    --warning-color: #ff9800;
    --muted-color: #9e9e9e;

    --bg-main: #f6f7fb;
    --bg-header: #ffffff;
    --bg-chat: #f4f8fb;
    --bg-message-user: #e3e5ea;
    --bg-message-agent: #eaf6ff;
    --bg-message-system: #fff8e1;
    --bg-message-tool: #f3e5f5;

    --text-primary: #212121;
    --text-secondary: #666666;
    --text-muted: #999999;

    --border-color: #ddd;
    --border-radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;

    /* Theme-specific (can be overridden via JavaScript from agent profile) */
    --header-gradient: linear-gradient(135deg, #6320ff 0%, #2a7cfb 45%, #60a5fa 100%);
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-main);
    margin: 0;
}

/* ==================== App Container ==================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 92vh;
    max-width: 580px;
    margin: 24px auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    border: 2px solid var(--primary-color);
    overflow: hidden;
    position: relative;  /* For absolute-positioned settings drawer */
}

/* ==================== Header ==================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 12px 20px;
    min-height: 56px;
    background: var(--header-gradient);
    color: white;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    height: 40px;
    width: auto;
    border-radius: 0;
    background: transparent;
    padding: 0;
}

.header-icon {
    font-size: 24px;
}

.header-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.subtitle {
    font-size: 11px;
    margin: 0;
    opacity: 0.85;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.connection-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.15);
    white-space: nowrap;
}

.connection-badge.connected {
    background: rgba(76, 175, 80, 0.3);
    color: #e8f5e9;
}

.connection-badge.disconnected {
    background: rgba(211, 47, 47, 0.3);
    color: #ffcdd2;
}

.btn-clear {
    padding: 4px 12px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-clear:hover {
    background: rgba(255,255,255,0.35);
}

/* ==================== Session Tabs Bar ==================== */
.session-tabs-bar {
    display: flex;
    align-items: stretch;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border-color);
    min-height: 0;
}

.session-tabs-bar:has(.session-tab) {
    min-height: 34px;
}

/* Event counter in session tabs bar */
.session-tabs-bar .event-counter {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border-right: 1px solid var(--border-color);
    white-space: nowrap;
}

.session-tabs {
    display: flex;
    gap: 0;
    flex: 1;
    overflow-x: auto;
    min-height: 0;
}

.session-tabs:empty + .tabs-actions {
    display: none;
}

.tabs-actions {
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 4px;
    border-left: 1px solid var(--border-color);
    background: #f0f2f5;
    flex-shrink: 0;
}

.btn-tab-action {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-tab-action:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.session-tab {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.session-tab:hover {
    background: #e8eaed;
}

.session-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: white;
    font-weight: 600;
}

.session-tab .tab-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.session-tab .tab-status.ringing-call {
    background: var(--warning-color);
    animation: pulse-dot 0.8s infinite;
}

.session-tab .tab-status.active-call {
    background: var(--success-color);
    animation: pulse-dot 1.5s infinite;
}

.session-tab .tab-status.ended-call {
    background: var(--muted-color);
}

.session-tab .tab-caller {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 4px;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ==================== Call Status Banner ==================== */
.call-status {
    padding: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 0;
}

.call-status.visible {
    max-height: 120px;
}

.call-status-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
}

.call-status.ringing .call-status-inner {
    background: linear-gradient(90deg, #fff8e1, #fff3c4);
    color: #e65100;
}

.call-status.connected .call-status-inner {
    background: linear-gradient(90deg, #e8f5e9, #c8e6c9);
    color: #2e7d32;
}

.call-status.ended .call-status-inner {
    background: linear-gradient(90deg, #fce4ec, #f8bbd0);
    color: #c62828;
}

.status-icon {
    font-size: 22px;
}

/* Ringing animation */
.call-status.ringing .status-icon {
    display: inline-block;
    animation: ring 0.6s ease-in-out infinite;
    transform-origin: 50% 4px;
}

@keyframes ring {
    0%   { transform: rotate(0deg); }
    15%  { transform: rotate(15deg); }
    30%  { transform: rotate(-12deg); }
    45%  { transform: rotate(8deg); }
    60%  { transform: rotate(-5deg); }
    75%  { transform: rotate(2deg); }
    100% { transform: rotate(0deg); }
}

/* ==================== Chat Container ==================== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
    background: var(--bg-chat);
}

.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #888;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 8px;
    animation: gentle-pulse 3s ease-in-out infinite;
}

@keyframes gentle-pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

.empty-hint {
    font-size: 13px;
    color: #bbb;
}

/* ==================== Chat Messages ==================== */
.chat-message {
    margin-bottom: var(--spacing-lg);
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-label .msg-time {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: none;
}

.message-content {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: 10px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    font-size: 0.93em;
    word-wrap: break-word;
}

/* User bubble — right-aligned */
.user-message .message-content {
    background: var(--bg-message-user);
    border: none;
    margin-left: 20%;
}

/* Agent bubble — left-aligned */
.agent-message .message-content {
    background: var(--bg-message-agent);
    border: none;
    margin-right: 20%;
}

/* Interrupted agent message — controlled by body classes */
body.grey-bargedin .agent-message.interrupted .message-content {
    opacity: 0.4;
}

body.grey-bargedin .agent-message.interrupted .message-label {
    opacity: 0.4;
}

body.strikethrough-bargedin .agent-message.interrupted .message-content {
    text-decoration: line-through;
    text-decoration-color: var(--text-muted);
}

/* Highlight question sentences in agent messages — draws demo-er attention */
.question-highlight {
    font-weight: 700;
    color: #0d47a1;
    background: #e3f2fd;
    border-radius: 3px;
    padding: 0 2px;
}

/* System event bubble — centered, subtle */
.system-message {
    text-align: center;
}

.system-message .message-content {
    display: inline-block;
    background: var(--bg-message-system);
    border: 1px solid #ffe082;
    font-size: 0.85em;
    padding: 6px 16px;
    border-radius: 16px;
    color: #795548;
}

/* Tool call bubble */
.tool-message .message-content {
    background: var(--bg-message-tool);
    border: 1px solid #ce93d8;
    margin-right: 20%;
    font-size: 0.85em;
    padding: 8px 14px;
}

/* DTMF input bubble — user-side, distinct from speech */
.dtmf-message .message-content {
    background: #e8f5e9;
    border: 1px solid #81c784;
    margin-left: 20%;
    font-size: 0.9em;
    padding: 8px 14px;
}

.dtmf-message .dtmf-digits {
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 700;
    font-size: 1.05em;
    letter-spacing: 2px;
    color: #2e7d32;
}

/* Production visualizer DTMF */
.message-dtmf .message-body {
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 600;
    color: #2e7d32;
}

.message-dtmf {
    border-left: 3px solid #4CAF50;
}

.dtmf-key {
    display: inline-block;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 4px;
    padding: 1px 6px;
    margin: 1px 2px;
    font-size: 0.9em;
}

.tool-message .tool-name {
    font-weight: 600;
    color: #7b1fa2;
}

.tool-message .tool-status {
    font-size: 11px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.tool-message .tool-status.approval_requested {
    color: #7b1fa2;
}

.tool-message .tool-status.approved,
.tool-message .tool-status.ready {
    color: var(--primary-color);
}

.tool-message .tool-status.completed {
    color: var(--success-color);
}

.tool-message .tool-status.in_progress {
    color: var(--warning-color);
}

.tool-message .tool-status.denied {
    color: var(--danger-color);
}

/* Typing / thinking indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 16px;
    background: var(--bg-message-agent);
    border-radius: 10px;
    margin-right: 20%;
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    background: #90caf9;
    border-radius: 50%;
    animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ==================== Controls Container ==================== */
.controls-container {
    padding: 10px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.controls-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.agent-selector {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.agent-selector:hover {
    border-color: var(--primary-color);
}

.agent-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 108, 198, 0.1);
}

.controls-spacer {
    flex: 1;
}

.btn {
    padding: 6px 14px;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn-test {
    background: var(--primary-color);
    color: white;
    border-color: #0052a3;
}

.btn-test:hover {
    background: #0052a3;
}

.btn-clear-chat {
    background: #f5f5f5;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-clear-chat:hover {
    background: #ffebee;
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-clear-all {
    background: #f5f5f5;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-clear-all:hover {
    background: #ffebee;
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-download-all {
    background: #e8f5e9;
    color: #2e7d32;
    border-color: #a5d6a7;
}

.btn-download-all:hover {
    background: #2e7d32;
    color: white;
    border-color: #2e7d32;
}

/* Remove old event-counter bottom styles (now in session-tabs-bar) */

.btn-settings {
    padding: 6px 12px;
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    background: #f5f5f5;
    color: var(--text-secondary);
    transition: all 0.2s;
    margin-left: 8px;
}

.btn-settings:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.btn-settings:active {
    transform: translateY(0);
}

/* ==================== Responsive ==================== */
@media (max-width: 620px) {
    .app-container {
        margin: 0;
        border-radius: 0;
        height: 100vh;
        border: none;
        max-width: 100%;
    }

    .app-header {
        border-radius: 0;
    }

    .saved-sidebar {
        width: 100%;
    }
}

/* ==================== Saved Sessions Sidebar ==================== */
.saved-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: white;
    border-left: 2px solid var(--border-color);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
    z-index: 20;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

.saved-sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    background: #f6f7fb;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.sidebar-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.sidebar-close:hover {
    background: #ffebee;
    color: var(--danger-color);
}

.sidebar-actions {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}

.btn-sidebar-action {
    flex: 1;
    padding: 5px 8px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.btn-sidebar-action:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-sidebar-action.danger:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.saved-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.saved-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 24px 12px;
    line-height: 1.6;
}

.saved-session-item {
    position: relative;
    padding: 10px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.saved-session-item:hover {
    background: #f0f4ff;
    border-color: #c5cae9;
}

.saved-session-item.active {
    background: #e3f2fd;
    border-color: var(--primary-color);
}

.saved-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.saved-lang {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
    background: var(--primary-color);
    padding: 1px 6px;
    border-radius: 4px;
}

.saved-time {
    font-size: 10px;
    color: var(--text-muted);
}

.saved-item-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.saved-caller {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.saved-count {
    font-size: 10px;
    color: var(--text-muted);
}

.saved-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px 4px;
    border-radius: 3px;
}

.saved-session-item:hover .saved-delete-btn {
    opacity: 1;
}

.saved-delete-btn:hover {
    color: var(--danger-color);
    background: #ffebee;
}

/* ==================== Read-Only Banner ==================== */
.readonly-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 6px 16px;
    background: #fff3e0;
    border-bottom: 1px solid #ffe0b2;
    font-size: 12px;
    font-weight: 500;
    color: #e65100;
}

.btn-exit-saved {
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #ffcc80;
    border-radius: var(--border-radius);
    background: white;
    color: #e65100;
    transition: all 0.15s;
}

.btn-exit-saved:hover {
    background: #e65100;
    color: white;
    border-color: #e65100;
}

/* Read-only chat overlay */
.chat-container.readonly {
    position: relative;
}

.chat-container.readonly::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 10px,
        rgba(0, 0, 0, 0.01) 10px,
        rgba(0, 0, 0, 0.01) 20px
    );
}

/* ==================== Settings Drawer ==================== */
.settings-drawer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--border-color);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.settings-drawer.open {
    transform: translateY(0);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: #f6f7fb;
}

.settings-header h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.settings-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.settings-close:hover {
    background: #ffebee;
    color: var(--danger-color);
}

.settings-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.settings-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius);
    transition: background 0.15s;
}

.settings-checkbox:hover {
    background: #f6f7fb;
}

.settings-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.settings-checkbox span {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* ==================== Conditional Display Rules ==================== */

/* Hide timestamps when setting is off */
body.hide-timestamps .msg-time {
    display: none;
}

/* Hide sound events when setting is off */
body.hide-sound-events .sound-event {
    display: none;
}
