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

:root {
    /* Teal & Emerald Palette (Fresh & Professional) */
    --primary: #042f2e;        /* Teal 950 */
    --primary-light: #134e4a;  /* Teal 900 */
    --accent: #10b981;         /* Emerald 500 */
    --accent-hover: #059669;   /* Emerald 600 */
    --accent-light: #d1fae5;   /* Emerald 100 */
    --bg-color: #f0fdf4;       /* Green 50 */
    --surface: #ffffff;
    --text-main: #1e293b;      /* Slate 800 */
    --text-muted: #475569;     /* Slate 600 */
    --border: #ccfbf1;         /* Teal 100 */
    --success: #10b981;        /* Emerald 500 */
    --warning: #f59e0b;        /* Amber 500 */
    --danger: #ef4444;         /* Red 500 */
    
    /* UX Variables */
    --radius: 16px;
    --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);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Maven Pro', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

*:not(.loader-spinner):not(.chat-bubble):not(.chat-bubble-wrap.me .chat-bubble):not(.chat-bubble-wrap.other .chat-bubble):not(.badge-dot):not(.notif-dot):not(.contact-avatar):not(.bubble-avatar):not(.notif-sheet):not(.notif-spinner):not(.swal2-popup):not(.swal2-confirm):not(.swal2-cancel) {
    border-radius: 0 !important;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    line-height: 1.5;
}

/* Mobile First Container */
.app-container {
    width: 100%;
    max-width: 480px; /* Android App Width */
    min-height: 100vh;
    background-color: var(--bg-color);
    box-shadow: 0 0 40px rgba(15, 23, 42, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Glassmorphism Header */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--primary);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(16, 185, 129, 0.2); /* Emerald tint border */
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.icon-btn {
    color: var(--text-muted);
    transition: var(--transition);
}
.icon-btn:hover { color: var(--primary); transform: scale(1.05); }

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 20px;
    padding-bottom: 90px; /* Space for bottom nav */
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Cards (Modern & Breathable) */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card:active {
    transform: scale(0.99);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Bottom Navigation (Glassmorphism) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    max-width: 480px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-around;
    padding: 12px 0 16px 0; /* Extra padding for iOS home bar */
    box-shadow: 0 -4px 20px rgba(4, 47, 46, 0.05); /* Teal shadow */
    z-index: 100;
    border-top: 1px solid rgba(16, 185, 129, 0.2); /* Emerald tint border */
    border-radius: 20px 20px 0 0;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    gap: 6px;
    transition: var(--transition);
    position: relative;
    width: 60px;
}

.nav-item .lucide {
    width: 22px;
    height: 22px;
    transition: var(--transition);
}

.nav-item.active {
    color: var(--accent);
}
.nav-item.active .lucide {
    stroke-width: 2.5px;
    transform: translateY(-2px);
}

/* Floating Labels Form UX */
.form-group {
    position: relative;
    margin-bottom: 20px;
}

.form-floating {
    position: relative;
}

.form-floating .form-control {
    width: 100%;
    padding: 24px 16px 8px 16px;
    border: none;
    border-radius: 16px;
    font-size: 15px;
    background: #f1f5f9;
    transition: var(--transition);
    color: var(--primary);
    font-weight: 500;
    -webkit-appearance: none;
}

.form-floating .form-control:focus {
    outline: none;
    background: #e2e8f0;
    box-shadow: inset 0 0 0 2px var(--accent-light);
}

.form-floating label {
    position: absolute;
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    font-size: 15px;
    color: var(--text-muted);
    pointer-events: none;
    transition: var(--transition);
    background: transparent;
}

.form-floating .form-control:focus ~ label,
.form-floating .form-control:not(:placeholder-shown) ~ label {
    top: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
}

/* Standard Input (Mobile Native Feel) */
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
    padding-left: 4px;
}

.form-control-standard, .form-control:not(.form-floating .form-control) {
    width: 100%;
    padding: 16px 18px;
    border: none;
    border-radius: 16px;
    font-size: 15px;
    background: #f1f5f9; /* Slate 100 */
    color: var(--primary);
    transition: var(--transition);
    -webkit-appearance: none;
}

.form-control-standard:focus, .form-control:not(.form-floating .form-control):focus {
    outline: none;
    background: #e2e8f0; /* Slate 200 */
    box-shadow: inset 0 0 0 2px var(--accent-light);
}

textarea.form-control-standard, textarea.form-control { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
    background: var(--accent-hover);
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 2px solid var(--accent);
}

/* Timeline/Notifications */
.notification-banner {
    background: var(--accent-light);
    color: var(--accent-hover);
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    line-height: 1.4;
}

.notification-banner .lucide {
    flex-shrink: 0;
    margin-top: 2px;
}

.notification-banner.alert {
    background: #fef3c7;
    color: #b45309;
}

.notification-banner.danger {
    background: #fee2e2;
    color: #b91c1c;
}

.notification-banner.success {
    background: #d1fae5;
    color: #047857;
}

/* Utils */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    display: inline-block;
    line-height: 1.2;
    text-align: center;
}
.bg-primary { background: var(--primary); color: white; }
.bg-accent { background: var(--accent); color: white; }
.bg-success { background: var(--success); color: white; }
.bg-warning { background: var(--warning); color: white; }

/* Dashboard Grids */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-box h2 { font-size: 24px; color: var(--primary); margin-bottom: 4px; }
.stat-box small { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase;}

/* PAGE LOADER */
#page-loader {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: #f8fafc;
    z-index: 99999;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease;
}
.loader-spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* SWAL OVERRIDES FOR AESTHETICS */
.swal2-popup {
    border-radius: 20px !important;
    padding: 1.5rem !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1) !important;
}
.swal2-title { font-size: 20px !important; color: var(--text-main) !important; }
.swal2-confirm, .swal2-cancel { border-radius: 12px !important; font-weight: 600 !important; }

/* MODAL / BOTTOM SHEET UX */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: flex-end; /* Mobile Bottom Sheet Feel */
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-color);
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

@media (min-width: 500px) {
    .modal-overlay { align-items: center; }
    .modal-content { border-radius: 20px; transform: scale(0.95); opacity: 0; }
    .modal-overlay.active .modal-content { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-color);
    z-index: 10;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-content form {
    padding: 20px 24px 24px 24px;
}
.modal-header h3 { margin: 0; font-size: 18px; color: var(--text-main); }
.modal-close {
    background: #f1f5f9;
    border: none;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.modal-close:active { transform: scale(0.9); }

/* ─── ICON BADGE (notif & chat) ──────────────────────────────────────────── */
.icon-btn-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.badge-dot {
    position: absolute;
    top: -5px;
    right: -6px;
    background: var(--danger);
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 20px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
    border: 2px solid white;
    animation: pop-in 0.2s cubic-bezier(0.175,0.885,0.32,1.5);
}
@keyframes pop-in { from { transform: scale(0); } to { transform: scale(1); } }

/* nav-item badge */
.nav-item .badge-dot { top: -4px; right: 10px; }

/* ─── NOTIFICATION PANEL (slide-down) ────────────────────────────────────── */
#notif-panel {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 64px;
}
#notif-panel.active { opacity: 1; visibility: visible; }

.notif-sheet {
    background: var(--surface);
    width: 100%;
    max-width: 480px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    transform: translateY(-20px);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.175,0.885,0.32,1), opacity 0.25s;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
#notif-panel.active .notif-sheet { transform: translateY(0); opacity: 1; }

.notif-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.notif-sheet-header h3 { font-size: 16px; font-weight: 700; color: var(--primary); }
.notif-sheet-header .notif-actions { display: flex; align-items: center; gap: 12px; }
#notif-read-all {
    font-size: 12px; font-weight: 600; color: var(--accent);
    background: none; border: none; cursor: pointer; padding: 0;
}
#notif-read-all:hover { text-decoration: underline; }

#notif-list { overflow-y: auto; flex: 1; }

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    background: var(--surface);
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--accent-light); }
.notif-item:hover { background: var(--bg-color); }
.notif-dot {
    width: 8px; height: 8px; border-radius: 50% !important;
    background: var(--accent); flex-shrink: 0; margin-top: 5px;
}
.notif-body { flex: 1; }
.notif-title { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.notif-msg { font-size: 12px; color: var(--text-muted); line-height: 1.4; margin-bottom: 4px; }
.notif-time { font-size: 11px; color: var(--text-muted); font-weight: 600; }

.notif-loading, .notif-empty {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px 20px; gap: 12px;
    color: var(--text-muted); font-size: 13px;
}
.notif-empty .lucide { width: 36px; height: 36px; opacity: 0.4; }
.notif-spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50% !important;
    animation: spin 0.8s linear infinite;
}

/* ─── CHAT PAGE ───────────────────────────────────────────────────────────── */
.contact-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    background: var(--surface);
}
.contact-item:hover { background: var(--bg-color); }

.contact-avatar {
    width: 46px; height: 46px; border-radius: 50% !important;
    background: var(--primary-light);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}
.contact-avatar img { width: 100%; height: 100%; object-fit: cover; }

.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-size: 14px; font-weight: 700; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.contact-role-badge {
    font-size: 10px; font-weight: 700; padding: 2px 7px;
    background: var(--accent-light); color: var(--accent);
    border-radius: 20px; white-space: nowrap;
}

/* Chat window — stays within the 480px app-container bounds */
.chat-window {
    display: flex;
    flex-direction: column;
    /* Use dvh so virtual keyboard shrinks the window, not covers input */
    height: 100dvh;
    height: 100vh; /* fallback */
    position: fixed;
    top: 0;
    /* Align to the app-container: centered, max 480px */
    left: 50%;
    transform: translateX(calc(-50% + 50vw));
    width: 100%;
    max-width: 480px;
    background: var(--bg-color);
    z-index: 500;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    will-change: transform;
}
/* Hidden state: slide out to the right */
.chat-window:not(.open) {
    transform: translateX(calc(-50% + 50vw + 100%));
    pointer-events: none;
}
.chat-window.open {
    transform: translateX(-50%);
}

.chat-header {
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex; align-items: center; gap: 12px;
    flex-shrink: 0;
    position: sticky; top: 0; z-index: 10;
}
.chat-back-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 4px;
    display: flex; align-items: center;
    transition: color 0.2s;
}
.chat-back-btn:hover { color: var(--primary); }

.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 16px 16px 0;
    display: flex; flex-direction: column; gap: 8px;
    scroll-behavior: smooth;
}

.chat-bubble-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: bubble-in 0.2s ease;
}
@keyframes bubble-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.chat-bubble-wrap.me { flex-direction: row-reverse; }

.bubble-avatar {
    width: 28px; height: 28px; border-radius: 50% !important;
    background: var(--primary-light); color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
    overflow: hidden;
}
.bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-bubble {
    max-width: 72%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    /* Force border-radius on chat bubbles — overrides global reset */
    border-radius: 18px 18px 4px 18px !important;
}
.chat-bubble-wrap.me .chat-bubble {
    background: var(--accent);
    color: white;
    border-radius: 18px 18px 4px 18px !important;
}
.chat-bubble-wrap.other .chat-bubble {
    background: var(--surface);
    color: var(--text-main);
    border-radius: 18px 18px 18px 4px !important;
    border: 1px solid var(--border);
}
.bubble-time {
    font-size: 10px; color: var(--text-muted);
    margin-top: 3px;
    text-align: right;
}
.chat-bubble-wrap.me .bubble-time { text-align: right; }

/* Typing indicator */
.chat-typing {
    display: none;
    padding: 4px 16px 8px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.chat-input-bar {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    display: flex; align-items: flex-end; gap: 10px;
    flex-shrink: 0;
}
#chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border);
    font-size: 14px;
    color: var(--primary);
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
    font-family: 'Maven Pro', sans-serif;
}
#chat-input:focus { outline: none; border-color: var(--accent); }

#chat-send-btn {
    width: 44px; height: 44px; flex-shrink: 0;
    background: var(--accent); color: white;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, transform 0.1s;
}
#chat-send-btn:hover { background: var(--accent-hover); }
#chat-send-btn:active { transform: scale(0.92); }
#chat-send-btn:disabled { background: var(--border); cursor: not-allowed; }

.chat-date-divider {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 0;
    position: relative;
}
.chat-date-divider::before, .chat-date-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--border);
}
.chat-date-divider::before { left: 0; }
.chat-date-divider::after { right: 0; }
