/* CMBR CRM — base styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: system-ui, sans-serif; font-size: 14px; color: #1a1a1a; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 20px; height: 48px; padding: 0 20px; background: #fff; border-bottom: 1px solid #e2e8f0; position: sticky; top: 0; z-index: 51; }
.topbar-brand { font-weight: 700; font-size: 15px; color: #1e293b; text-decoration: none; flex-shrink: 0; }
.topbar-nav { display: flex; gap: 2px; flex: 1; align-items: center; }
.topbar-nav a { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 48px; color: #475569; text-decoration: none; font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.topbar-nav a:hover { color: #1e293b; }
.topbar-nav a.active { color: #2563eb; border-bottom-color: #2563eb; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #64748b; flex-shrink: 0; }
.topbar-user a { color: #64748b; text-decoration: none; }
.topbar-user a:hover { color: #2563eb; }

/* Mobile drawer plumbing */
.menu-btn { display: none; background: none; border: none; font-size: 22px; cursor: pointer; padding: 4px 8px; color: #475569; line-height: 1; flex-shrink: 0; }
.drawer-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 49; }
.drawer-overlay.open { display: block; }

/* Filters button (contacts mobile only) */
.filters-btn { display: none; }

/* Main */
.main-content { padding: 24px; }
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.page-header h2 { font-size: 20px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }

/* Login */
.login-body { display: flex; min-height: 100vh; background: #f1f5f9; justify-content: center; align-items: center; }
.login-card { background: #fff; padding: 40px; border-radius: 8px; width: 340px; box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.login-card h1 { font-size: 22px; margin-bottom: 24px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; margin-top: 14px; }
.login-card input { width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px; }
.login-card button { width: 100%; margin-top: 20px; padding: 10px; background: #2563eb; color: #fff; border: none; border-radius: 4px; font-size: 14px; cursor: pointer; }
.login-card button:hover { background: #1d4ed8; }
.error { color: #dc2626; font-size: 13px; margin-bottom: 8px; }

/* Table */
.table-scroll-wrap { overflow: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; min-width: 900px; border-collapse: collapse; }
.data-table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid #e2e8f0; font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; }
.data-table tr.clickable-row:hover { background: #f8fafc; cursor: pointer; }
.empty { color: #94a3b8; font-style: italic; }

/* Search */
.search-form input { padding: 6px 10px; border: 1px solid #cbd5e1; border-radius: 4px; width: 260px; }

/* Pill */
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.pill.member { background: #dcfce7; color: #166534; }

/* Side panel */
.panel-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 100; }
.panel-overlay.open { display: block; }
.detail-panel { position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100vw; background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.15); z-index: 101; transform: translateX(100%); transition: transform .2s ease; display: flex; flex-direction: column; }
.detail-panel.open { transform: translateX(0); }
#panel-body { display: flex; flex-direction: column; flex: 1; overflow-y: auto; overflow-x: hidden; }
.panel-header { background: #1e293b; color: #fff; padding: 16px 20px; display: flex; align-items: flex-start; gap: 12px; flex-shrink: 0; }
.panel-name { font-size: 17px; font-weight: 700; line-height: 1.2; }
.panel-email { font-size: 13px; opacity: .75; margin-top: 3px; }
.panel-header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.panel-close { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px; opacity: .7; }
.panel-close:hover { opacity: 1; background: none; }
.panel-content { padding: 16px 20px; flex: 1; min-width: 0; }
.panel-section { margin-bottom: 18px; }
.panel-section h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: #64748b; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid #f1f5f9; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; width: 100%; }
.info-item { min-width: 0; }
.info-item .lbl { font-size: 11px; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.info-item .val { font-size: 13px; font-weight: 500; word-break: break-word; }
.info-item.wide { grid-column: span 2; }
.panel-notes { font-size: 13px; color: #374151; line-height: 1.5; white-space: pre-wrap; }
.panel-footer { padding: 12px 20px; border-top: 1px solid #e2e8f0; display: flex; align-items: center; gap: 12px; flex-shrink: 0; background: #fff; }

/* Panel edit form */
.panel-edit-form { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.panel-edit-form .panel-content { overflow-y: auto; min-height: 0; }
.panel-edit-form .panel-section label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 500; color: #374151; margin-bottom: 8px; }
.panel-edit-form input:not([type=checkbox]),
.panel-edit-form textarea { padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 13px; font-family: inherit; width: 100%; }
.panel-edit-form input:not([type=checkbox]):focus,
.panel-edit-form textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.panel-edit-form textarea { min-height: 80px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 60px 90px; gap: 8px; }
.checkbox-label { flex-direction: row !important; align-items: center !important; gap: 8px !important; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: auto !important; }

/* Buttons */
.btn { display: inline-block; padding: 6px 12px; background: #2563eb; color: #fff; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #1d4ed8; }
.btn-danger { display: inline-block; padding: 6px 12px; background: #dc2626; color: #fff; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; }
.btn-danger:hover { background: #b91c1c; }
.btn-inline-sm { padding: 1px 6px; font-size: 11px; border: 1px solid #cbd5e1; border-radius: 3px; cursor: pointer; background: #f8fafc; color: #475569; vertical-align: middle; }
.btn-inline-sm:hover { background: #e2e8f0; }
button { padding: 4px 10px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 12px; cursor: pointer; background: #fff; }
button:hover { background: #f1f5f9; }

/* Mini tables — detail panel history sections */
.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table th { text-align: left; color: #64748b; font-weight: 600; padding: 4px 8px 6px; border-bottom: 1px solid #e2e8f0; white-space: nowrap; }
.mini-table td { padding: 3px 8px; border-bottom: 1px solid #f8fafc; vertical-align: top; }
.mini-table tr:last-child td { border-bottom: none; }
.panel-empty { font-size: 12px; color: #94a3b8; font-style: italic; }
.contact-link { color: #1e40af; text-decoration: none; cursor: pointer; }
.contact-link:hover { text-decoration: underline; }
.mini-dl-link { font-size: 11px; color: #2563eb; white-space: nowrap; }
.tag-refunded { color: #dc2626; font-size: 11px; }
.tag-inkind { color: #7c3aed; font-size: 11px; }
.tag-pseudo { color: #92400e; font-size: 11px; }
.tag-source { color: #64748b; font-size: 11px; }
.tag-minor { display: inline-block; font-size: 10px; font-weight: 600; color: #7c3aed; background: #ede9fe; border-radius: 3px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }
.minor-row td { background: #f8fafc; color: #475569; }
.minor-row td[data-col="name"] { padding-left: 24px; }
.minor-indent { color: #cbd5e1; margin-right: 4px; }
/* Volunteer hours grid */
.vol-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.vol-stat { text-align: center; background: #f8fafc; border-radius: 6px; padding: 6px 4px; }
.vol-stat .val { font-size: 16px; font-weight: 700; color: #1e293b; display: block; }
.vol-stat .lbl { font-size: 11px; color: #64748b; }
/* Follow-up panel highlight */
.panel-section-warning h3 { color: #b45309; }
.panel-section-info h3 { color: #1e40af; }

/* Two-col layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.two-col section h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }

/* Edit form */
.edit-form { max-width: 480px; display: flex; flex-direction: column; gap: 12px; }
.edit-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.edit-form input, .edit-form textarea { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px; font-family: inherit; }
.edit-form textarea { min-height: 80px; resize: vertical; }


/* ── Tier 2: Status pills (upgrade) ──────────────────────────────────────── */
.pill.expiring { background: #fef9c3; color: #854d0e; }
.pill.lapsed { background: #fee2e2; color: #991b1b; }
.pill.needs-join { background: #fed7aa; color: #9a3412; }
.pill .pill-sub { opacity: 0.7; font-weight: 500; }
.pill.donor { background: #ede9fe; color: #5b21b6; }
.pill.donor-recent { background: #bbf7d0; color: #15803d; }
.pill.donor-lapsed { background: #fed7aa; color: #c2410c; }
.pill.waiver-current { background: #bbf7d0; color: #15803d; }
.pill.waiver-expired { background: #fed7aa; color: #c2410c; }

/* ── Tier 2: Name-cell badges ────────────────────────────────────────────── */
.badge-ji { display: inline-block; font-size: 9px; font-weight: 700; background: #dbeafe; color: #1d4ed8; border-radius: 3px; padding: 1px 4px; margin-left: 5px; vertical-align: middle; letter-spacing: .02em; }
.badge-pending { display: inline-block; font-size: 10px; font-weight: 700; background: #fef3c7; color: #92400e; border-radius: 3px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }
.badge-mc-optout { display: inline-block; font-size: 9px; font-weight: 700; background: #fee2e2; color: #991b1b; border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: middle; letter-spacing: .02em; }
.badge-mc-bounce { display: inline-block; font-size: 9px; font-weight: 700; background: #fef9c3; color: #854d0e; border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: middle; letter-spacing: .02em; }

/* ── Tier 2: Nav badges ──────────────────────────────────────────────────── */
.nav-badge { display: inline-block; background: #dc2626; color: #fff; font-size: 10px; font-weight: 700; border-radius: 99px; padding: 1px 6px; margin-left: 6px; min-width: 18px; text-align: center; vertical-align: middle; line-height: 14px; }
.nav-badge:empty { display: none; }

/* ── Sticky header row + Name column ─────────────────────────────────────── */
.data-table thead th { position: sticky; top: 0; z-index: 5; background: #f8fafc; }
.data-table th[data-col="name"],
.data-table td[data-col="name"] { position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: 2px 0 4px rgba(0,0,0,.06); }
.data-table th[data-col="name"] { background: #f8fafc; z-index: 6; }
.data-table tbody tr:nth-child(even) td { background: #f8fafc; }
.data-table tbody tr:nth-child(even) td[data-col="name"] { background: #f8fafc; }
.data-table tr.clickable-row:hover td { background: #eff6ff; }
.data-table tr.clickable-row:hover td[data-col="name"] { background: #eff6ff; }


/* ── Tier 3: Contacts two-column layout ──────────────────────────────────── */
.contacts-layout { display: flex; gap: 16px; align-items: stretch; height: calc(100vh - 72px); overflow: hidden; }
.seg-sidebar-wrap { width: 210px; flex-shrink: 0; overflow-y: auto; }
.contacts-main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ── Tier 3: Segment sidebar ─────────────────────────────────────────────── */
.seg-sidebar { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 0 12px; }
.seg-section-label { font-size: 10px; font-weight: 700; letter-spacing: .08em; color: #94a3b8; text-transform: uppercase; padding: 8px 12px 4px; }
.seg-reports-label { margin-top: 8px; padding-top: 12px; border-top: 1px solid #e2e8f0; }
.seg-group-label { font-size: 10px; font-weight: 600; letter-spacing: .05em; color: #64748b; text-transform: uppercase; padding: 10px 12px 3px; }
.seg-action { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; text-decoration: none; color: #1e293b; font-size: 13px; font-weight: 500; }
.seg-action:hover { background: #eff6ff; color: #2563eb; }
.seg-action.active { background: #dbeafe; color: #1d4ed8; border-left: 3px solid #2563eb; padding-left: 9px; }
.seg-badge { background: #dc2626; color: #fff; font-size: 10px; font-weight: 700; border-radius: 99px; padding: 1px 6px; min-width: 18px; text-align: center; flex-shrink: 0; }
.seg-link { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px 4px 18px; text-decoration: none; color: #475569; font-size: 12px; gap: 4px; }
.seg-link:hover { background: #eff6ff; color: #2563eb; }
.seg-link.active { background: #eff6ff; color: #1d4ed8; font-weight: 600; }
.seg-count { font-size: 11px; color: #94a3b8; flex-shrink: 0; }
.seg-coming-soon { display: block; padding: 4px 18px; font-size: 11px; color: #94a3b8; font-style: italic; }



/* ── Relationships ───────────────────────────────────────────────────────── */
.rel-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.rel-item { display: flex; align-items: center; gap: 6px; font-size: 13px; flex-wrap: wrap; }
.rel-item .lbl { color: #64748b; font-weight: 600; min-width: 90px; }
.rel-item .val { font-weight: 500; }
.rel-email { color: #94a3b8; font-size: 12px; }
.btn-remove { margin-left: auto; background: none; border: none; color: #94a3b8; font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1; }
.btn-remove:hover { color: #dc2626; }
.rel-add { margin-top: 6px; }
.rel-add-row { display: flex; gap: 6px; margin-bottom: 4px; }
.input-sm { font-size: 13px; padding: 4px 8px; border: 1px solid #cbd5e1; border-radius: 4px; background: #fff; }
.input-sm:focus { outline: none; border-color: #93c5fd; }
.rel-result { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.rel-result:last-child { border-bottom: none; }
.rel-result button { font-size: 12px; padding: 2px 8px; background: #2563eb; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.rel-result button:hover { background: #1d4ed8; }
.rel-no-results { font-size: 12px; color: #94a3b8; padding: 4px 6px; }

/* ── Tier 6: Responsive / mobile ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-btn { display: inline-flex; align-items: center; }
  .topbar-brand { flex: 1; }
  .topbar-nav { position: fixed; top: 48px; left: -240px; bottom: 0; width: 220px; background: #fff; flex-direction: column; align-items: stretch; gap: 0; border-right: 1px solid #e2e8f0; transition: left .2s ease; z-index: 50; padding: 8px 0; overflow-y: auto; }
  .topbar-nav.open { left: 0; box-shadow: 4px 0 16px rgba(0,0,0,.18); }
  .topbar-nav a { height: 44px; border-bottom: none; border-left: 3px solid transparent; padding: 0 16px; }
  .topbar-nav a.active { border-bottom: none; border-left-color: #2563eb; background: #eff6ff; }
  .topbar-user span { display: none; }
  .main-content { padding: 16px; }
  /* Contacts: segment sidebar becomes a drawer */
  .contacts-layout { display: block; height: calc(100vh - 64px); overflow: hidden; }
  .contacts-main { height: 100%; }
  .seg-sidebar-wrap { position: fixed; top: 48px; left: -240px; bottom: 0; width: 220px; background: #fff; z-index: 50; transition: left .2s ease; border-right: 1px solid #e2e8f0; max-height: none; overflow-y: auto; }
  .seg-sidebar-wrap.open { left: 0; box-shadow: 4px 0 16px rgba(0,0,0,.18); }
  /* Prevent auto-zoom on input focus (iOS/Edge require font-size >= 16px) */
  .contacts-toolbar .search-form input { font-size: 16px; }
  /* Disable sticky name column — too wide with few columns on small screens */
  .data-table td[data-col="name"],
  .data-table th[data-col="name"] { position: static; box-shadow: none; }
  /* Let table natural-size on mobile; horizontal scroll only when needed */
  .data-table { min-width: 0; }
  /* Labeled filter chip */
  .filters-btn { display: inline-flex !important; align-items: center; gap: 6px; padding: 6px 12px; background: #eff6ff; color: #1d4ed8; border: 1px solid #93c5fd; border-radius: 6px; font-size: 13px; font-weight: 600; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .filters-btn:hover { background: #dbeafe; }
}

