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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --header-h: 61px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
.hidden { display: none !important; }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; background: var(--surface); color: var(--text); transition: all 0.15s; white-space: nowrap; }
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-block { width: 100%; justify-content: center; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* --- Screens --- */
.screen { min-height: 100vh; }

/* --- Profiles --- */
#profiles-screen { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); padding: 40px 20px; }
.profiles-card { background: var(--surface); padding: 40px; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 100%; max-width: 560px; }
.profiles-card h1 { font-size: 22px; margin-bottom: 4px; }
.profiles-card .subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.profiles-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.profile-card { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #f8fafc; gap: 12px; }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-weight: 600; font-size: 15px; }
.profile-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.profile-actions { display: flex; gap: 6px; flex-shrink: 0; }
.profiles-empty { text-align: center; color: var(--text-muted); font-size: 14px; padding: 24px 0; margin-bottom: 16px; }
.profiles-footer { margin-top: 8px; }
.profiles-shared-divider { font-size: 11px; font-weight: 600; color: var(--text-muted); text-align: center; padding: 8px 0 4px; letter-spacing: 0.5px; text-transform: uppercase; }
.profile-card-shared { background: #f0f9ff; border-color: #bae6fd; }
.badge-shared { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: 10px; font-weight: 600; background: #dbeafe; color: var(--primary); vertical-align: middle; }

/* --- Form --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.form-group input, .form-group select { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border 0.15s; }
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.optional { color: var(--text-muted); font-weight: 400; }
.error-msg { color: var(--danger); font-size: 13px; }

/* --- Header --- */
header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); height: var(--header-h); flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 16px; }
header h1 { font-size: 18px; }
.user-badge { background: #dbeafe; color: var(--primary); padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }

/* --- Dashboard --- */
#dashboard { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.dashboard-body { display: flex; flex: 1; overflow: hidden; }

/* --- Sidebar --- */
.entity-sidebar { width: 260px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { padding: 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.entity-list { flex: 1; overflow-y: auto; }

.ts-item { padding: 10px 14px; cursor: pointer; border-left: 3px solid transparent; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.ts-item:hover { background: #f1f5f9; }
.ts-item.active { background: #eff6ff; border-left-color: var(--primary); }
.ts-item.selected { background: #f0f9ff; border-left-color: #0ea5e9; }
.ts-item-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-item.active .ts-item-name { color: var(--primary); }
.ts-item-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-item-count { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
.ts-checkbox { cursor: pointer; accent-color: var(--primary); }

/* --- Main panel --- */
.main-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 20px 24px 0; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 16px; flex-wrap: wrap; flex-shrink: 0; }
.panel-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.panel-title h2 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 500px; }
.field-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.panel-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* --- Search input --- */
.search-input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; background: var(--surface); }
.search-input:focus { border-color: var(--primary); }

/* --- Add recipient bar --- */
.add-recipient-bar { position: relative; margin-bottom: 14px; flex-shrink: 0; }
.search-wrap { display: flex; gap: 8px; }
.type-select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; background: var(--surface); cursor: pointer; }
.type-select:focus { border-color: var(--primary); }

.search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 100; max-height: 280px; overflow-y: auto; margin-top: 4px; }
.search-result-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--border); gap: 12px; }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f1f5f9; }
.search-result-name { font-size: 13px; font-weight: 600; }
.search-result-meta { font-size: 12px; color: var(--text-muted); }
.search-result-type { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.type-candidate { background: #dbeafe; color: var(--primary); }
.type-contact { background: #fce7f3; color: #db2777; }
.search-no-results { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.search-searching { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* --- Table --- */
.table-container { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); background: #f8fafc; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 2; }
td { padding: 9px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
td.col-email { color: var(--text-muted); font-size: 12px; }
td.col-status { font-size: 12px; }
td.col-action { text-align: right; white-space: nowrap; }
tr.filter-row { background: #f8fafc; }
tr.filter-row td { padding: 6px 14px; }
.filter-input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }
.filter-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1); }

/* --- Loading / Empty --- */
.loading, .empty-state { padding: 60px 40px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 100%; max-width: 800px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-small { max-width: 440px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border); }
