/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
    --primary:       #4f46e5;
    --primary-dark:  #4338ca;
    --primary-light: #ede9fe;
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --border:        #e2e8f0;
    --text:          #1e293b;
    --text-muted:    #64748b;
    --danger:        #ef4444;
    --danger-dark:   #dc2626;
    --success:       #22c55e;
    --warning:       #f59e0b;
    --info:          #3b82f6;
    --sidebar-w:     260px;
    --topbar-h:      56px;
    --radius:        8px;
    --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:     0 4px 12px rgba(0,0,0,.10);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Shell ──────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
}
.btn-compose {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    font-weight: 500;
    margin-bottom: 16px;
    transition: background .15s;
    border: none; cursor: pointer; font-size: .9rem;
}
.btn-compose:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }

.sidebar-nav ul { list-style: none; }
.sidebar-nav ul li { margin-bottom: 2px; }
.sidebar-nav ul a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    transition: background .12s;
    position: relative;
}
.sidebar-nav ul a:hover { background: var(--bg); text-decoration: none; }
.sidebar-nav ul a.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.sidebar-nav .nav-divider { height: 1px; background: var(--border); margin: 10px 0; }

.badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: .7rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 20px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-info { flex: 1; min-width: 0; }
.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .85rem;
    flex-shrink: 0;
}
.user-detail { display: flex; flex-direction: column; min-width: 0; }
.user-name  { font-size: .85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: .75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout {
    color: var(--text-muted);
    padding: 6px;
    border-radius: 6px;
    transition: color .12s, background .12s;
    display: flex;
}
.btn-logout:hover { color: var(--danger); background: #fee2e2; text-decoration: none; }

/* ─── Main Content ───────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.topbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 14px;
    box-shadow: var(--shadow);
}
.page-title { font-size: 1rem; font-weight: 600; }
.btn-menu-toggle {
    display: none;
    border: none; background: none; cursor: pointer; color: var(--text); padding: 4px;
}
.content-area { padding: 24px; max-width: 1100px; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .12s, border-color .12s, color .12s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); color: #fff; }
.btn-sm        { padding: 5px 12px; font-size: .8rem; }
.btn-block     { width: 100%; justify-content: center; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label, .form-row .form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}
input[type=text], input[type=email], input[type=password], input[type=file],
textarea, select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
textarea { resize: vertical; min-height: 140px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type=checkbox] { width: auto; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; }
.checkbox-label input { width: auto; }
.field-hint { font-size: .78rem; color: var(--text-muted); margin-top: 5px; }
.required { color: var(--danger); }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: .9rem;
}
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* ─── Auth Page ──────────────────────────────────────────────────────────── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.auth-container { width: 100%; max-width: 420px; padding: 20px; }
.auth-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    box-shadow: var(--shadow-md);
}
.auth-logo {
    display: flex; flex-direction: column; align-items: center;
    margin-bottom: 24px; gap: 8px; color: var(--primary);
}
.auth-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.auth-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 24px; color: var(--text-muted); text-align: center; }
.input-password-wrap { position: relative; }
.input-password-wrap input { padding-right: 42px; }
.btn-toggle-password {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: var(--text-muted); display: flex;
}

/* ─── Email List ─────────────────────────────────────────────────────────── */
.email-list {
    width: 100%; border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.email-item {
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid var(--border);
}
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: #f8faff; }
.email-item.unread .col-from,
.email-item.unread .col-subject { font-weight: 600; }
.email-item td { padding: 12px 14px; font-size: .88rem; }
.col-star { width: 36px; text-align: center; }
.col-from { width: 200px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.col-subject { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-item.unread .col-subject { color: var(--text); }
.col-date { width: 110px; text-align: right; color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.col-status { width: 110px; }

.btn-star {
    background: none; border: none; cursor: pointer;
    font-size: 1.1rem; color: #cbd5e1; transition: color .1s;
}
.btn-star:hover, .btn-star.starred { color: var(--warning); }

.list-toolbar { margin-bottom: 12px; color: var(--text-muted); font-size: .85rem; }

/* ─── Email Detail ───────────────────────────────────────────────────────── */
.email-detail {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.email-detail-toolbar {
    display: flex; align-items: center; gap: 8px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.email-header-block { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.email-subject { font-size: 1.15rem; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.email-meta { display: flex; flex-direction: column; gap: 5px; }
.email-meta-row { display: flex; gap: 10px; font-size: .875rem; }
.email-meta-row .label { min-width: 70px; color: var(--text-muted); font-weight: 500; }
.email-body { padding: 24px; min-height: 200px; }
.email-iframe { width: 100%; min-height: 300px; border: none; display: block; }
.email-text { white-space: pre-wrap; font-family: inherit; font-size: .9rem; line-height: 1.7; color: var(--text); }

/* ─── Attachments ────────────────────────────────────────────────────────── */
.email-attachments {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.email-attachments h4 { font-size: .875rem; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); }
.attach-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.attach-card {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    max-width: 260px;
    min-width: 160px;
    transition: box-shadow .12s;
}
.attach-card:hover { box-shadow: var(--shadow-md); }
.attach-icon { flex-shrink: 0; color: var(--text-muted); }
.attach-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; }
.attach-info { flex: 1; min-width: 0; }
.attach-name { display: block; font-size: .82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-size { display: block; font-size: .75rem; color: var(--text-muted); }
.attach-download { color: var(--text-muted); flex-shrink: 0; display: flex; padding: 4px; border-radius: 4px; transition: color .1s, background .1s; }
.attach-download:hover { color: var(--primary); background: var(--primary-light); text-decoration: none; }

/* ─── Status Badges ──────────────────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 500;
}
.status-badge.received  { background: #e0f2fe; color: #0369a1; }
.status-badge.sent      { background: #fef9c3; color: #854d0e; }
.status-badge.delivered { background: #dcfce7; color: #166534; }
.status-badge.bounced   { background: #fee2e2; color: #991b1b; }
.status-badge.failed    { background: #fee2e2; color: #991b1b; }

/* ─── Compose ────────────────────────────────────────────────────────────── */
.compose-container {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 32px;
    max-width: 760px;
}
.compose-field { margin-bottom: 16px; }
.compose-field label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.compose-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 64px 20px;
    color: var(--text-muted);
}
.empty-state svg { margin: 0 auto 16px; opacity: .3; display: block; }
.empty-state p { font-size: 1rem; margin-bottom: 16px; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; gap: 10px;
    margin-top: 20px; justify-content: center;
    font-size: .875rem; color: var(--text-muted);
}

/* ─── Admin ──────────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    border-left: 3px solid var(--primary);
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-label { font-size: .85rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.stat-sub   { font-size: .78rem; color: var(--danger); margin-top: 3px; }

.admin-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}
.admin-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.admin-form .form-row { display: flex; gap: 16px; }
.admin-form .form-row .form-group { flex: 1; }

.admin-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.admin-table th {
    text-align: left; padding: 10px 14px;
    border-bottom: 2px solid var(--border);
    font-size: .8rem; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
}
.admin-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg); }
.admin-table .row-inactive td { opacity: .5; }
.admin-table .actions { display: flex; gap: 6px; align-items: center; }

.role-badge {
    display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .75rem; font-weight: 500;
}
.role-badge.admin { background: var(--primary-light); color: var(--primary); }
.role-badge.user  { background: var(--bg); color: var(--text-muted); }

.text-muted { color: var(--text-muted); }

/* ─── Mobile Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }
    .main-content { margin-left: 0; }
    .btn-menu-toggle { display: flex; }
    .topbar { padding: 0 16px; }
    .content-area { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .compose-container { padding: 20px 16px; }
    .col-from { max-width: 120px; }
    .admin-form .form-row { flex-direction: column; }

    /* Overlay saat sidebar terbuka */
    .sidebar.open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.3);
        z-index: -1;
    }
}

/* ─── Inbox Toast Notification ───────────────────────────────────────────── */
.inbox-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 14px 16px;
    min-width: 280px;
    max-width: 360px;
    animation: toastSlideIn .3s ease;
}
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(110%); }
    to   { opacity: 1; transform: translateX(0); }
}
.toast-icon {
    font-size: 1.3rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 1px;
}
.toast-body    { flex: 1; min-width: 0; }
.toast-title   { font-size: .875rem; font-weight: 600; color: var(--text); }
.toast-detail  { font-size: .8rem; color: var(--text-muted); margin-top: 3px;
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-close   { background: none; border: none; cursor: pointer; color: var(--text-muted);
                  font-size: 1.2rem; line-height: 1; padding: 0 2px; flex-shrink: 0;
                  transition: color .1s; }
.toast-close:hover { color: var(--text); }

/* ─── Animasi baris email baru ───────────────────────────────────────────── */
@keyframes newEmailFlash {
    0%   { background: #ede9fe; }
    60%  { background: #ede9fe; }
    100% { background: transparent; }
}
.new-email-flash {
    animation: newEmailFlash 3s ease forwards;
}
