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

:root {
    --bg-color: #f8fafc;
    --border-color: #e2e8f0;
    --glass-border: #e2e8f0;
    --card-bg: #ffffff;
    --glass-bg: #ffffff;
    --bg-card: #ffffff;
    --primary: #0f172a;
    --primary-hover: #334155;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --success: #10b981;
    --success-bg: #d1fae5;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --sidebar-width: 280px;
    --sidebar-bg: #ffffff;
    --sidebar-active: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

body.dark-mode {
    --bg-color: #0b0f19;
    --card-bg: #111827;
    --border-color: #1f2937;
    --primary: #ffffff;
    --primary-hover: #e2e8f0;
    --accent: #3b82f6;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --sidebar-bg: #111827;
    --sidebar-active: #1f2937;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger-bg: rgba(239, 68, 68, 0.1);
    --warning-bg: rgba(245, 158, 11, 0.1);
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    margin: 0 0 15px 0;
    color: var(--text-main);
    font-weight: 600;
}

h2 { font-size: 24px; }
h3 { font-size: 18px; }

p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Auth Screens */
body.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

body.dark-mode.auth-page {
    background: linear-gradient(135deg, #0b0f19 0%, #111827 100%);
}

#login-screen, #forgot-screen, #reset-screen {
    width: 400px;
    max-width: 90vw;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-main);
}

/* Reusing glass-container class but styling it as a premium solid card */
.glass-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.step-box {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.step-box:hover {
    box-shadow: var(--shadow-md);
}

/* Forms */
label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    display: block;
    margin-bottom: 8px;
}

input, select, textarea {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--card-bg);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Buttons */
button {
    width: 100%;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
}

.btn-primary {
    background: var(--primary);
    color: var(--card-bg);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-accent:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-color);
    border-color: var(--text-muted);
}

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

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

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

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 50;
}

.app-sidebar .logo {
    padding: 25px 20px 15px 20px;
    margin: 0;
    justify-content: flex-start;
}

.app-sidebar .nav-menu {
    flex: 1;
    list-style: none;
    padding: 10px 15px;
    margin: 0;
    overflow-y: auto;
}

.nav-item {
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
}

.nav-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    color: inherit;
}

.nav-item:hover {
    background: var(--sidebar-active);
    color: var(--text-main);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--accent);
    font-weight: 600;
}

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

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-header {
    display: none;
    padding: 15px 20px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
}

.content-area {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    position: relative;
}

/* Sections */
.section {
    display: none;
    animation: fadeIn 0.4s ease;
    max-width: 1100px;
    margin: 0 auto;
}

.section.active {
    display: block;
}

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

.header-action {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.header-action h2 {
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.5px;
}

/* Tables */
.table-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    background: var(--bg-color);
    padding: 16px 20px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-color);
}

/* Badges */
.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    display: inline-block;
    text-transform: uppercase;
}

.status-connected { background: var(--success-bg); color: var(--success); }
.status-disconnected { background: var(--danger-bg); color: var(--danger); }
.status-warning { background: var(--warning-bg); color: var(--warning); }

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 30px;
    width: 450px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
    margin: 0;
    font-size: 20px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    width: auto;
    padding: 0;
}

.close-btn:hover { color: var(--text-main); }

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .mobile-header {
        display: flex;
    }
    .content-area {
        padding: 20px;
    }
    .header-action {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    .header-action button {
        width: 100%;
    }
    .table-container {
        overflow-x: auto;
    }
}

.overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
}
.overlay.active { display: block; }

/* AI Widget Support - Premium Light Theme */
body.auth-page #wahnotif-ai-widget {
    display: none !important;
}

#wahnotif-ai-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
}

#ai-widget-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #4c1d95); /* Wahnotif Logo Purple */
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(124, 58, 237, 0.4);
    transition: transform 0.3s;
    position: relative;
}

#ai-widget-button:hover {
    transform: scale(1.1) rotate(10deg);
}

#ai-widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid var(--bg-color);
}

#ai-widget-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
}

#ai-widget-window.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.ai-widget-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #7c3aed, #4c1d95); /* Wahnotif Logo Purple */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 20px;
}

.ai-widget-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--bg-color);
}

.ai-msg {
    display: flex;
    max-width: 85%;
}

.ai-msg.received {
    align-self: flex-start;
}

.ai-msg.sent {
    align-self: flex-end;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-msg.received .msg-bubble {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top-left-radius: 4px;
    color: var(--text-color);
    box-shadow: var(--shadow-sm);
}

.ai-msg.sent .msg-bubble {
    background: linear-gradient(135deg, #7c3aed, #4c1d95);
    border-top-right-radius: 4px;
    color: white;
}

.ai-widget-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: var(--card-bg);
}

#ai-widget-input {
    flex: 1;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 10px 15px;
    color: var(--text-color);
    outline: none;
    font-family: inherit;
    min-width: 0;
    font-size: 14px;
}

#ai-widget-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #4c1d95);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

#ai-widget-send:hover {
    background: var(--primary-hover);
}

@media (max-width: 480px) {
    #ai-widget-window {
        width: calc(100vw - 40px);
        right: -10px;
        bottom: 70px;
        height: 60vh;
    }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Custom Tooltip */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    opacity: 1;
}
[data-tooltip]::after {
    opacity: 0;
    transition: opacity 0.2s;
}

/* Live Inbox Mobile Responsiveness (PWA Native App Feel) */
@media (max-width: 768px) {
    .inbox-layout {
        gap: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        height: calc(100vh - 120px) !important;
        margin: -20px; /* Counteract parent padding to fill screen */
    }
    
    .inbox-sidebar {
        width: 100% !important;
        border-right: none !important;
    }

    .inbox-main {
        display: none !important; /* Hidden by default on mobile */
        position: absolute !important;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        background: #efeae2 !important;
    }

    /* When a chat is active on mobile */
    .inbox-layout.chat-active .inbox-sidebar {
        display: none !important;
    }

    .inbox-layout.chat-active .inbox-main {
        display: flex !important;
    }

    /* Show back button on mobile */
    .mobile-only-btn {
        display: block !important;
    }

    /* Make PWA feel native */
    .app-layout {
        height: 100vh;
        overflow: hidden; /* Prevent body scroll in PWA */
    }
    
    .main-content {
        height: calc(100vh - 60px) !important;
        overflow-y: auto;
    }

    /* Hide Wibi Widget when a chat is open to avoid blocking input */
    body:has(.inbox-layout.chat-active) #wahnotif-ai-widget {
        display: none !important;
    }

    #pwaInstallBanner {
        left: 15px !important;
        right: 15px !important;
        bottom: 15px !important;
        max-width: none !important;
        width: auto !important;
        box-sizing: border-box;
    }
}
