/* ===== Modern Webmail Design System ===== */

:root {
    --primary: var(--brand-primary, #2563EB);
    --primary-rgb: 37, 99, 235;
    --accent: var(--brand-accent, #8B5CF6);
    --accent-rgb: 139, 92, 246;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --surface-hover: #F1F5F9;
    --border: #E2E8F0;
    --text: #1E293B;
    --text-muted: #64748B;
    --text-light: #94A3B8;
    --danger: #EF4444;
    --success: #22C55E;
    --warning: #F59E0B;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.1), 0 3px 10px rgba(0,0,0,.05);
    --transition: .2s ease;
    --sidebar-w: 260px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { margin:0; padding:0; box-sizing:border-box; }
*::before, *::after { box-sizing:border-box; }

html { font-size:14px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { opacity: 0.85; }
img { max-width: 100%; height: auto; }

/* ===== Flash Messages ===== */
.flash {
    padding: 12px 20px; border-radius: var(--radius-sm); margin: 16px 24px;
    font-size: 13px; font-weight: 500; display:flex; align-items:center; gap:8px;
    animation: slideDown .3s ease;
}
.flash-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }
.flash-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.flash-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }
@keyframes slideDown { from { opacity:0; transform: translateY(-10px); } to { opacity:1; transform: translateY(0); } }

/* ===== Login Page ===== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    padding: 20px;
}
.login-card {
    background: var(--surface); border-radius: 20px; padding: 48px 40px;
    width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
    animation: fadeIn .4s ease;
}
@keyframes fadeIn { from { opacity:0; transform: scale(.96); } to { opacity:1; transform: scale(1); } }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img { max-height: 48px; }
.login-logo .logo-text { font-size: 24px; font-weight: 800; color: var(--primary); }
.login-card h1 { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control {
    width: 100%; padding: 12px 16px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; font-family: var(--font); background: var(--surface); color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15); }
.form-control::placeholder { color: var(--text-light); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.form-check label { font-size: 13px; color: var(--text-muted); cursor: pointer; }
.login-error {
    background: #FEE2E2; color: #991B1B; padding: 10px 16px; border-radius: var(--radius-sm);
    font-size: 13px; margin-bottom: 20px; border: 1px solid #FCA5A5;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; font-family: var(--font);
    cursor: pointer; transition: all var(--transition); text-decoration: none;
    white-space: nowrap; line-height: 1.4;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary); color: #fff; opacity: 0.88; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 8px 12px; }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }

/* ===== App Layout ===== */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w); 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 var(--transition);
}
.sidebar-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.sidebar-header img { max-height: 36px; }
.sidebar-header .logo-text { font-size: 18px; font-weight: 800; color: var(--primary); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.nav-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-light); padding: 12px 12px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 13px; font-weight: 500; transition: all var(--transition);
    margin-bottom: 2px; text-decoration: none;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: rgba(var(--primary-rgb), 0.12); color: var(--primary); font-weight: 600; }
.nav-item .icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item .badge {
    margin-left: auto; background: var(--primary); color: #fff; font-size: 11px;
    font-weight: 700; padding: 2px 8px; border-radius: 20px; min-width: 20px; text-align: center;
}
.sidebar-footer { padding: 16px 12px; border-top: 1px solid var(--border); }

/* Main Content */
.main-content {
    flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh;
}

/* Topbar */
.topbar {
    height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50;
}
.topbar .mobile-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); }
.topbar-search { flex: 1; max-width: 400px; position: relative; }
.topbar-search input {
    width: 100%; padding: 9px 16px 9px 40px; border: 1px solid var(--border); border-radius: 20px;
    font-size: 13px; background: var(--bg); transition: all var(--transition);
}
.topbar-search input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15); }
.topbar-search .search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-light); font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.topbar .user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 12px; border-radius: var(--radius-sm); transition: background var(--transition); }
.topbar .user-menu:hover { background: var(--surface-hover); }
.topbar .user-menu .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: rgba(var(--primary-rgb), 0.12); }
.topbar .user-menu .user-name { font-size: 13px; font-weight: 600; }
.topbar .user-menu .user-role { font-size: 11px; color: var(--text-muted); }

/* Content Area */
.content-area { flex: 1; padding: 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-header .actions { display: flex; gap: 10px; }

/* ===== Mail List ===== */
.mail-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.mail-item {
    display: flex; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border);
    transition: background var(--transition); cursor: pointer; gap: 16px; text-decoration: none; color: var(--text-muted);
}
.mail-item:hover { background: var(--surface-hover); text-decoration: none; color: var(--text-muted); }
.mail-item:last-child { border-bottom: none; }
.mail-item.unread { font-weight: 600; }
.mail-item.unread .mail-from { color: var(--text); }
.mail-item .mail-from { width: 200px; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-item .mail-subject { flex: 1; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-item.unread .mail-subject { color: var(--text); }
.mail-item .mail-date { font-size: 12px; color: var(--text-light); white-space: nowrap; }
.mail-item .unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.mail-item .attach-icon { color: var(--text-light); font-size: 14px; }
.mail-empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.mail-empty .icon { font-size: 48px; margin-bottom: 16px; }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }
.pagination a, .pagination span {
    padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
    border: 1px solid var(--border); background: var(--surface); transition: all var(--transition);
    text-decoration: none; color: var(--text);
}
.pagination a:hover { background: var(--surface-hover); text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Message View ===== */
.message-view { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.message-toolbar { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.message-header { padding: 20px; border-bottom: 1px solid var(--border); }
.message-header .from { font-size: 15px; font-weight: 600; }
.message-header .from-email { color: var(--text-muted); font-weight: 400; }
.message-header .meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.message-header .subject { font-size: 18px; font-weight: 700; margin-top: 12px; }
.message-body { padding: 24px; font-size: 14px; line-height: 1.7; }
.message-body img { max-width: 100%; border-radius: var(--radius-sm); }
.message-attachments { padding: 16px 20px; border-top: 1px solid var(--border); }
.message-attachments h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; }
.attachment-item {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 13px; margin-right: 8px; margin-bottom: 8px;
    transition: all var(--transition); text-decoration: none; color: var(--text);
}
.attachment-item:hover { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.08); text-decoration: none; }

/* ===== Compose ===== */
.compose-view { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* ===== Admin Dashboard ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 28px; }
.stat-card {
    background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 16px; }
.stat-card .stat-icon.blue { background: #DBEAFE; color: #2563EB; }
.stat-card .stat-icon.green { background: #DCFCE7; color: #16A34A; }
.stat-card .stat-icon.purple { background: #EDE9FE; color: #7C3AED; }
.stat-card .stat-icon.orange { background: #FFEDD5; color: #EA580C; }
.stat-card .stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.stat-card .stat-number { font-size: 32px; font-weight: 800; margin-top: 4px; }

/* ===== Data Tables ===== */
.data-table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 14px 20px; text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-muted); border-bottom: 2px solid var(--border); background: var(--bg);
}
.data-table td { padding: 14px 20px; font-size: 13px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-hover); }
.data-table .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #DCFCE7; color: #166534; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-purple { background: #EDE9FE; color: #6D28D9; }

/* ===== Cards ===== */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

/* ===== Profile/Settings ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 3px solid var(--border); }

/* ===== Superadmin ===== */
.tenant-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
    display: flex; align-items: center; gap: 16px; transition: all var(--transition);
}
.tenant-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.tenant-card .tenant-logo { width: 48px; height: 48px; border-radius: 12px; object-fit: contain; background: var(--bg); }
.tenant-card .tenant-info { flex: 1; }
.tenant-card .tenant-name { font-size: 15px; font-weight: 700; }
.tenant-card .tenant-domain { font-size: 12px; color: var(--text-muted); }
.tenant-card .tenant-stats { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.color-preview { width: 24px; height: 24px; border-radius: 6px; display: inline-block; border: 2px solid var(--border); vertical-align: middle; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar .mobile-toggle { display: block; }
    .form-row { flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .content-area { padding: 16px; }
    .mail-item .mail-from { width: 120px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-header .actions { width: 100%; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; }
    .topbar-search { display: none; }
}
