/**
 * CTOAM CRM (crm.ctoam.com) — Admin shared styles.
 * Design system adapted from the CTOAM services CRM, extended with source/site
 * pills and a submission timeline for the consolidated multi-form view.
 */

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

:root {
    --primary: #002870;
    --primary-light: #0041b8;
    --primary-hover: #003399;
    --accent: #0066cc;
    --bg: #f0f2f7;
    --surface: #ffffff;
    --surface2: #f5f7fa;
    --surface3: #eaecf2;
    --border: #dde1ec;
    --border-light: #eef0f7;
    --text: #111827;
    --text-muted: #6b7280;
    --text-dim: #4b5563;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #2563eb;
    --sidebar-w: 260px;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
    width: 38px; height: 38px;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: white; flex-shrink: 0;
}
.logo-text { font-size: 15px; font-weight: 700; color: white; line-height: 1.2; }
.logo-sub  { font-size: 11px; color: rgba(255,255,255,0.55); font-weight: 400; }

.sidebar-nav { flex: 1; padding: 16px 12px; }
.nav-section-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
    color: rgba(255,255,255,0.4); padding: 12px 8px 6px; font-weight: 600;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    color: rgba(255,255,255,0.7); text-decoration: none;
    font-size: 13.5px; font-weight: 500; transition: all 0.15s; margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-link.active { background: rgba(255,255,255,0.18); color: white; font-weight: 600; }
.nav-link i { width: 18px; text-align: center; font-size: 14px; }
.nav-badge {
    margin-left: auto; background: #e0312e; color: white;
    font-size: 10px; font-weight: 700; border-radius: 99px; padding: 2px 7px;
}

.sidebar-footer { padding: 16px 12px; border-top: 1px solid rgba(255,255,255,0.1); }
.admin-info {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 9px;
    background: rgba(255,255,255,0.08); margin-bottom: 8px;
}
.admin-avatar {
    width: 34px; height: 34px; background: rgba(255,255,255,0.25);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}
.admin-name { font-size: 13px; font-weight: 600; color: white; }
.admin-role { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: capitalize; }

/* ── Main content ── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
    gap: 16px; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.page-title { font-size: 18px; font-weight: 700; color: var(--text); }
.page-breadcrumb { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { padding: 28px 32px; flex: 1; }

/* ── Cards ── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface2);
}
.card-title { font-size: 13.5px; font-weight: 700; color: var(--text); }
.card-body { padding: 20px; }

/* ── Stat cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.stat-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; margin-bottom: 14px; }
.stat-card.blue   .stat-icon { background: #dbeafe; color: #1d4ed8; }
.stat-card.green  .stat-icon { background: #dcfce7; color: #15803d; }
.stat-card.amber  .stat-icon { background: #fef3c7; color: #b45309; }
.stat-card.red    .stat-icon { background: #fee2e2; color: #b91c1c; }
.stat-card.purple .stat-icon { background: #f3e8ff; color: #7e22ce; }
.stat-card.teal   .stat-icon { background: #ccfbf1; color: #0f766e; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    padding: 11px 16px; text-align: left; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted);
    border-bottom: 2px solid var(--border); background: var(--surface2); white-space: nowrap;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle; color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8f9fe; }

/* ── Status badges ── */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600;
    text-transform: capitalize; white-space: nowrap;
}
.badge-new         { background: #dbeafe; color: #1e40af; }
.badge-contacted   { background: #f3e8ff; color: #6b21a8; }
.badge-qualified   { background: #dcfce7; color: #166534; }
.badge-follow_up   { background: #fef3c7; color: #92400e; }
.badge-closed_won  { background: #d1fae5; color: #064e3b; }
.badge-closed_lost { background: #fee2e2; color: #991b1b; }
.badge-default     { background: var(--surface3); color: var(--text-muted); }

/* ── Source / site pills ── */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 7px; font-size: 11px; font-weight: 600;
    white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.pill-site { background: #e0e7ff; color: #3730a3; }
.pill-form { background: #ecfeff; color: #155e75; border: 1px solid #cffafe; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
    font-family: inherit; cursor: pointer; border: none; text-decoration: none;
    transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: white; color: var(--text-dim); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 7px 10px; }

/* ── Forms ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.form-control {
    width: 100%; background: white; border: 1px solid var(--border); border-radius: 8px;
    padding: 9px 13px; color: var(--text); font-size: 13.5px; font-family: inherit;
    outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(0,65,184,0.1); }
textarea.form-control { resize: vertical; min-height: 90px; }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: 9px; font-size: 13.5px; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; border: 1px solid; }
.alert-success { background: var(--success-bg); color: #166534; border-color: var(--success-border); }
.alert-danger  { background: var(--danger-bg);  color: #991b1b; border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }

/* ── Filter bar ── */
.filter-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; }
.search-input {
    width: 100%; background: white; border: 1px solid var(--border); border-radius: 8px;
    padding: 9px 13px 9px 36px; color: var(--text); font-size: 13.5px; font-family: inherit;
    outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(0,65,184,0.1); }

/* ── Contact detail ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.detail-value { font-size: 14px; color: var(--text); word-break: break-word; }

/* ── Submission timeline ── */
.timeline { list-style: none; position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 0 0 18px 0; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
    position: absolute; left: -26px; top: 2px; width: 16px; height: 16px; border-radius: 50%;
    background: white; border: 3px solid var(--primary-light);
}
.timeline-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.timeline-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.timeline-body { font-size: 13px; color: var(--text-dim); margin-top: 6px; background: var(--surface2); border-radius: 8px; padding: 10px 12px; }

/* ── Notes ── */
.note { background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px; }
.note-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }
.note-body { font-size: 13.5px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.page-btn {
    padding: 7px 13px; border-radius: 7px; border: 1px solid var(--border); background: white;
    color: var(--text-dim); font-size: 13px; cursor: pointer; text-decoration: none;
    font-family: inherit; transition: all 0.15s;
}
.page-btn:hover { background: var(--surface2); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Progress bars (dashboard breakdowns) ── */
.bar-track { background: var(--surface3); border-radius: 99px; height: 6px; overflow: hidden; }
.bar-fill { background: var(--primary-light); border-radius: 99px; height: 6px; }

/* ── Utilities ── */
.text-muted   { color: var(--text-muted); }
.text-dim     { color: var(--text-dim); }
.text-sm      { font-size: 12px; }
.text-center  { text-align: center; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; } .w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.empty { text-align: center; padding: 44px 16px; color: var(--text-muted); }
.empty i { font-size: 28px; margin-bottom: 10px; display: block; opacity: 0.6; }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .detail-grid, .form-row { grid-template-columns: 1fr; }
    .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
    .main { margin-left: 0; }
}

/* ── Added: new pipeline statuses ── */
.badge-waiting_response { background: #e0e7ff; color: #3730a3; }
.badge-completed        { background: #d1fae5; color: #065f46; }

/* ── Added: client type pills ── */
.pill-ct { border: 1px solid transparent; }
.pill-ct-individual { background: #eef2ff; color: #3730a3; border-color: #dfe4fb; }
.pill-ct-doctor     { background: #ecfdf5; color: #065f46; border-color: #d3f3e4; }
.pill-ct-clinic     { background: #fff7ed; color: #9a3412; border-color: #fbe3cd; }

/* ── Added: email body view ── */
.email-body {
    background: var(--surface2); border: 1px solid var(--border); border-radius: 9px;
    padding: 16px 18px; font-size: 13.5px; line-height: 1.7; color: var(--text);
    white-space: pre-wrap; word-break: break-word;
}
tbody tr.clickable { cursor: pointer; }
