:root {
    --bg-main: #f4f7f6;
    --bg-card: #ffffff;
    --primary: #4338ca;
    --primary-hover: #3730a3;
    --secondary: #0ea5e9;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html {
    font-size: 14px; /* Base font size dikecilkan dari browser default 16px */
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }
.mt-4 { margin-top: 0.85rem; }
.w-full { width: 100%; }

/* Panels */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

/* Screens */
.screen {
    min-height: 100vh;
    display: none;
}
.screen.active {
    display: flex;
}

/* Login */
#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0e7ff 100%);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 2.2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.5s ease-out;
}

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

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}
.logo-icon {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
    box-shadow: 0 4px 10px rgba(67, 56, 202, 0.3);
    flex-shrink: 0;
}
.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}
.input-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
}
input, textarea, .premium-select {
    background: #f9fafb;
    border: 1px solid var(--border);
    padding: 0.65rem 0.85rem;
    border-radius: 7px;
    color: var(--text-main);
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s;
    width: 100%;
}
input:focus, textarea:focus, .premium-select:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.12);
}

.btn-primary, .btn-secondary {
    padding: 0.65rem 1.2rem;
    border-radius: 7px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(67, 56, 202, 0.2);
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(67, 56, 202, 0.3);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.btn-secondary {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}
.btn-secondary:hover {
    background: #f3f4f6;
}
.btn-secondary.sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
}
.btn-danger {
    background: var(--danger);
    color: white;
    padding: 0.65rem 1.2rem;
    border-radius: 7px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.875rem;
}
.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* Dashboard Layout */
#dashboard-screen {
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar — overflow visible agar toggle button tidak terpotong */
.sidebar-wrapper {
    position: relative;
    height: 100vh;
    flex-shrink: 0;
}

.sidebar {
    width: 220px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
    border-right: 1px solid var(--border);
    padding: 1.2rem;
    transition: width 0.25s ease;
    overflow: hidden;
}
.sidebar.collapsed {
    width: 60px;
    padding: 1.2rem 0.75rem;
}
.sidebar.collapsed .sidebar-text {
    display: none;
}
.sidebar.collapsed .user-profile {
    justify-content: center;
}
.sidebar.collapsed .logo-container.sm {
    justify-content: center;
}

/* Sidebar Toggle Button — dipindah ke wrapper, tidak di dalam sidebar */
.sidebar-toggle {
    position: absolute;
    top: 1rem;
    right: -13px;
    width: 26px; height: 26px;
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 50;
    box-shadow: var(--shadow-md);
    transition: transform 0.25s ease, color 0.2s, border-color 0.2s;
}
.sidebar-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.logo-container.sm {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.logo-container.sm .logo-icon {
    width: 28px; height: 28px; font-size: 0.9rem;
}
.nav-links {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.85rem;
    border-radius: 7px;
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.875rem;
    cursor: pointer;
}
.nav-item:hover {
    background: #f3f4f6;
    color: var(--text-main);
}
.nav-item.active {
    background: #eef2ff;
    color: var(--primary);
    border-right: 3px solid var(--primary);
}
.nav-item svg {
    flex-shrink: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.avatar {
    width: 30px; height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.user-info .name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .division { font-size: 0.72rem; color: var(--text-muted); text-transform: capitalize; }
.icon-btn {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    transition: color 0.2s;
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--danger); }

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-main);
    min-width: 0;
}
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.5rem;
    background: white;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-shrink: 0;
}
.top-bar h2 {
    font-size: 1.05rem;
    font-weight: 600;
}
.status-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* WebSocket Status Dot */
.ws-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.ws-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    transition: background 0.3s;
}
.ws-dot.connected { background: var(--success); animation: pulse-dot 2s infinite; }
.ws-dot.error { background: var(--danger); }
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Views */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}
.view.active {
    display: flex;
}

/* Workspace Grid (Inbox) */
.workspace-grid {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 1.2rem;
    flex: 1;
    min-height: 0;
    padding: 1.2rem;
}

/* Ticket List */
.ticket-list-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #f9fafb;
    border-radius: 10px 10px 0 0;
}
.tab {
    flex: 1;
    padding: 0.75rem 0.5rem;
    background: none; border: none;
    color: var(--text-muted);
    font-weight: 600; cursor: pointer;
    border-bottom: 2px solid transparent;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: white;
}
.badge {
    background: var(--danger);
    color: white;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 0.68rem;
    margin-left: 0.2rem;
}
.ticket-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: white;
    border-radius: 0 0 10px 10px;
}
.ticket-item {
    padding: 0.75rem;
    background: white;
    border-radius: 7px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.ticket-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.ticket-item.active {
    border-color: var(--primary);
    background: #eef2ff;
}
.ticket-item h4 { font-size: 0.875rem; margin-bottom: 0.2rem; color: var(--text-main); }
.ticket-item p { font-size: 0.75rem; color: var(--text-muted); }

/* Chat Panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-header {
    padding: 0.85rem 1.2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border-radius: 10px 10px 0 0;
    flex-shrink: 0;
}
.channel-badge {
    font-size: 0.72rem;
    background: #dcfce7;
    color: #166534;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: #f8fafc;
}
.chat-bubble {
    max-width: 72%;
    padding: 0.7rem 1rem;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
}
.chat-bubble.customer {
    background: white;
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}
.chat-bubble.agent {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
/* Bot bubble di kanan karena bot berbicara atas nama Saga (seperti agent) */
.chat-bubble.bot {
    background: #0ea5e9;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.chat-input-area {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    background: white;
    border-radius: 0 0 10px 10px;
    align-items: flex-end;
    flex-shrink: 0;
}
.chat-input-area textarea {
    flex: 1;
    min-height: 44px;
    max-height: 100px;
    resize: none;
    pointer-events: auto !important;
}
.stat-card {
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* CRM Sidebar */
.crm-sidebar {
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.crm-sidebar h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.85rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* CRM Tabs inside sidebar */
.crm-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
}
.crm-tab {
    flex: 1;
    padding: 0.5rem 0.4rem;
    background: none;
    border: none;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.crm-tab.active {
    background: var(--primary);
    color: white;
}
.crm-tab-pane { display: none; }
.crm-tab-pane.active { display: block; }

/* Follow-up labels */
.followup-item {
    padding: 0.65rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}
.followup-item .fu-label {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.7rem;
    margin-bottom: 4px;
}
.fu-PANAS { background: #fee2e2; color: #dc2626; }
.fu-HANGAT { background: #fef3c7; color: #d97706; }
.fu-DINGIN { background: #dbeafe; color: #2563eb; }

/* Other Views (CRM, Analytics) */
.view-content {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}
.instruction-box {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    padding: 1.2rem;
    border-radius: 10px;
    margin-bottom: 1.5rem;
}
.instruction-box h3 {
    color: var(--primary);
    margin-bottom: 0.4rem;
    font-size: 0.95rem;
}
.instruction-box p {
    color: #4f46e5;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Utilities */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 1.5rem;
}
.empty-state svg {
    margin-bottom: 0.85rem;
    color: #cbd5e1;
}

.loader {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s infinite linear;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.error-msg {
    color: var(--danger);
    font-size: 0.82rem;
    text-align: center;
    padding: 0.65rem;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 7px;
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem; right: 1.5rem;
    background: var(--text-main);
    color: white;
    padding: 0.8rem 1.2rem;
    border-radius: 7px;
    box-shadow: var(--shadow-lg);
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 9999;
    font-size: 0.875rem;
    max-width: 320px;
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
    background: white;
    border-radius: 12px;
    padding: 1.8rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}
.modal-box h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.5rem; }
.modal-box p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.2rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.2rem; }

/* ===== VIEW CONTENT (full page views) ===== */
.view-content {
    padding: 1.5rem;
    overflow-y: auto;
    height: 100%;
}

/* ===== Follow-up AI View ===== */
.fu-label {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.fu-PANAS { background: #fef2f2; color: #ef4444; }
.fu-HANGAT { background: #fffbeb; color: #f59e0b; }
.fu-DINGIN { background: #eff6ff; color: #0ea5e9; }

.followup-item {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    margin-bottom: 7px;
    background: #fafafa;
    transition: background 0.15s;
}
.followup-item:hover { background: white; }

/* ===== Blast View ===== */
#blast-form textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    box-sizing: border-box;
}

/* ===== Admin Tab Buttons ===== */
.admin-tab-btn {
    transition: all 0.2s;
    font-weight: 600;
    cursor: pointer;
}
.admin-tab-btn:hover {
    opacity: 0.85;
}

/* ===== Office Hours ===== */
#office-hours-container {
    max-height: 400px;
    overflow-y: auto;
}

/* ===== Stat Cards ===== */
.stat-card {
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ===== Responsive improvements ===== */
@media (max-width: 900px) {
    .workspace-grid {
        grid-template-columns: 1fr !important;
    }
    .crm-sidebar {
        display: none !important;
    }
}

/* ===== Data Table Styling ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
    white-space: nowrap;
}
.data-table thead tr {
    background-color: #f8fafc;
    border-bottom: 2px solid var(--border);
}
.data-table th {
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-main);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}
.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s;
}
.data-table tbody tr:hover {
    background-color: #f1f5f9;
}
.data-table td {
    padding: 12px 16px;
    color: var(--text-muted);
}
.data-table td .badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.7rem;
}
