/* ===== Variables ===== */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --light: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --text: #334155;
    --text-light: #94a3b8;
    --sidebar-width: 260px;
    --header-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--light); color: var(--text); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }
ul { list-style: none; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-header .logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}
.sidebar-header h1 { font-size: 18px; font-weight: 600; }

.sidebar-nav { padding: 16px 0; }
.sidebar-nav .nav-section {
    padding: 8px 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-light);
    margin-top: 8px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #cbd5e1;
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,0.08);
    color: var(--white);
    border-left-color: var(--primary);
}
.sidebar-nav a .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-nav a .badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

/* Header */
.top-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.top-header .search-bar {
    display: flex;
    align-items: center;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 12px;
    width: 400px;
    max-width: 50%;
}
.top-header .search-bar input {
    border: none;
    background: transparent;
    padding: 8px;
    width: 100%;
    font-size: 14px;
    outline: none;
}
.top-header .user-menu {
    display: flex;
    align-items: center;
    gap: 16px;
}
.top-header .user-menu .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

/* Page content */
.page-content { padding: 24px; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h2 { font-size: 24px; font-weight: 700; color: var(--dark); }

/* ===== Cards ===== */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 20px; }

/* ===== Dashboard Grid ===== */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.stat-card .stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-card .stat-icon.green { background: #dcfce7; color: var(--success); }
.stat-card .stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-card .stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-card .stat-info h3 { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-card .stat-info p { font-size: 13px; color: var(--text-light); }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ===== Messages ===== */
.message-list { list-style: none; }
.message-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    gap: 12px;
    cursor: pointer;
}
.message-item:hover { background: var(--light); }
.message-item.unread { background: var(--primary-light); font-weight: 600; }
.message-item.unread:hover { background: #c7d2fe; }
.message-item .msg-star {
    cursor: pointer;
    color: var(--text-light);
    font-size: 16px;
    transition: color 0.2s;
}
.message-item .msg-star.starred { color: var(--warning); }
.message-item .msg-sender {
    width: 180px;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-item .msg-subject {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-item .msg-subject .msg-preview {
    color: var(--text-light);
    font-weight: 400;
    margin-left: 8px;
}
.message-item .msg-date {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}
.message-item .msg-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
.message-item:hover .msg-actions { opacity: 1; }

/* Message view */
.message-view { padding: 24px; }
.message-view .msg-header { margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.message-view .msg-header h2 { font-size: 22px; margin-bottom: 8px; }
.message-view .msg-meta { display: flex; gap: 16px; font-size: 13px; color: var(--text-light); }
.message-view .msg-body { font-size: 15px; line-height: 1.8; white-space: pre-wrap; }
.message-view .msg-toolbar { display: flex; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
textarea.form-control { min-height: 200px; resize: vertical; }
select.form-control { appearance: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E") no-repeat right 12px center var(--white); padding-right: 36px; }

/* Checkbox */
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.form-check label { font-size: 14px; margin: 0; font-weight: 400; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-secondary { background: var(--light); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16a34a; color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--white);
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}
.btn-icon:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-light); }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ===== Contacts ===== */
.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.contact-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    transition: box-shadow 0.2s;
}
.contact-card:hover { box-shadow: var(--shadow-lg); }
.contact-card .contact-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.contact-card .contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}
.contact-card .contact-name { font-weight: 600; font-size: 15px; }
.contact-card .contact-email { font-size: 13px; color: var(--text-light); }
.contact-card .contact-details { font-size: 13px; color: var(--secondary); margin-top: 8px; }
.contact-card .contact-details span { display: block; margin-bottom: 4px; }
.contact-card .contact-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.contact-group-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: white;
}

/* ===== Calendar ===== */
.calendar-container { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); }
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.calendar-header h3 { font-size: 18px; }
.calendar-nav { display: flex; gap: 8px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar-day-header {
    padding: 12px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.calendar-day {
    min-height: 100px;
    padding: 8px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.calendar-day:nth-child(7n) { border-right: none; }
.calendar-day:hover { background: var(--light); }
.calendar-day.today { background: var(--primary-light); }
.calendar-day.other-month { opacity: 0.4; }
.calendar-day .day-number { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.calendar-day .day-number.today-num {
    background: var(--primary);
    color: white;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.calendar-event {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
    cursor: pointer;
}

/* ===== Rules ===== */
.rule-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}
.rule-item .rule-status { font-size: 24px; cursor: pointer; }
.rule-item .rule-info { flex: 1; }
.rule-item .rule-info h4 { font-size: 15px; font-weight: 600; }
.rule-item .rule-info p { font-size: 13px; color: var(--text-light); }
.rule-item .rule-actions { display: flex; gap: 8px; }

/* ===== Archive ===== */
.archive-settings .setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}
.archive-log-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    gap: 12px;
}

/* ===== Table ===== */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-light); background: var(--light); }
.table tbody tr:hover { background: var(--light); }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--white);
    border-radius: 12px;
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close { cursor: pointer; font-size: 24px; color: var(--text-light); background: none; border: none; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Auth ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
}
.auth-card {
    background: var(--white);
    border-radius: 16px;
    padding: 40px;
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}
.auth-card .auth-logo {
    text-align: center;
    margin-bottom: 32px;
}
.auth-card .auth-logo .logo-icon {
    width: 56px;
    height: 56px;
    background: var(--primary);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    font-weight: 700;
    margin-bottom: 12px;
}
.auth-card .auth-logo h2 { font-size: 22px; color: var(--dark); }
.auth-card .auth-logo p { font-size: 14px; color: var(--text-light); }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-light); }

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ===== Toggle switch ===== */
.toggle {
    position: relative;
    width: 48px;
    height: 26px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 26px;
    cursor: pointer;
    transition: 0.3s;
}
.toggle .slider:before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    left: 3px;
    top: 3px;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider:before { transform: translateX(22px); }

/* ===== Responsive ===== */
.sidebar-toggle { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text); }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .top-header .search-bar { max-width: 200px; }
    .message-item .msg-sender { width: 100px; }
    .contact-grid { grid-template-columns: 1fr; }
}

/* ===== Utilities ===== */
.text-muted { color: var(--text-light); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.hidden { display: none; }
