@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root { --bg: #F8F9FA; --card-bg: #FFFFFF; --text: #111827; --text-muted: #6B7280; --primary: #4F46E5; --primary-hover: #4338CA; --input-bg: #F3F4F6; --border: #E5E7EB; --radius: 16px; --mail-color: #4F46E5; }
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }
html, body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow-x: hidden; height: 100%; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;}
.dash-body { padding: 40px 5%; max-width: 1200px; margin: 0 auto; }
.mail-body { height: 100vh; height: 100dvh; overflow: hidden; background: white;}

.login-container { background: var(--card-bg); padding: 40px; border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.02); width: 100%; max-width: 420px; text-align: center; border: 1px solid var(--border); }
.logo-icon { width: 56px; height: 56px; background: var(--primary); color: white; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; margin: 0 auto 20px; }
h1 { font-size: 24px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.02em;}
.subtitle { color: var(--text-muted); font-size: 15px; font-weight: 500; margin-bottom: 32px;}
.slider-wrapper { width: 100%; overflow: hidden; }
.form-slider { display: flex; width: 200%; transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.step { width: 50%; flex-shrink: 0; padding: 0 4px; }

input.std-input, textarea.std-input { width: 100%; padding: 14px 16px; margin-bottom: 16px; border: 1.5px solid var(--border); border-radius: 12px; font-size: 15px; font-weight: 500; background: var(--card-bg); outline: none; transition: all 0.2s; color: var(--text); }
input.std-input:focus, textarea.std-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1); }
input[type="file"] { padding: 10px; font-size: 14px; background: var(--input-bg); border: 1px dashed var(--border);}
button { width: 100%; padding: 14px 20px; background: var(--primary); color: white; border: none; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px;}
button:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { width: 100%; padding: 14px 20px; background: var(--primary); color: white; border: none; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px;}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: var(--input-bg); color: var(--text); padding: 14px 20px; border-radius: 12px; font-size: 15px; font-weight: 600; border: none; cursor: pointer;}
.btn-secondary:hover { background: #E5E7EB; }
.btn-danger { background: #FEE2E2; color: #EF4444; padding: 14px 20px; border-radius: 12px; font-size: 15px; font-weight: 600; border: none; cursor: pointer;}
.btn-danger:hover { background: #FECACA; }

.user-badge { background: var(--input-bg); padding: 12px 16px; border-radius: 12px; display: inline-flex; justify-content: space-between; align-items: center; width: 100%; cursor: pointer; font-size: 15px; font-weight: 600; margin-bottom: 24px;}
.user-badge small { color: var(--primary); font-weight: 600; font-size: 13px; }
.error-msg { color: #EF4444; font-size: 14px; font-weight: 500; margin-top: 12px; display: none; }

.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px; }
.dash-header h2 { font-weight: 700; font-size: 28px; letter-spacing: -0.02em; margin:0;}
.header-actions { display: flex; gap: 12px; }
.btn-icon { width: 44px; height: 44px; padding: 0; font-size: 24px; border-radius: 50%; border:none; background:white; cursor:pointer;}
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
.card { background: var(--card-bg); padding: 24px; border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.03); cursor: pointer; transition: all 0.3s; border: 1px solid var(--border); border-left: 6px solid var(--primary); position: relative;}
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(0,0,0,0.06); border-color: transparent;}
.card h3 { font-size: 18px; margin-bottom: 4px; font-weight: 600;}
.card p { color: var(--text-muted); font-size: 14px;}
.badge-count { background: #EF4444; color: white; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; }

.modal { display: none; position: fixed; inset: 0; background: rgba(17, 24, 39, 0.4); align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); padding: 20px; }
.modal-content { background: var(--card-bg); padding: 32px; border-radius: 24px; width: 100%; max-width: 480px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); max-height: 90vh; overflow-y: auto;}
.modal-content h3 { margin-bottom: 8px; font-size: 22px;}
.row { display: flex; gap: 16px; width:100%;}
.modal-actions { display: flex; gap: 12px; margin-top: 16px; }
.input-group { margin-bottom: 16px; text-align: left; width:100%;}
.input-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px;}

.mail-layout { display: flex; height: 100vh; height: 100dvh; background: var(--card-bg); }
.sidebar { width: 260px; background: var(--bg); padding: 24px; border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index:2;}
.sidebar .brand { font-weight: 600; font-size: 15px; color: var(--text); cursor: pointer; margin-bottom: 32px;}
.compose-btn { margin-bottom: 32px; border-radius: 12px; background: var(--mail-color); font-weight: 600; z-index:100; position:relative;}
.mail-nav a { display: flex; justify-content: space-between; padding: 12px 16px; color: var(--text-muted); text-decoration: none; border-radius: 10px; margin-bottom: 8px; font-weight: 500;}
.mail-nav a.active { background: #E5E7EB; color: var(--text); font-weight: 600;}

.mail-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--card-bg); position:relative;}
.mail-header { padding: 20px 32px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.mail-header h2 { font-size: 20px; margin: 0; font-weight: 600;}
.mail-list { overflow-y: auto; flex: 1; }

.mail-item { display: flex; padding: 12px 32px; border-bottom: 1px solid var(--border); align-items: center; gap: 16px; cursor: pointer;}
.mail-item:nth-child(even) { background-color: var(--bg); }
.mail-item:nth-child(odd) { background-color: #FFFFFF; }
.mail-item:hover { background-color: #Eef2ff; }

/* UNREAD LOGIC */
.mail-item.unread { font-weight: 600; position: relative;}
.mail-item.unread:nth-child(even) { background-color: #F3F4F6; }
.mail-item.unread::before { content: ''; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 8px; height: 8px; background: var(--primary); border-radius: 50%; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--mail-color); color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; text-transform: uppercase;}
.sender { width: 180px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);}
.subject { flex: 1; color: var(--text-muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.mail-item.unread .subject { color: var(--primary); font-weight: 700;}
.mail-item.unread .sender { color: var(--primary); font-weight: 700;}
.time { font-size: 12px; color: var(--text-muted); white-space: nowrap;}

.skeleton-row { display: flex; padding: 12px 32px; gap: 16px; border-bottom: 1px solid var(--border); align-items: center;}
.sk-avatar { width: 36px; height: 36px; border-radius: 50%; background: #eee; animation: pulse 1.5s infinite; }
.sk-text { height: 12px; background: #eee; border-radius: 6px; animation: pulse 1.5s infinite;}
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 0.3; } 100% { opacity: 0.6; } }

/* BIG COMPOSE WINDOW - Desktop */
.compose-window { position: fixed; bottom: 24px; right: 24px; width: 600px; height: 600px; background: white; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); border: 1px solid var(--border); z-index: 9999; display: none; flex-direction: column; overflow: hidden;}
.compose-header { background: var(--bg); padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border);}
.compose-header h3 { font-size: 16px; font-weight: 600; margin: 0;}

.btn-close { width: 36px !important; height: 36px !important; padding: 0 !important; background: transparent !important; color: var(--text-muted) !important; font-size: 20px !important; border-radius: 8px !important; border: none !important; margin: 0 !important; display: flex !important; align-items: center; justify-content: center;}
.btn-close:hover { background: #E5E7EB !important; color: var(--text) !important;}

.compose-body { display: flex; flex-direction: column; flex: 1; overflow-y:auto; background:white;}
.compose-body input { padding: 16px 20px; border: none; border-bottom: 1px solid var(--border); border-radius: 0; margin: 0; font-size: 15px; width:100%;}
.compose-body input:focus { box-shadow: none; border-bottom-color: var(--primary);}

/* Quill Container overrides */
#editor-container { flex: 1; border: none !important; font-size: 15px; font-family: 'Inter', sans-serif; display: flex; flex-direction: column;}
.ql-toolbar { border: none !important; border-bottom: 1px solid var(--border) !important; padding: 8px 16px !important; background: #F9FAFB;}
.ql-container { flex: 1; overflow-y: auto; font-family: 'Inter', sans-serif; font-size: 15px; }
.ql-editor { min-height: 150px; }

.compose-footer { padding: 16px 20px; display: flex; align-items: center; gap: 16px; border-top: 1px solid var(--border); background: white;}
.compose-footer .btn-primary { width: auto; padding: 12px 32px; border-radius: 100px; font-size: 15px; margin:0;}
.attach-btn { cursor: pointer; color: var(--text-muted); font-size: 20px; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.2s;}
.attach-btn:hover { background: var(--bg); color: var(--text);}

/* READ VIEW */
.read-view { position: absolute; inset: 0; background: white; z-index: 10; display: none; flex-direction: column; overflow-y: auto;}
.read-header { padding: 16px 32px; border-bottom: 1px solid var(--border); background: var(--bg); display: flex; align-items: center; position: sticky; top: 0; z-index: 11;}
.read-content { padding: 32px; font-size: 15px; line-height: 1.6; max-width: 800px; margin: 0 auto; width: 100%;}
.read-content img { max-width: 100%; height: auto;}

/* MOBILE RESPONSIVE FIX COMPLET */
@media (max-width: 768px) {
    .mail-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; flex-direction: row; padding: 12px 16px; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; align-items: center;}
    
    .compose-window { 
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important; 
        height: 100dvh !important; 
        max-height: 100dvh !important;
        border-radius: 0 !important; 
        border: none !important;
        position: fixed !important;
        margin: 0 !important;
        flex-direction: column;
    }
    
    .compose-header { padding-top: max(16px, env(safe-area-inset-top)) !important; }
    .compose-footer { padding-bottom: max(16px, env(safe-area-inset-bottom)) !important; }
    
    .compose-body { flex: 1 1 auto !important; min-height: 0 !important; overflow-y: auto !important; display: flex; flex-direction: column;}
    
    .mail-item { padding: 12px 16px; }
    .sender { width: 120px; }
    .mail-header { flex-direction: column; align-items:flex-start; gap: 16px;}
    .search-bar input { width: 100% !important; }
    
    .read-header { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
    .read-header > div { display: flex; width: 100%; justify-content: space-between;}
}