/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #e2e8f0;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-box {
    background: #fff;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h1 { font-size: 1.5rem; color: var(--gray-900); margin-bottom: 0.25rem; }
.login-subtitle { color: var(--gray-500); margin-bottom: 1.5rem; }

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

/* === Sidebar === */
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
}

.sidebar-brand strong { color: #fff; font-size: 1.1rem; }
.sidebar-brand span { font-size: 0.75rem; color: var(--sidebar-text); }

.sidebar-nav {
    list-style: none;
    padding: 0.5rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.sidebar-nav li a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav li.active a { background: rgba(255,255,255,0.1); color: var(--sidebar-active); font-weight: 500; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.btn-logout {
    display: block;
    text-align: center;
    padding: 0.4rem;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    text-decoration: none;
    border-radius: var(--radius);
}

.btn-logout:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }

/* === Content === */
.content {
    flex: 1;
    margin-left: 220px;
    min-width: 0;
}

.content-header {
    padding: 1.25rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 50;
}

.content-header h1 { font-size: 1.25rem; font-weight: 600; }

.content-body { padding: 1.5rem; }

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #fff;
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 0.25rem; }
.stat-detail { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.25rem; }

/* === Toolbar === */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toolbar-actions { display: flex; gap: 0.5rem; }

.search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.search-form input, .search-form select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--gray-100);
    color: var(--gray-700);
    text-decoration: none;
}

.btn:hover { background: var(--gray-200); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.btn-full { width: 100%; justify-content: center; }

/* === Tables === */
.data-table {
    width: 100%;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead th {
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--gray-50); }

.actions { white-space: nowrap; display: flex; gap: 0.25rem; }

.text-success { color: var(--success); font-weight: 600; }
.text-error { color: var(--danger); }
.text-muted { color: var(--gray-400); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-orange { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* === Forms === */
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.85rem; color: var(--gray-700); }
.form-group small { color: var(--gray-400); font-size: 0.75rem; }

.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.85rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.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(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.form-group-wide { grid-column: span 2; }

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.form-card {
    padding: 1.25rem;
    margin-bottom: 1rem;
}

/* === Cards === */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.card h3 { font-size: 1rem; margin-bottom: 0.75rem; }

/* === Alerts === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* === Modal === */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show { display: flex; }

.modal-content {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    width: 90%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 800px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0.25rem;
}

/* === Progress Bar === */
.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

/* === Template Editor === */
.code-editor {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    tab-size: 2;
    resize: vertical;
}

.template-help {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.template-help code {
    background: var(--gray-100);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

.preview-frame {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
}

/* === Contact Selector (for campaigns) === */
.contact-selector {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    overflow: hidden;
}

.selector-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.selector-toolbar input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.8rem;
}

#selectedCount { font-size: 0.8rem; color: var(--gray-500); white-space: nowrap; }

.contact-list-scroll {
    max-height: 250px;
    overflow-y: auto;
}

.contact-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--gray-100);
}

.contact-option:hover { background: var(--gray-50); }
.contact-option input { flex-shrink: 0; }
.contact-option span { min-width: 200px; }
.contact-option small { color: var(--gray-500); }

/* === Campaign Header === */
.campaign-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.campaign-meta {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.85rem;
}

.campaign-actions { display: flex; gap: 0.5rem; }

/* === Country Grid === */
.country-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.country-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--gray-50);
    border-radius: var(--radius);
    font-size: 0.82rem;
}

.country-stat strong { min-width: 2rem; }

/* === Utilities === */
.hidden { display: none !important; }

/* === Checkbox in table === */
.data-table input[type="checkbox"] { cursor: pointer; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-brand span, .sidebar-nav li a span { display: none; }
    .content { margin-left: 60px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
    .form-group-wide { grid-column: span 1; }
}
