/* ═══════════════════════════════════════════════════════════
   eHealth CRM — Shared Stylesheet
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --sidebar-w: 240px;
  --header-h: 56px;
  --accent: #0d6efd;
  --accent-light: #e8f0fe;
  --success: #198754;
  --warning: #fd7e14;
  --danger: #dc3545;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --bg: #f8f9fa;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08);
  --edit-bg: #f0f7ff;
  --edit-border: #0d6efd;
}

* { box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); margin: 0; font-size: 14px; color: #212529; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: #1a1d23; color: #adb5bd; display: flex; flex-direction: column;
  z-index: 1000; transition: transform .25s;
}
.sidebar-brand {
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .logo {
  width: 32px; height: 32px; background: var(--accent); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px;
}
.sidebar-brand span { font-weight: 600; font-size: 15px; color: #fff; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar .nav-section { padding: 16px 20px 4px; font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #495057; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 20px;
  color: #adb5bd; text-decoration: none; border-left: 3px solid transparent;
  font-size: 13.5px; transition: all .15s; cursor: pointer;
}
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.sidebar .nav-link.active { color: #fff; background: rgba(13,110,253,.15); border-left-color: var(--accent); }
.sidebar .nav-link i { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 99px;
  min-width: 20px; text-align: center;
}

/* ── Main layout ───────────────────────────────────────── */
.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

/* ── Topbar ────────────────────────────────────────────── */
.topbar {
  height: var(--header-h); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-title { font-weight: 600; font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-content { padding: 24px; flex: 1; }

/* ── KPI cards ─────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-row  { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card { background: #fff; border-radius: 10px; padding: 16px 18px; box-shadow: var(--card-shadow); border: 1px solid var(--border); }
.kpi-card .kpi-icon,
.kpi-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; font-size: 17px; }
.kpi-card .kpi-val,
.kpi-val { font-size: 26px; font-weight: 700; line-height: 1; margin-bottom: 3px; }
.kpi-card .kpi-lbl,
.kpi-lbl { font-size: 12px; color: var(--text-muted); }
.kpi-card .kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ────────────────────────────────────────────── */
.tbl-wrap { background: #fff; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--card-shadow); overflow: hidden; }
.tbl-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tbl-header h6 { margin: 0; font-weight: 600; font-size: 14px; }
table { width: 100%; font-size: 13px; border-collapse: collapse; }
thead th { background: #f8f9fa; font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; color: #495057; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody td { padding: 10px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* ── Status / priority badges ──────────────────────────── */
.badge-tier1 { background: #fff0f0; color: #c0392b; font-size: 10px; padding: 3px 8px; border-radius: 99px; font-weight: 600; }
.badge-tier2 { background: #fff8e1; color: #e65100; font-size: 10px; padding: 3px 8px; border-radius: 99px; font-weight: 600; }
.badge-tier3 { background: #e8f5e9; color: #2e7d32; font-size: 10px; padding: 3px 8px; border-radius: 99px; font-weight: 600; }

.status-pill { font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 500; display: inline-block; white-space: nowrap; }
/* Lead statuses */
.st-NEW           { background: #e3f2fd; color: #1565c0; }
.st-CONTACTED     { background: #e8eaf6; color: #283593; }
.st-INTERESTED    { background: #e8f5e9; color: #1b5e20; }
.st-PROPOSAL_SENT { background: #fff8e1; color: #e65100; }
.st-NEGOTIATING   { background: #fce4ec; color: #880e4f; }
.st-WON           { background: #e8f5e9; color: #1b5e20; font-weight: 700; }
.st-LOST          { background: #fce4ec; color: #b71c1c; }
.st-NOT_INTERESTED{ background: #f5f5f5; color: #757575; }
/* Branch statuses */
.st-ACTIVE           { background: #e8f5e9; color: #1b5e20; }
.st-INACTIVE         { background: #f5f5f5; color: #757575; }
.st-SUSPENDED        { background: #fff8e1; color: #e65100; }
.st-UNDER_CONSTRUCTION { background: #e3f2fd; color: #1565c0; }
.st-CLOSED           { background: #fce4ec; color: #880e4f; }

.no-web-dot  { width: 7px; height: 7px; border-radius: 50%; background: #dc3545; display: inline-block; margin-right: 4px; }
.has-web-dot { width: 7px; height: 7px; border-radius: 50%; background: #198754; display: inline-block; margin-right: 4px; }

.pri-HIGH   { color: #dc3545; font-weight: 600; }
.pri-MEDIUM { color: #fd7e14; font-weight: 600; }
.pri-LOW    { color: #6c757d; font-weight: 600; }

/* ── Gap badges ────────────────────────────────────────── */
.gap-badge   { font-size: 10px; padding: 3px 8px; border-radius: 5px; font-weight: 600; display: inline-block; }
.gap-missing { background: #fff0f0; color: #c0392b; }
.gap-present { background: #e8f5e9; color: #2e7d32; }

/* ── Cards ─────────────────────────────────────────────── */
.dash-card { background: #fff; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--card-shadow); }
.dash-card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input { font-size: 13px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; outline: none; }
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(13,110,253,.12); }

/* ── Pagination ────────────────────────────────────────── */
.pag-wrap { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.pag-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.pag-btn { padding: 4px 10px; border: 1px solid var(--border); border-radius: 5px; background: #fff; cursor: pointer; font-size: 12px; }
.pag-btn:hover { background: var(--accent-light); }
.pag-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Loading overlay ───────────────────────────────────── */
.loading-overlay { display: none; position: absolute; inset: 0; background: rgba(255,255,255,.7); border-radius: 10px; z-index: 10; align-items: center; justify-content: center; }
.loading-overlay.show { display: flex; }
.spinner { width: 28px; height: 28px; border: 3px solid #dee2e6; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Activity feed ─────────────────────────────────────── */
.activity-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.activity-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Info rows ─────────────────────────────────────────── */
.info-row { display: flex; gap: 6px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid #f5f5f5; font-size: 13px; }
.info-row:last-child { border-bottom: none; }
.info-lbl { color: var(--text-muted); min-width: 130px; flex-shrink: 0; font-size: 12px; padding-top: 1px; }
.info-val { font-weight: 500; word-break: break-word; }

/* ── Timeline ──────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 11px; top: 0; bottom: 0; width: 2px; background: #e9ecef; }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-dot { position: absolute; left: -22px; top: 4px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; }
.tl-card { background: #f8f9fa; border-radius: 8px; padding: 10px 14px; border: 1px solid #e9ecef; }
.tl-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.tl-text { font-size: 13px; }

/* ── Facility header / hero ────────────────────────────── */
.fac-header { background: linear-gradient(135deg, #1a1d23 0%, #2c3047 100%); color: #fff; padding: 20px 24px; border-radius: 11px 11px 0 0; }
.fac-hero   { background: linear-gradient(135deg, #1a1d23 0%, #2c3047 100%); color: #fff; padding: 24px; border-radius: 12px; margin-bottom: 20px; }
.fac-title  { font-size: 18px; font-weight: 700; }
.fac-meta   { font-size: 12px; color: rgba(255,255,255,.65); margin-top: 4px; }
.modal-xl .modal-content { border-radius: 12px; }

/* ── Charts ────────────────────────────────────────────── */
.chart-container { position: relative; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .kpi-grid, .kpi-row { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
}

/* ── Login page ────────────────────────────────────────── */
body.login-body {
  background: #1a1d23;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 14px; padding: 40px 36px;
  width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,.35);
}
.logo {
  width: 44px; height: 44px; background: #0d6efd; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; margin: 0 auto 16px;
}
.brand-name { font-size: 20px; font-weight: 700; text-align: center; color: #1a1d23; margin-bottom: 4px; }
.brand-sub  { font-size: 13px; color: #6c757d; text-align: center; margin-bottom: 28px; }
.login-card label { font-size: 13px; font-weight: 500; color: #343a40; margin-bottom: 4px; display: block; }
.login-card input[type=text],
.login-card input[type=password] {
  width: 100%; padding: 9px 12px; border: 1px solid #dee2e6; border-radius: 7px;
  font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s; margin-bottom: 16px;
}
.login-card input:focus { border-color: #0d6efd; box-shadow: 0 0 0 3px rgba(13,110,253,.12); }
.btn-login {
  width: 100%; padding: 10px; background: #0d6efd; color: #fff; border: none;
  border-radius: 7px; font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-login:hover { background: #0b5ed7; }
.alert-err {
  background: #fff5f5; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 7px; padding: 9px 12px; font-size: 13px; margin-bottom: 16px;
}

/* ── Leads page ────────────────────────────────────────── */
.status-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.st-tab {
  padding: 5px 13px; border-radius: 99px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); background: #fff; cursor: pointer; transition: all .15s;
  white-space: nowrap; user-select: none;
}
.st-tab:hover { border-color: var(--accent); color: var(--accent); }
.st-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.overdue-date { color: #dc3545; font-weight: 600; }
.today-date   { color: #e65100; font-weight: 600; }
.svc-pill { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: #e8f0fe; color: #1565c0; margin: 1px; display: inline-block; }

/* ── Branches page ─────────────────────────────────────── */
.org-avatar {
  width: 36px; height: 36px; border-radius: 8px; background: #e8f0fe; color: #1a73e8;
  font-weight: 600; font-size: 13px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.org-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.section-tab { display: none; }
.section-tab.active { display: block; }
.detail-panel { background: #fff; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--card-shadow); }
.detail-header { background: linear-gradient(135deg, #1a1d23 0%, #2c3047 100%); color: #fff; padding: 20px 24px; border-radius: 9px 9px 0 0; }
.hq-badge { font-size: 10px; padding: 2px 7px; border-radius: 4px; background: #fef7e0; color: #b45309; font-weight: 600; }
.drag-handle { cursor: grab; color: #aaa; }
.drag-handle:active { cursor: grabbing; }
tr.drag-over { outline: 2px dashed var(--accent); }

/* ── Facility detail page ──────────────────────────────── */
.amenity-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; margin: 3px; }
.amenity-yes { background: #e8f5e9; color: #2e7d32; }
.amenity-no  { background: #f5f5f5; color: #9e9e9e; }
.accred-badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 7px; font-size: 12px; font-weight: 600; margin: 3px; }
.accred-yes { background: #e8f5e9; color: #1b5e20; }
.accred-no  { background: #fafafa; color: #bdbdbd; border: 1px solid #e0e0e0; }
.lic-ACTIVE          { background: #e8f5e9; color: #2e7d32; }
.lic-EXPIRED         { background: #fce8e6; color: #c62828; }
.lic-SUSPENDED       { background: #fff3e0; color: #e65100; }
.lic-PENDING_RENEWAL { background: #fff8e1; color: #f57f17; }
.lic-RENEWED         { background: #e3f2fd; color: #1565c0; }
.spec-pill { font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 500; }
.shimmer { height: 14px; border-radius: 4px; background: linear-gradient(90deg,#f0f0f0 25%,#e8e8e8 50%,#f0f0f0 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Facility editor ───────────────────────────────────── */
.filter-panel { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); overflow: hidden; }
.filter-header { display: flex; align-items: center; padding: 11px 16px; cursor: pointer; user-select: none; font-size: 13px; gap: 6px; background: #fff; }
.filter-header:hover { background: #fafbfc; }
.filter-body { padding: 14px 16px 16px; border-top: 1px solid var(--border); }
.filter-body.collapsed { display: none; }
.filter-label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.filter-divider { height: 1px; background: #f0f0f0; margin: 10px 0 12px; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.results-summary { font-size: 13px; color: var(--text-muted); }
.fe-table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); overflow: hidden; }
.fe-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fe-table thead th { background: #f8f9fa; font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; color: #495057; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.fe-table tbody tr.view-row:hover { background: #fafbfc; }
.fe-table tbody td { padding: 9px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.fe-table tbody tr.view-row.editing > td { background: var(--edit-bg); border-bottom: none; }
.fe-table tbody tr:last-child td,
.fe-table tbody tr.edit-row:last-child td { border-bottom: none; }
.row-num { color: #bbb; font-size: 11px; text-align: center; width: 40px; }
.fac-link { color: #1a1a2e; text-decoration: none; font-weight: 500; font-size: 13px; transition: color .1s; }
.fac-link:hover { color: var(--accent); }
.city-tag { display: inline-block; font-size: 10px; color: var(--text-muted); background: #f0f0f0; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: middle; font-weight: 400; }
.emirate-tag { font-size: 11px; font-weight: 600; color: #1565c0; background: #e3f2fd; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.ownership-tag { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 4px; background: #f0f0f0; color: #495057; white-space: nowrap; }
.cat-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 6px; cursor: pointer; transition: box-shadow .15s; }
.cat-cell, .subcat-cell { cursor: pointer; }
.cat-cell:hover .cat-badge, .subcat-cell:hover .subcat-badge { box-shadow: 0 0 0 2px var(--accent); }
.subcat-badge { display: inline-block; font-size: 11px; font-weight: 500; padding: 3px 10px; border-radius: 6px; background: #e9ecef; color: #495057; cursor: pointer; transition: box-shadow .15s; }
.no-subcat-tag { color: #ccc; font-size: 11px; font-style: italic; }
.edit-btn { color: var(--text-muted); font-size: 13px; opacity: 0; transition: opacity .12s; background: none; border: none; padding: 2px 5px; cursor: pointer; border-radius: 4px; }
.view-row:hover .edit-btn { opacity: 1; }
.edit-btn:hover { background: var(--accent-light); color: var(--accent); }
.edit-row > td { background: var(--edit-bg); border-bottom: 2px solid var(--edit-border) !important; padding: 10px 14px; }
.edit-row-content { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.edit-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; min-width: 0; flex-shrink: 0; padding-bottom: 6px; }
.edit-label strong { color: #212529; }
.edit-fields { display: flex; gap: 10px; flex: 1; min-width: 300px; }
.edit-field { flex: 1; min-width: 140px; }
.edit-field-label { display: block; font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.edit-actions { display: flex; gap: 6px; align-items: flex-end; flex-shrink: 0; padding-bottom: 1px; }
.pagination-wrap { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pagination-wrap .btn { min-width: 32px; height: 30px; padding: 0 8px; font-size: 12px; line-height: 28px; }
.view-row.saving { pointer-events: none; opacity: .6; }
.fe-toast { position: fixed; bottom: 24px; right: 24px; padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,.18); z-index: 9999; opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; pointer-events: none; }
.fe-toast.show { opacity: 1; transform: translateY(0); }
.fe-toast.success { background: #198754; color: #fff; }
.fe-toast.error   { background: #dc3545; color: #fff; }
.fe-toast.info    { background: #0d6efd; color: #fff; }
.state-cell { text-align: center; padding: 36px 14px !important; color: var(--text-muted); font-size: 13px; }

@media (max-width: 900px) {
  .page-content { padding: 12px; }
  .topbar { padding: 0 12px; }
  .edit-fields { min-width: 0; flex-direction: column; }
  .edit-row-content { flex-direction: column; align-items: flex-start; }
  .edit-label { display: none; }
}
@media (max-width: 600px) {
  .topbar-title { font-size: 13px; }
  .filter-body .row { flex-direction: column; }
}
