/**
 * CCAP Enterprise Design System v3.0
 * High-density, professional Dark & Light Theme System for Mission-Critical Call Centers
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Light Theme Palette (Default Light) */
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-subtle: #f1f5f9;
    --bg-surface-hover: #e2e8f0;
    --border-color: #e2e8f0;
    --border-subtle: #cbd5e1;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-dim: #94a3b8;

    --accent-primary: #0284c7;
    --accent-primary-hover: #0369a1;
    --accent-emerald: #059669;
    --accent-emerald-subtle: #ecfdf5;
    --accent-amber: #d97706;
    --accent-amber-subtle: #fffbeb;
    --accent-rose: #e11d48;
    --accent-rose-subtle: #fff1f2;
    --accent-indigo: #4f46e5;
    --accent-indigo-subtle: #eef2ff;

    --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.07), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --shadow-elevated: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --sidebar-width: 250px;
    --header-height: 60px;
}

[data-bs-theme="dark"] {
    /* Dark Theme Palette (Enterprise Slate) */
    --bg-body: #0b0f19;
    --bg-surface: #111827;
    --bg-surface-subtle: #1f2937;
    --bg-surface-hover: #2d3748;
    --border-color: #1f2937;
    --border-subtle: #374151;

    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;

    --accent-primary: #38bdf8;
    --accent-primary-hover: #0ea5e9;
    --accent-emerald: #10b981;
    --accent-emerald-subtle: rgba(16, 185, 129, 0.12);
    --accent-amber: #f59e0b;
    --accent-amber-subtle: rgba(245, 158, 11, 0.12);
    --accent-rose: #f43f5e;
    --accent-rose-subtle: rgba(244, 63, 94, 0.12);
    --accent-indigo: #818cf8;
    --accent-indigo-subtle: rgba(129, 140, 248, 0.12);

    --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.3);
    --shadow-elevated: 0 14px 30px rgba(0, 0, 0, 0.5);
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 0.875rem;
    line-height: 1.5;
    letter-spacing: -0.01em;
    overflow-x: hidden;
}

.font-mono {
    font-family: var(--font-mono) !important;
}

/* Theme utility classes */
.text-main {
    color: var(--text-main) !important;
}

.text-dim {
    color: var(--text-dim) !important;
}

.bg-surface {
    background-color: var(--bg-surface) !important;
}

.bg-surface-subtle {
    background-color: var(--bg-surface-subtle) !important;
}

.border-theme {
    border-color: var(--border-color) !important;
}

/* High-contrast badge support for theme variables */
.badge.text-main,
.badge.bg-surface-subtle {
    color: var(--text-main) !important;
    background-color: var(--bg-surface-subtle) !important;
    border-color: var(--border-color) !important;
}

/* App Wrapper Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Modern Left Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1020;
    transition: width 0.2s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-main);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.sidebar-brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #059669 0%, #0284c7 100%);
    color: #ffffff;
    font-size: 1.1rem;
    margin-right: 0.75rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.nav-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    padding: 0.75rem 0.75rem 0.25rem 0.75rem;
    margin-top: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.sidebar-link i {
    font-size: 1.1rem;
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.sidebar-link:hover {
    color: var(--text-main);
    background-color: var(--bg-surface-subtle);
}

.sidebar-link.active {
    color: #ffffff;
    background-color: var(--accent-primary);
    font-weight: 600;
}

[data-bs-theme="dark"] .sidebar-link.active {
    background-color: #0284c7;
    color: #ffffff;
}

/* Sidebar Submenu & Collapsible Settings */
.sidebar-dropdown-toggle {
    cursor: pointer;
    user-select: none;
}
.sidebar-dropdown-toggle .dropdown-arrow {
    transition: transform 0.2s ease;
    transform: rotate(0deg);
}
.sidebar-dropdown-toggle[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}
.sidebar-submenu {
    border-left: 2px solid var(--border-color);
    margin-left: 1.15rem;
    padding-left: 0.5rem;
    margin-top: 0.25rem;
    margin-bottom: 0.45rem;
}
.sidebar-sublink {
    font-size: 0.825rem;
    padding: 0.42rem 0.65rem;
    margin-bottom: 2px;
}
.sidebar-sublink i {
    font-size: 0.95rem;
    width: 18px;
    margin-right: 0.55rem;
}

/* Main Content Area */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header Top Bar */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1010;
}

/* Cards & Panels */
.card-enterprise {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-header-enterprise {
    padding: 0.85rem 1.25rem;
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.95rem;
}

/* High-Density Data Tables */
.table-enterprise {
    width: 100%;
    margin-bottom: 0;
    color: var(--text-main);
    border-color: var(--border-color);
    vertical-align: middle;
}

.table-enterprise thead th {
    background-color: var(--bg-surface-subtle);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    border-top: none;
    white-space: nowrap;
}

.table-enterprise tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.table-enterprise tbody tr:hover {
    background-color: var(--bg-surface-subtle);
}

/* Metric / KPI Chips */
.kpi-box {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-card);
}

.kpi-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}

/* Micro Badges & Pills */
.pill-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    line-height: 1;
}

.pill-success {
    background-color: var(--accent-emerald-subtle);
    color: var(--accent-emerald);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.pill-warning {
    background-color: var(--accent-amber-subtle);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.pill-danger {
    background-color: var(--accent-rose-subtle);
    color: var(--accent-rose);
    border: 1px solid rgba(244, 63, 94, 0.3);
}

.pill-info {
    background-color: var(--accent-indigo-subtle);
    color: var(--accent-indigo);
    border: 1px solid rgba(129, 140, 248, 0.3);
}

/* Operator Status Selector Pill */
.status-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}
.dot-online { background-color: var(--accent-emerald); box-shadow: 0 0 8px var(--accent-emerald); }
.dot-prepare { background-color: #64748b; box-shadow: 0 0 6px rgba(100, 116, 139, 0.4); }
.dot-busy { background-color: var(--accent-primary); }
.dot-lunch { background-color: var(--accent-amber); }
.dot-break, .dot-break_15 { background-color: #f97316; }
.dot-training { background-color: #8b5cf6; }
.dot-offline { background-color: var(--text-dim); }

/* Slide-over Draw Panel */
.slideover-panel {
    position: fixed;
    top: 0;
    right: -450px;
    width: 450px;
    height: 100vh;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-elevated);
    z-index: 1040;
    transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.slideover-panel.open {
    right: 0;
}

.slideover-panel.pinned {
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.25);
    border-left: 2px solid var(--accent-primary);
}

.slideover-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1030;
    display: none;
}

.slideover-backdrop.show {
    display: block;
}

/* Pinned Softphone state on body */
body.phone-pinned .slideover-backdrop {
    display: none !important;
    pointer-events: none !important;
}

@media (min-width: 1200px) {
    body.phone-pinned .app-main {
        margin-right: 380px;
        transition: margin-right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* Modal Stacking Hierarchy */
.modal {
    z-index: 1055 !important;
}
.modal-backdrop {
    z-index: 1050 !important;
}
#incomingCallModal {
    z-index: 1080 !important;
}

/* ==========================================================================
   Visual Flow Builder Styles
   ========================================================================== */
.flow-builder-container-fluid {
    height: calc(100vh - 195px);
    min-height: 600px;
    width: 100%;
    position: relative;
}

.flow-builder-wrapper {
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.flow-sim-drawer {
    border-top: 2px solid var(--accent-primary) !important;
    background-color: var(--bg-surface);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
}

[data-bs-theme="dark"] .flow-sim-drawer {
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
}

.flow-builder-wrapper:fullscreen,
.flow-builder-wrapper:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    background-color: var(--bg-body) !important;
    z-index: 9999;
}

.flow-canvas-container {
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.flow-node {
    border-radius: 8px;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.flow-node:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25) !important;
}

.flow-port {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--accent-primary);
    border: 2px solid var(--bg-surface);
    cursor: crosshair;
    transition: transform 0.15s ease, background-color 0.15s ease;
    z-index: 10;
}

.flow-port:hover {
    transform: scale(1.4);
    background-color: var(--accent-amber) !important;
}

.flow-port-in {
    position: absolute;
    left: -7px;
    top: 50%;
    transform: translateY(-50%);
    background-color: var(--accent-primary);
}

.flow-port-out {
    position: relative;
    right: -7px;
}

.flow-edge-path {
    transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.flow-edge-path:hover {
    stroke: var(--accent-amber) !important;
    stroke-width: 5px !important;
}

.edge-active-pulse {
    stroke: #10b981 !important;
    stroke-dasharray: 8,4;
    animation: flowEdgePulse 1s linear infinite;
}

@keyframes flowEdgePulse {
    from { stroke-dashoffset: 24; }
    to { stroke-dashoffset: 0; }
}

.node-active-pulse {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.35) !important;
    animation: flowNodeGlow 1.5s infinite alternate;
}

@keyframes flowNodeGlow {
    0% { box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3); }
    100% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.6); }
}

/* Ensure inactive tabs are strictly hidden and active flow tab is properly flexed */
.tab-content > .tab-pane:not(.active) {
    display: none !important;
}

#tab-flow.active {
    display: flex !important;
    flex-direction: column;
}

