/* === Custom Properties === */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --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-width: 240px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--gray-800); background: var(--gray-50); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
table { border-collapse: collapse; width: 100%; }

/* === Layout === */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    display: flex; flex-direction: column;
    z-index: 100;
}
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--gray-700); }
.sidebar-header h2 { font-size: 18px; font-weight: 700; }
.nav-links { list-style: none; padding: 12px 0; flex: 1; }
.nav-links li a {
    display: block; padding: 10px 20px; color: var(--gray-300);
    font-size: 14px; transition: background 0.15s, color 0.15s;
}
.nav-links li a:hover { background: var(--gray-700); color: #fff; text-decoration: none; }
.nav-links li a.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--gray-700); font-size: 13px; }
.sidebar-footer .user-name { display: block; color: var(--gray-300); margin-bottom: 4px; }
.sidebar-footer .logout-link { color: var(--gray-400); font-size: 12px; }
.sidebar-footer .logout-link:hover { color: #fff; }

.content { margin-left: var(--sidebar-width); padding: 24px 32px; min-height: 100vh; }
.content-full { padding: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* === Page Header === */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 700; }

/* === Cards === */
.card {
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 16px; font-weight: 600; }

/* === Stat Cards === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; }
.stat-card .stat-label { font-size: 12px; text-transform: uppercase; color: var(--gray-500); font-weight: 600; letter-spacing: 0.5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* === Tables === */
.table-wrapper { overflow-x: auto; }
table th, table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--gray-200); font-size: 14px; }
table th { background: var(--gray-50); font-weight: 600; color: var(--gray-600); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
table tr:hover { background: var(--gray-50); }

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500;
    border: 1px solid transparent; transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.form-control {
    width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: 6px;
    font-size: 14px; font-family: inherit; transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { appearance: auto; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* === Badges === */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 12px; font-weight: 600; text-transform: capitalize;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* === 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: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md);
    width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--gray-400); line-height: 1; }
.modal-close:hover { color: var(--gray-700); }

/* === Toast === */
#toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 300;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px; border-radius: 6px; color: #fff; font-size: 14px;
    box-shadow: var(--shadow-md); animation: slideIn 0.3s ease;
    min-width: 280px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === Login Page === */
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 32px; }
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; color: var(--gray-500); font-size: 14px; margin-bottom: 24px; }
.login-error { background: var(--danger-light); color: var(--danger); padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }

/* === Queue / Work View === */
.queue-container { display: grid; grid-template-columns: 340px 1fr; gap: 24px; }
.queue-list { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; max-height: calc(100vh - 160px); overflow-y: auto; }
.queue-item { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); cursor: pointer; transition: background 0.1s; }
.queue-item:hover { background: var(--gray-50); }
.queue-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.queue-item .entity-name { font-weight: 600; font-size: 14px; }
.queue-item .entity-meta { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.work-view { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.work-view h2 { font-size: 20px; margin-bottom: 4px; }
.work-view .entity-details { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.work-view .detail-item label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; }
.work-view .detail-item span { display: block; font-size: 14px; font-weight: 500; }

.script-panel { background: var(--gray-50); border-radius: 6px; padding: 16px; margin: 16px 0; }
.script-panel h4 { font-size: 13px; color: var(--gray-600); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.script-panel .script-content { font-size: 14px; white-space: pre-wrap; }

.outreach-form { border-top: 1px solid var(--gray-200); padding-top: 16px; margin-top: 16px; }

/* === Charts === */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.chart-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.chart-card canvas { width: 100% !important; }

/* === Tabs === */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab {
    padding: 8px 16px; font-size: 14px; font-weight: 500; color: var(--gray-500);
    border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer;
    background: none; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === Tag Editor (for stages) === */
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--gray-300); border-radius: 6px; min-height: 42px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--primary-light); color: var(--primary); border-radius: 4px; font-size: 13px; }
.tag button { background: none; border: none; color: var(--primary); font-size: 16px; line-height: 1; padding: 0; }
.tag-input { border: none; outline: none; font-size: 14px; flex: 1; min-width: 120px; padding: 4px; }

/* === Empty State === */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-500); }
.empty-state h3 { font-size: 18px; color: var(--gray-700); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* === Responsive === */
@media (max-width: 1024px) {
    .queue-container { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .nav-links li a span, .sidebar-footer .user-name { display: none; }
    .content { margin-left: 60px; padding: 16px; }
}

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