/* Base Palette & Variables */
:root {
    --primary: #565ADD;
    --primary-hover: #4548b0;
    --primary-light: rgba(86, 90, 221, 0.1);
    
    /* Layout Variables */
    --bg-page: #f1f5f9; /* Overall desktop background */
    --bg-app: #ffffff; /* Inner app background */
    --bg-sidebar: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    
    --success: #10b981;
    --success-light: #ecfdf5;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    
    --sidebar-width: 250px;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-pill: 50px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

[data-theme='dark'] {
    --bg-page: #020617;
    --bg-app: #0f172a;
    --bg-sidebar: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
}

/* Ensure raw PNG logos with dark text remain visible in dark mode */
[data-theme='dark'] .logo img {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Global Normalize */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s;
    overflow: hidden; /* Stop full body scroll, handle internally */
}

/* Utilities */
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.w-100 { width: 100%; }
.text-right { text-align: right; }
.p-0 { padding: 0 !important; }
.border-0 { border: none !important; box-shadow: none !important; }
.overflow-hidden { overflow: hidden; }

/* Desktop Full Width Layout */
.app-container {
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-app);
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 1.5rem 1.5rem;
}

.nav-scroll {
    overflow-y: auto;
    flex: 1;
    padding: 0 1rem;
}

.nav-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    padding-left: 0.75rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: var(--radius-pill); /* Pill shaped hover/active */
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
}

.nav-item.active {
    background-color: var(--primary);
    color: white;
}
.nav-item.active i { color: white; }

.sidebar-promo {
    background: linear-gradient(145deg, var(--bg-card), var(--bg-page));
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin: 1.5rem;
    text-align: center;
}
.promo-icon i {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}
.sidebar-promo h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.sidebar-promo p { font-size: 0.75rem; color: var(--text-secondary); }

/* Top Header */
.main-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.global-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2.5rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-app);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.hamburger-btn {
    display: none; /* hidden on desktop */
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
}

.search-bar {
    position: relative;
    max-width: 400px;
    width: 100%;
}
.search-bar i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.search-bar input {
    width: 100%;
    padding: 0.75rem 3rem 0.75rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background-color: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
    transition: all 0.2s;
}
.search-bar input:focus { border-color: var(--primary); }
.shortcut-key {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--border);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.icon-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-app);
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.notification-dot {
    position: absolute;
    top: 10px; right: 10px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--danger);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 0.5rem;
}
.avatar-sm, .avatar, .avatar-lg, .avatar-xl {
    border-radius: 50%;
    object-fit: cover;
}
.avatar-sm { width: 40px; height: 40px; }
.avatar { width: 44px; height: 44px; }
.avatar-lg { width: 72px; height: 72px; border: 2px solid var(--primary); }
.avatar-xl { width: 96px; height: 96px; border: 3px solid var(--primary); }

.user-info { display: flex; flex-direction: column; }
.user-info strong { font-size: 0.875rem; }
.user-info span { font-size: 0.75rem; color: var(--text-secondary); }

/* Main Content Views */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2.5rem;
}
.view-section {
    display: none;
    animation: fadeIn 0.3s ease-out;
}
.view-section.active { display: block; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}
h1 { font-size: 1.8rem; letter-spacing: -0.02em; }
.subtitle { color: var(--text-secondary); }

/* Buttons */
.btn {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.btn-pill { border-radius: var(--radius-pill); padding: 0.6rem 1.5rem; }
.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background-color: var(--bg-sidebar); border-color: var(--text-secondary); }

/* Metric Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.insight-grid {
    display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: transform 0.2s;
}
.metric-card:hover { transform: translateY(-2px); }

.card-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    box-shadow: 0 10px 15px -3px rgba(86,90,221,0.3);
}

.metric-header { display: flex; justify-content: space-between; align-items: flex-start; }
.metric-title { font-weight: 500; font-size: 0.9rem; color: var(--text-secondary); }
.card-primary .metric-title { color: rgba(255,255,255,0.8); }

.metric-icon-arrow {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-primary);
}
.card-primary .metric-icon-arrow {
    background: white; border: none; color: var(--primary);
}

.metric-value { font-size: 2.5rem; font-weight: 700; margin: 0.75rem 0; }
.metric-footer { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; }
.badge-trend { display: flex; align-items: center; padding: 0.15rem 0.4rem; border-radius: 4px; font-weight: 600; }
.badge-trend.positive { background: var(--success-light); color: var(--success); }
.badge-trend.negative { background: var(--danger-light); color: var(--danger); }
.trend-text { color: var(--text-secondary); }
.card-primary .trend-text { color: rgba(255,255,255,0.8); }

/* Dashboard Grids */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.card-header h2 { font-size: 1.25rem; }
.chart-card { min-height: 400px; display: flex; flex-direction: column; }
.canvas-wrapper { flex: 1; position: relative; width: 100%; min-height: 250px; }

.dashboard-sidebar-grid { display: grid; gap: 1.5rem; }

/* Lists & Tables */
.agent-list { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.agent-list li {
    display: flex; align-items: center; gap: 1rem;
    padding-bottom: 0.75rem; border-bottom: 1px dashed var(--border);
}
.agent-list li:last-child { border: none; padding-bottom: 0; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; font-weight: 600; background: var(--bg-card); }
.data-table tr:hover { background-color: var(--bg-input); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.5rem; }
.form-control {
    width: 100%; padding: 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-family: inherit; background: var(--bg-input);
    color: var(--text-primary); outline: none; transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--primary); }

/* Badges */
.badge { padding: 0.25rem 0.75rem; border-radius: 2rem; font-size: 0.75rem; font-weight: 600; }
.badge.danger { background-color: var(--danger-light); color: var(--danger); }
.badge.warning { background-color: var(--warning-light); color: var(--warning); }
.badge.success { background-color: var(--success-light); color: var(--success); }
.badge.neutral { background-color: var(--border); color: var(--text-primary); }

/* Kanban Board */
.kanban-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.kanban-col { background: var(--bg-input); padding: 1.25rem; border-radius: var(--radius-md); min-height: 400px; }
.kanban-header { margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; }
.kanban-header h3 { font-size: 0.9rem; color: var(--text-secondary); }
.kanban-cards { display: flex; flex-direction: column; gap: 1rem; }
.k-card {
    background: var(--bg-card); padding: 1.25rem; border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border); cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.k-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.k-card-title { font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; line-height: 1.4; }
.k-card-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; font-size: 0.85rem; color: var(--text-secondary); }
.k-card-meta .avatar { width: 28px; height: 28px; }

/* Calendar Grid */
.calendar-wrapper { padding: 1.5rem; }
.calendar-header-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
    font-weight: 600; color: var(--text-secondary); padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.calendar-days-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
    background-color: var(--border); 
    border-bottom: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.cal-day {
    background-color: var(--bg-card); min-height: 120px;
    padding: 0.75rem; transition: background-color 0.2s;
    height: 100%; overflow: hidden;
}
.cal-day:hover { background-color: var(--bg-input); cursor: pointer; }
.cal-date { font-weight: 500; color: var(--text-secondary); margin-bottom: 0.5rem; display: block; }
.cal-event {
    background-color: var(--primary-light); color: var(--primary);
    padding: 0.4rem 0.6rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600;
    margin-bottom: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event.completed {
    background-color: var(--success-light); color: var(--success); text-decoration: line-through;
}
.cal-day.other-month { background-color: var(--bg-input); opacity: 0.5; }


/* HALF-PAGE DRILLDOWN */
.half-page-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
    opacity: 0; visibility: hidden; z-index: 1000; transition: all 0.3s;
}
.agent-half-page-panel {
    position: fixed; right: -50vw; top: 0; width: 50vw; height: 100vh;
    background: var(--bg-sidebar); box-shadow: -10px 0 30px rgba(0,0,0,0.1); z-index: 1010;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex; flex-direction: column; border-left: 1px solid var(--border);
}
.agent-half-page-panel.open { right: 0; }
.half-page-overlay.open { opacity: 1; visibility: visible; }
.panel-header { padding: 2.5rem 2.5rem 1.5rem 2.5rem; border-bottom: 1px solid var(--border); }
.panel-content { padding: 1.5rem 2.5rem; overflow-y: auto; flex: 1; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   RESPONSIVE DESIGN (Media Queries)
   ========================================= */

@media (max-width: 1100px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .agent-half-page-panel {
        width: 70vw; right: -70vw;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 1.5rem 1rem;
    }
    
    .hamburger-btn { display: block; }
    .shortcut-key { display: none; }
    .user-info { display: none; }
    
    .global-header {
        padding: 1rem;
        gap: 1rem;
    }
    .search-bar input {
        padding-left: 2rem;
        padding-right: 1rem;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: 260px;
        transition: left 0.3s ease;
        box-shadow: var(--shadow-xl);
    }
    .sidebar.open {
        left: 0;
    }
    .sidebar-overlay {
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5); z-index: 90;
        display: none;
    }
    .sidebar-overlay.open {
        display: block;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    .insight-grid {
        grid-template-columns: 1fr;
    }
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .header-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }
    .header-actions .btn {
        flex: 1;
    }
    
    .data-table th, .data-table td {
        padding: 1rem 0.5rem;
    }
    .data-table .text-right { display: none; }
    
    .kanban-board {
        grid-template-columns: 1fr;
    }
    
    /* Calendar responsiveness for mobile - horizontally scrollable or simplified */
    .calendar-wrapper { overflow-x: auto; padding: 0.5rem; }
    .calendar-header-grid { min-width: 600px; }
    .calendar-days-grid { min-width: 600px; }
    
    .agent-half-page-panel {
        width: 100vw; right: -100vw;
    }
    .panel-header, .panel-content { padding: 1.5rem; }
    
    .agent-profile-hero {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
}
