:root {
    --primary-color: #0078D4;
    --primary-hover: #005a9e;
    --bg-color: #f3f2f1;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #323130;
    --text-secondary: #605e5c;
    --border-color: #edebe9;
    --error-color: #a80000;
    --error-bg: #fde7e9;
    --success-color: #107c10;
    --success-bg: #dff6dd;
    --font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

body { margin: 0; font-family: var(--font-family); -webkit-font-smoothing: antialiased; color: var(--text-primary); }
* { box-sizing: border-box; }

.hidden { display: none !important; }

/* ================= LOGIN PAGE ================= */
.login-body {
    background: linear-gradient(135deg, #0078D4 0%, #002050 100%);
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; position: relative; overflow: hidden;
}

.login-body::before {
    content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 60%);
    animation: rotate 40s linear infinite; pointer-events: none;
}

@keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.login-container { width: 100%; max-width: 440px; position: relative; z-index: 1; }
.login-card { background: var(--card-bg); backdrop-filter: blur(12px); border-radius: 12px; padding: 50px 48px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4); text-align: center; animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideUp { 0% { opacity: 0; transform: translateY(30px); } 100% { opacity: 1; transform: translateY(0); } }

.logo-container, .auth-icon-container { margin-bottom: 24px; display: inline-flex; padding: 16px; background: white; border-radius: 50%; box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
.login-title { font-size: 28px; font-weight: 600; margin: 0 0 8px 0; color: var(--text-primary); }
.login-subtitle { font-size: 15px; color: var(--text-secondary); margin: 0 0 32px 0; }
.login-form { display: flex; flex-direction: column; gap: 20px; text-align: left; }
.input-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.input-group input { width: 100%; padding: 14px 16px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 15px; font-family: inherit; transition: all 0.2s ease; background: white; }
.input-group input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.2); }

.login-btn { background: var(--primary-color); color: white; border: none; border-radius: 6px; padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.2s, transform 0.1s; display: flex; justify-content: center; align-items: center; }
.login-btn:hover { background: var(--primary-hover); }
.login-btn:active { transform: scale(0.98); }
.back-btn { background: transparent; color: var(--text-secondary); border: none; font-size: 14px; font-weight: 600; cursor: pointer; padding: 8px; margin-top: -10px; }
.back-btn:hover { color: var(--text-primary); text-decoration: underline; }

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

.error-msg { margin-top: 16px; padding: 12px; background: var(--error-bg); color: var(--error-color); border-radius: 6px; font-size: 14px; font-weight: 600; animation: shake 0.4s; text-align: center; }
.success-msg { margin-bottom: 16px; padding: 12px; background: var(--success-bg); color: var(--success-color); border-radius: 6px; font-size: 14px; font-weight: 600; text-align: center; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.footer-text { position: absolute; bottom: 24px; color: rgba(255,255,255,0.7); font-size: 13px; text-align: center; width: 100%; }

/* MFA specific */
.qr-container { background: white; padding: 12px; border-radius: 8px; display: inline-block; border: 1px solid var(--border-color); margin-bottom: 16px; }
.qr-container img { width: 150px; height: 150px; }
.mfa-instructions { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; line-height: 1.5; }

/* ================= DASHBOARD PAGE ================= */
.dashboard-body { background: var(--bg-color); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.dashboard-header { background: white; box-shadow: 0 2px 10px rgba(0,0,0,0.06); position: relative; z-index: 10; }
.header-content { max-width: 1600px; margin: 0 auto; padding: 0 24px; height: 64px; display: flex; justify-content: space-between; align-items: center; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-title { font-size: 20px; font-weight: 600; margin: 0; color: #323130; }
.header-title span { color: var(--primary-color); }
.header-right { display: flex; align-items: center; gap: 16px; }
.user-info { display: flex; align-items: center; gap: 12px; margin-right: 12px; }
.user-avatar { width: 34px; height: 34px; background: #0078D4; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; box-shadow: 0 2px 6px rgba(0,120,212,0.3); }
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.action-btn { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); padding: 8px 16px; border-radius: 6px; font-size: 14px; cursor: pointer; font-weight: 600; transition: all 0.2s; }
.action-btn:hover { background: #f3f2f1; color: var(--text-primary); }
.logout-btn:hover { background: #fdf5f5; border-color: #f7d6d6; color: #d13438; }

.dashboard-main { flex: 1; padding: 24px; max-width: 1600px; margin: 0 auto; width: 100%; height: calc(100vh - 64px); display: flex; flex-direction: column; }
.report-wrapper { background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.06); flex: 1; border: 1px solid var(--border-color); overflow: hidden; position: relative; }
.report-container { width: 100%; height: 100%; border: none; }
iframe { border: none !important; }

.loading-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: white; gap: 16px; z-index: 5; }
.loading-state p { color: var(--text-primary); font-weight: 600; font-size: 18px; margin: 0; }
.loading-sub { color: var(--text-secondary); font-size: 14px; }
.spinner { width: 44px; height: 44px; border: 3.5px solid #f3f2f1; border-top-color: var(--primary-color); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 8px; }

/* Reset default link styling */
a { text-decoration: none; color: inherit; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: white; width: 100%; max-width: 400px; border-radius: 8px; padding: 32px; box-shadow: 0 20px 40px rgba(0,0,0,0.2); animation: slideUp 0.3s ease; }
.modal-card h3 { margin: 0 0 24px 0; font-size: 20px; color: var(--text-primary); }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; justify-content: flex-end; }
.cancel-btn { background: white; border: 1px solid var(--border-color); padding: 10px 16px; border-radius: 4px; font-weight: 600; cursor: pointer; color: var(--text-secondary); }
.cancel-btn:hover { background: #f3f2f1; }
.save-btn { background: var(--primary-color); border: none; color: white; padding: 10px 24px; border-radius: 4px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; min-width: 80px; }
.save-btn:hover { background: var(--primary-hover); }

/* ================= SELECTION VIEW ================= */
.selection-container { 
    max-width: 900px; margin: auto; text-align: center; padding-top: 40px;
    animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.selection-title { font-size: 32px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.selection-subtitle { font-size: 18px; color: var(--text-secondary); margin-bottom: 48px; }

.selection-grid { 
    display: grid; 
    grid-template-columns: repeat(2, 1fr); 
    gap: 32px; 
    width: 100%; 
}
@media (max-width: 768px) {
    .selection-grid { grid-template-columns: 1fr; }
}
.selection-card { 
    background: white; border-radius: 12px; padding: 40px; border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); cursor: pointer; transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.selection-card:hover { transform: translateY(-8px); box-shadow: 0 20px 40px rgba(0,0,0,0.1); border-color: var(--primary-color); }
.card-icon { background: #f3f2f1; padding: 24px; border-radius: 50%; color: var(--primary-color); margin-bottom: 8px; }
.selection-card h3 { margin: 0; font-size: 20px; font-weight: 600; }
.selection-card p { margin: 0; color: var(--text-secondary); font-size: 15px; line-height: 1.5; }
.card-btn { background: var(--primary-color); color: white; border: none; padding: 10px 24px; border-radius: 6px; font-weight: 600; margin-top: 16px; width: 100%; pointer-events: none; }

/* ================= VIEW SECTIONS ================= */
.view-section { height: 100%; display: flex; flex-direction: column; animation: fadeIn 0.4s ease; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; padding: 0 4px; }
.view-header h2 { font-size: 24px; font-weight: 700; margin: 0; }
.back-link-btn { background: transparent; border: none; color: var(--primary-color); font-weight: 600; cursor: pointer; font-size: 15px; padding: 0; margin-bottom: 8px; align-self: flex-start; display: flex; align-items: center; gap: 4px; opacity: 0.8; transition: opacity 0.2s; }
.back-link-btn:hover { opacity: 1; text-decoration: underline; }

/* ================= TICKETS SYSTEM ================= */
.tickets-container { background: white; border-radius: 12px; border: 1px solid var(--border-color); flex: 1; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.tickets-list-header { padding: 16px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: #faf9f8; }
.tickets-list-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.tickets-list { flex: 1; overflow-y: auto; }
.ticket-row { padding: 16px 24px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; cursor: pointer; transition: background 0.2s; }
.ticket-row:hover { background: #f3f2f1; }
.ticket-info h4 { margin: 0 0 4px 0; font-size: 15px; color: var(--text-primary); }
.ticket-meta { font-size: 13px; color: var(--text-secondary); display: flex; gap: 12px; }
.status-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-new { background: #eef2ff; color: #4f46e5; border: 1px solid #c7d2fe; }
.status-assigned { background: #f0f9ff; color: #0369a1; border: 1px solid #bae6fd; }
.status-in_progress { 
    background: #fffbeb; color: #b45309; border: 1px solid #fef3c7; 
    animation: pulse-yellow 2s infinite;
}
.status-pending { background: #fdf2f8; color: #be185d; border: 1px solid #fce7f3; }
.status-resolved { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.status-closed { background: #f8fafc; color: #64748b; border: 1px solid #e2e8f0; opacity: 0.8; }
.status-cancelled { background: #fff1f2; color: #e11d48; border: 1px solid #fecdd3; }

@keyframes pulse-yellow {
    0% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(217, 119, 6, 0); }
    100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0); }
}

.empty-state { padding: 80px; text-align: center; color: var(--text-secondary); font-size: 15px; }
.new-ticket-btn { background: var(--primary-color); color: white; border: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.new-ticket-btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 120, 212, 0.2); }

.ticket-modal { max-width: 800px; }
.ticket-modal textarea { width: 100%; padding: 12px; border: 1px solid var(--border-color); border-radius: 6px; font-family: inherit; font-size: 15px; resize: vertical; }
.ticket-modal select { width: 100%; padding: 12px; border: 1px solid var(--border-color); border-radius: 6px; background: #fff; cursor: default; -webkit-appearance: none; appearance: none; }

/* Form Enhancement Styles */
.form-section { background: #fdfdfd; padding: 15px; border-radius: 8px; border: 1px solid #edf2f7; margin-bottom: 15px; }
.form-section h4 { margin-top: 0; color: var(--primary-color); font-size: 0.95rem; margin-bottom: 12px; border-bottom: 2px solid #eee; padding-bottom: 5px; }
.section-title-alt { font-weight: 600; font-size: 0.9rem; margin-bottom: 10px; color: #4a5568; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.scrollable-form::-webkit-scrollbar { width: 6px; }
.scrollable-form::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 10px; }

.ticket-detail-card { max-width: 600px; width: 90%; max-height: 80vh; display: flex; flex-direction: column; padding: 0; border-radius: 12px; overflow: hidden; }
.detail-header { padding: 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: #faf9f8; }
.ticket-chat { flex: 1; overflow-y: auto; padding: 24px; background: #f8f8f8; display: flex; flex-direction: column; gap: 16px; min-height: 300px; }
.chat-msg { max-width: 85%; padding: 12px 16px; border-radius: 8px; font-size: 15px; line-height: 1.5; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.msg-customer { align-self: flex-end; background: var(--primary-color); color: white; border-bottom-right-radius: 2px; }
.msg-admin { align-self: flex-start; background: white; color: var(--text-primary); border-bottom-left-radius: 2px; }
.msg-time { font-size: 11px; margin-top: 4px; opacity: 0.7; display: block; text-align: right; }
.ticket-detail-card .modal-actions { padding: 16px 24px; border-top: 1px solid var(--border-color); background: white; margin-top: 0; }

.reply-box { padding: 20px; background: white; border-top: 1px solid var(--border-color); }
.reply-box textarea { 
    width: 100%; padding: 12px 16px; border: 1.5px solid var(--border-color); 
    border-radius: 8px; font-family: inherit; font-size: 15px; 
    resize: none; transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}
.reply-box textarea:focus { 
    outline: none; border-color: var(--primary-color); 
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1); 
}

.refresh-btn {
    background: #fff;
    color: var(--primary-color);
    border: 1.5px solid var(--primary-color);
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 10px rgba(0, 120, 212, 0.1);
}

.refresh-btn:hover {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 120, 212, 0.3);
    transform: translateY(-1px);
}

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

.refresh-btn:hover span.refresh-icon {
    animation: spin 0.8s infinite linear;
}

.refresh-icon {
    display: inline-block;
    transition: transform 0.4s ease;
}


/* ================= 2-STEP TICKET FLOW ================= */
.selection-card-mini {
    background: #fff; border: 2px solid #eee; border-radius: 12px; padding: 25px 15px;
    cursor: pointer; transition: all 0.2s ease; display: flex; flex-direction: column;
    align-items: center; gap: 10px; height: 100%;
}
.selection-card-mini:hover { border-color: var(--primary-color); background: #f0f7ff; transform: translateY(-3px); box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.selection-card-mini .icon-mini { font-size: 32px; margin-bottom: 5px; }
.selection-card-mini b { font-size: 16px; color: var(--text-primary); }
.selection-card-mini span { font-size: 12px; color: var(--text-secondary); line-height: 1.3; }

/* Full Screen Modal Style */
.full-modal {
    max-width: 100% !important; height: 100vh !important; border-radius: 0 !important;
    display: flex; flex-direction: column; padding: 0 !important; animation: fadeIn 0.3s ease !important;
}
.full-modal-header {
    background: var(--primary-color); color: white; padding: 20px 40px;
    display: flex; justify-content: space-between; align-items: center;
}
.close-full-btn { background: rgba(255,255,255,0.2); border: none; color: white; padding: 8px 20px; border-radius: 6px; font-weight: 700; cursor: pointer; transition: background 0.2s; }
.close-full-btn:hover { background: rgba(255,255,255,0.3); }

.full-modal .scrollable-form {
    flex: 1; padding: 0; overflow-y: auto; background: #fff;
    display: flex; flex-direction: column;
}
.modal-actions-top {
    display: flex; justify-content: flex-end; align-items: center;
    padding: 15px 40px; border-bottom: 1px solid #eee; background: #fafafa;
    position: sticky; top: 0; z-index: 5;
}
.form-body-wrapper {
    flex: 1; overflow-y: auto; padding: 30px 15%;
}
.form-section { background: #fff; padding: 12px 18px; border-radius: 8px; border: 1px solid #edf2f7; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.02); }
@media (max-width: 1000px) {
    .form-body-wrapper { padding: 20px; }
    .modal-actions-top { padding: 15px 20px; }
}
/* ================= LIVE CHAT SYSTEM ================= */
.live-chat-bubble {
    position: fixed; bottom: 30px; right: 30px;
    width: 60px; height: 60px; border-radius: 50%;
    background: var(--primary-color); color: white;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 32px rgba(0, 120, 212, 0.4);
    cursor: pointer; z-index: 2000; transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.live-chat-bubble:hover { transform: scale(1.1) rotate(5deg); }
.live-chat-bubble svg { width: 30px; height: 30px; }

.chat-badge {
    position: absolute; top: -5px; right: -5px;
    background: var(--error-color); color: white;
    width: 22px; height: 22px; border-radius: 50%;
    font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid white;
}

.chat-window {
    position: fixed; bottom: 100px; right: 30px;
    width: 380px; height: 550px; background: white;
    border-radius: 16px; box-shadow: 0 12px 48px rgba(0,0,0,0.25);
    z-index: 2001; display: flex; flex-direction: column; overflow: hidden;
    animation: slideUpIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}
@keyframes slideUpIn { from { opacity: 0; transform: translateY(40px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.chat-header {
    background: var(--primary-color); color: white;
    padding: 18px 24px; display: flex; justify-content: space-between; align-items: center;
}
.chat-header h4 { margin: 0; font-size: 16px; font-weight: 600; }
.chat-header .status-dot { 
    width: 8px; height: 8px; background: #4ecb71; border-radius: 50%; 
    display: inline-block; margin-right: 6px; box-shadow: 0 0 10px #4ecb71; 
}

.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    background: #f8f9fa; display: flex; flex-direction: column; gap: 12px;
}
.chat-pill {
    max-width: 80%; padding: 10px 14px; border-radius: 18px;
    font-size: 14px; line-height: 1.5; position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.chat-pill.cust {
    align-self: flex-end; background: var(--primary-color); color: white;
    border-bottom-right-radius: 4px;
}
.chat-pill.adm {
    align-self: flex-start; background: white; color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.chat-pill .time {
    font-size: 10px; margin-top: 4px; opacity: 0.7; display: block;
}

.chat-input-area {
    padding: 16px; border-top: 1px solid var(--border-color);
    display: flex; gap: 10px; background: white;
}
.chat-input-area input {
    flex: 1; border: 1.5px solid var(--border-color); border-radius: 20px;
    padding: 10px 16px; font-size: 14px; outline: none; transition: border-color 0.2s;
}
.chat-input-area input:focus { border-color: var(--primary-color); }
.chat-send-btn {
    width: 40px; height: 40px; background: var(--primary-color);
    color: white; border: none; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.2s;
}
.chat-send-btn:hover { background: var(--primary-hover); }

/* Admin specific chat layout */
.admin-chat-grid {
    display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 180px);
    background: white; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-color);
}
.chat-sessions-list {
    border-right: 1px solid var(--border-color); overflow-y: auto; background: #fafafa;
}
.session-item {
    padding: 16px; border-bottom: 1px solid var(--border-color); cursor: pointer;
    transition: background 0.2s; position: relative;
}
.session-item:hover { background: #f0f0f0; }
.session-item.active { background: #e0f0ff; border-left: 4px solid var(--primary-color); }
.session-item .name { font-weight: 700; font-size: 14px; display: block; margin-bottom: 2px; }
.session-item .last-msg { font-size: 12px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .unread {
    position: absolute; right: 16px; top: 16px;
    background: var(--primary-color); color: white;
    width: 18px; height: 18px; border-radius: 50%;
    font-size: 10px; display: flex; align-items: center; justify-content: center;
}
