:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --sidebar-width: 250px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

/* Auth Pages */
.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: 400px; padding: 1rem; }
.auth-card {
    background: white;
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    text-align: center;
}
.auth-card h1 { font-size: 2rem; color: var(--primary); margin-bottom: 0.25rem; }
.auth-subtitle { color: var(--gray-500); margin-bottom: 1.5rem; }
.auth-links { margin-top: 1rem; }
.auth-links a { color: var(--primary); text-decoration: none; font-size: 0.875rem; }

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

.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
}
.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-header h2 { color: var(--primary); font-size: 1.25rem; }
.sidebar-close { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; }
.sidebar-nav { flex: 1; padding: 0.5rem; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.2s;
}
.nav-item:hover { background: var(--gray-100); }
.nav-item.active { background: var(--primary); color: white; }
.nav-icon { font-size: 1.1rem; }
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--gray-200);
}
.user-info { padding: 0.5rem 1rem; }
.user-info span { display: block; font-weight: 500; font-size: 0.875rem; }
.user-info small { color: var(--gray-500); font-size: 0.75rem; }
.logout-btn { color: var(--danger) !important; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}
.top-bar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.page-title { font-size: 1.25rem; font-weight: 600; }
.menu-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; }
.content-area { padding: 1.5rem; }

/* Cards & Panels */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.panel {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-header h3 { font-size: 0.95rem; font-weight: 600; }
.panel-body { padding: 1rem 1.5rem; }

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.widget {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.widget-link { text-decoration: none; color: inherit; transition: box-shadow 0.2s; }
.widget-link:hover { box-shadow: var(--shadow-md); }
.widget-icon { font-size: 2rem; }
.widget-content h3 { font-size: 1.5rem; font-weight: 700; }
.widget-content p { color: var(--gray-500); font-size: 0.8rem; }
.dashboard-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th { text-align: left; padding: 0.75rem; border-bottom: 2px solid var(--gray-200); color: var(--gray-500); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
.table td { padding: 0.75rem; border-bottom: 1px solid var(--gray-100); }
.table tr:hover td { background: var(--gray-50); }
.table a { color: var(--primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { margin-bottom: 0.5rem; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--gray-700); margin-bottom: 0.25rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }
.checkbox-label { display: flex !important; align-items: center; gap: 0.5rem; cursor: pointer; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--gray-300);
    background: white;
    color: var(--gray-700);
    cursor: pointer;
    transition: all 0.2s;
}
.btn:hover { background: var(--gray-50); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }

/* Filters */
.filter-bar { margin-bottom: 1rem; }
.filter-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.filter-form input, .filter-form select { padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.875rem; }

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
}
.status-active, .status-sent, .status-completed { background: #d1fae5; color: #065f46; }
.status-inactive, .status-withdrawn, .status-failed { background: #fee2e2; color: #991b1b; }
.status-pending { background: #fef3c7; color: #92400e; }

/* Progress Bars */
.progress-bar { height: 6px; background: var(--gray-200); border-radius: 3px; overflow: hidden; }
.progress-bar-lg { height: 12px; background: var(--gray-200); border-radius: 6px; overflow: hidden; margin-bottom: 0.5rem; }
.progress-fill { height: 100%; border-radius: inherit; transition: width 0.3s; }
.progress-green { background: var(--success); }
.progress-orange { background: var(--warning); }
.progress-red { background: var(--danger); }
.progress-large { text-align: center; padding: 1rem 0; }
.progress-text { font-size: 1.1rem; font-weight: 600; margin-top: 0.5rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Pagination */
.pagination { display: flex; gap: 0.25rem; margin-top: 1rem; justify-content: center; }
.page-link { padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: var(--radius); text-decoration: none; color: var(--gray-700); font-size: 0.8rem; }
.page-link.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Detail Pages */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; }
.detail-list dt { font-weight: 500; color: var(--gray-500); font-size: 0.8rem; }
.detail-list dd { font-size: 0.875rem; }

/* Misc */
.page-actions { margin-bottom: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.inline { display: inline; }
.actions { white-space: nowrap; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.badge { background: var(--primary); color: white; padding: 0.125rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100); }
.section-title { margin: 1.5rem 0 0.75rem; font-size: 1rem; color: var(--gray-700); }
.block-item { margin-bottom: 1rem; }
.block-item ul { list-style: none; padding-left: 1rem; }
.block-item li { padding: 0.25rem 0; font-size: 0.875rem; color: var(--gray-700); }
.block-item li::before { content: "•"; color: var(--primary); margin-right: 0.5rem; }
.block-section { margin-bottom: 1.5rem; }
.block-section h4 { margin-bottom: 0.5rem; color: var(--gray-700); }
.bulk-actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.bulk-actions select { padding: 0.375rem 0.75rem; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.8rem; }
.note-form { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--gray-200); }
.note-item { padding: 0.75rem 0; border-bottom: 1px solid var(--gray-100); }
.note-meta { display: flex; justify-content: space-between; margin-bottom: 0.25rem; font-size: 0.75rem; color: var(--gray-500); }
.note-item p { font-size: 0.875rem; }
.notes-list { max-height: 300px; overflow-y: auto; }
.email-item { padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100); }
.email-item strong { display: block; font-size: 0.85rem; }
.email-item small { color: var(--gray-500); }
.template-item { padding: 1rem 0; border-bottom: 1px solid var(--gray-200); margin-bottom: 1rem; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .menu-toggle { display: block; }
    .main-content { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .dashboard-panels { grid-template-columns: 1fr; }
    .filter-form { flex-direction: column; }
    .filter-form input, .filter-form select { width: 100%; }
}
