/* ─── ACM Platform Design System ─────────────────────────────────────────── */

:root {
  --primary:       #1a5fa8;
  --primary-dark:  #134a85;
  --primary-light: #e8f0fb;
  --secondary:     #2e7d52;
  --accent:        #d97706;
  --danger:        #dc2626;
  --warning:       #f59e0b;
  --success:       #16a34a;
  --info:          #0284c7;

  --bg:            #f0f4f8;
  --surface:       #ffffff;
  --surface2:      #f8fafc;
  --border:        #dde3ec;
  --border-dark:   #b0bbc9;

  --text:          #1e2b3a;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;

  --sidebar-bg:    #0f2744;
  --sidebar-text:  #c8d8ee;
  --sidebar-hover: #1a3a5c;
  --sidebar-active:#1a5fa8;
  --sidebar-w:     220px;
  --header-h:      56px;

  --radius:        6px;
  --radius-lg:     10px;
  --shadow:        0 1px 4px rgba(0,0,0,.08), 0 2px 12px rgba(0,0,0,.06);
  --shadow-md:     0 4px 20px rgba(0,0,0,.12);

  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-img {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}
.sidebar-logo .logo-mark {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.2px;
  line-height: 1.2;
}
.sidebar-logo .logo-sub {
  font-size: 10px;
  color: var(--sidebar-text);
  margin-top: 1px;
  opacity: .65;
  line-height: 1.2;
}

.sidebar-section {
  padding: 16px 0 4px;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #5a7a99;
  padding: 0 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: #6eb5ff;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info .user-name { font-size: 12.5px; font-weight: 600; color: #e2ecf8; }
.user-info .user-role { font-size: 11px; color: #7a98b8; }
.logout-btn {
  margin-top: 10px;
  width: 100%;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: #9bb5cc;
  padding: 7px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: background .15s;
}
.logout-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ─── Main ────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.page {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

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

/* ─── Stat Cards ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--text); margin-top: 4px; }
.stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-card.blue .stat-value  { color: var(--primary); }
.stat-card.green .stat-value { color: var(--secondary); }
.stat-card.amber .stat-value { color: var(--accent); }
.stat-card.red .stat-value   { color: var(--danger); }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .08s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 15px; height: 15px; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success   { background: var(--secondary); color: #fff; }
.btn-success:hover { background: #245f3f; }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline   { background: transparent; border-color: var(--border-dark); color: var(--text); }
.btn-outline:hover { background: var(--bg); }

.btn-ghost     { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 6px; border-radius: var(--radius); }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* ─── Toggle Switch ───────────────────────────────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border-dark);
  border-radius: 22px;
  transition: background .2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

input[type=text], input[type=email], input[type=password],
input[type=tel], input[type=date], input[type=number],
select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-family: var(--font);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,95,168,.15);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box input {
  padding-left: 34px;
  width: 260px;
}
.search-box svg {
  position: absolute;
  left: 10px;
  width: 16px; height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ─── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 10px 14px;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  cursor: pointer;
}
tbody tr:hover { background: var(--primary-light); }
tbody td {
  padding: 10px 14px;
  color: var(--text);
  vertical-align: middle;
}
tbody td.muted { color: var(--text-muted); }

/* ─── Badges / Status ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-teal   { background: #ccfbf1; color: #0f766e; }

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.tab:hover { color: var(--primary); background: var(--primary-light); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Page-level tab bar (e.g. Billing module tabs) */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
}
.tab-btn {
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color .15s, border-color .15s, background .15s;
}
.tab-btn:hover { color: var(--primary); background: var(--primary-light); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: fadeIn .15s;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .15s;
}
.modal-lg  { max-width: 900px; }
.modal-sm  { max-width: 420px; }
.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.close-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: var(--radius);
}
.close-btn:hover { background: var(--bg); color: var(--text); }
.close-btn svg { width: 20px; height: 20px; }

/* ─── Filter Bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-bar select { width: auto; min-width: 140px; }

/* ─── Section Heading ────────────────────────────────────────────────────── */
.section-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 0 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 14px;
}

/* ─── Login Screen ───────────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0d1f38 0%, #1a3a5c 60%, #0f2744 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.login-box {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  padding: 44px 44px 36px;
  width: 380px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-img { width: 72px; height: 72px; display: block; margin: 0 auto 12px; }
.login-logo .brand { font-size: 26px; font-weight: 800; color: var(--primary); letter-spacing: -.5px; margin-top: 4px; }
.login-logo .brand-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.login-box h2 { font-size: 19px; font-weight: 700; margin-bottom: 20px; }
.login-err { background: #fee2e2; color: var(--danger); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.login-forgot { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.login-forgot a { color: var(--primary); text-decoration: none; font-weight: 500; }
.login-forgot a:hover { text-decoration: underline; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.pagination .page-info { font-size: 12px; color: var(--text-muted); margin-right: auto; }
.page-btn {
  min-width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border-dark);
  background: var(--surface);
  cursor: pointer; font-size: 13px;
  transition: background .12s;
}
.page-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.page-btn:disabled { opacity: .4; cursor: default; pointer-events: none; }

/* ─── Alert / Toast ─────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; top: 20px; right: 20px;
  z-index: 9990; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  min-width: 260px; max-width: 380px;
  animation: slideLeft .2s;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideLeft { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Alert banners ─────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ─── Misc helpers ──────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.full-width { width: 100%; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ─── Client detail ─────────────────────────────────────────────────────── */
.client-header-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.client-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.client-name { font-size: 20px; font-weight: 800; color: var(--text); }
.client-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.client-meta span + span::before { content: ' · '; }

/* ─── Billing ────────────────────────────────────────────────────────────── */

/* Reconciliation sections */
.recon-section { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.recon-section-header {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}
.recon-denied  { background: #fef2f2; color: #b91c1c; border-bottom: 1px solid #fecaca; }
.recon-paid    { background: #f0fdf4; color: #15803d; border-bottom: 1px solid #bbf7d0; }
.recon-warn    { background: #fffbeb; color: #92400e; border-bottom: 1px solid #fde68a; }
.recon-pending { background: #eff6ff; color: #1d4ed8; border-bottom: 1px solid #bfdbfe; }

.ra-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.ra-stat { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.ra-stat-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.ra-stat-val   { font-size: 22px; font-weight: 800; margin-top: 4px; }

/* ─── Upload zone ────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text-muted);
}
.upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone svg { width: 36px; height: 36px; margin-bottom: 10px; }
.upload-zone p { font-size: 14px; margin: 4px 0; }
.upload-zone .hint { font-size: 12px; opacity: .7; }

/* ─── Config / Drag rows ─────────────────────────────────────────────────── */
.field-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: grab;
}
.field-row:hover { border-color: var(--primary); }
.field-row .drag-handle { color: var(--text-light); cursor: grab; }
.field-row .field-name { flex: 1; font-weight: 600; }
.field-row .field-type { font-size: 12px; color: var(--text-muted); padding: 2px 8px; background: var(--bg); border-radius: 20px; }

/* ─── Address Autocomplete ───────────────────────────────────────────────── */
.addr-wrap { position: relative; }
.addr-dropdown {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border-dark);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 500;
  max-height: 220px;
  overflow-y: auto;
}
.addr-option {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.addr-option:last-child { border-bottom: none; }
.addr-option:hover, .addr-option.highlighted { background: var(--primary-light); }
.addr-option .addr-main { font-weight: 600; color: var(--text); }
.addr-option .addr-sub  { font-size: 11px; color: var(--text-muted); }
.addr-loading { padding: 10px 12px; color: var(--text-muted); font-size: 12px; font-style: italic; }

/* ─── Activity Log ───────────────────────────────────────────────────────── */
.activity-item {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 34px; height: 34px; border-radius: 50%;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 14px; margin-top: 2px;
}
.dot-visit   { background: #dbeafe; }
.dot-phone   { background: #dcfce7; }
.dot-f2f     { background: #ede9fe; }
.dot-review  { background: #fef3c7; }
.dot-other   { background: #f1f5f9; }
.activity-body { flex: 1; }
.activity-type { font-weight: 700; font-size: 13px; }
.activity-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.activity-notes { font-size: 13px; color: var(--text); margin-top: 4px; font-style: italic; }

/* ─── Case Notes Feed ────────────────────────────────────────────────────── */
.note-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.note-item:last-child { border-bottom: none; }
.note-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.note-author { font-weight: 700; font-size: 13px; }
.note-date   { font-size: 12px; color: var(--text-muted); }
.note-text   { font-size: 13.5px; color: var(--text); white-space: pre-wrap; line-height: 1.5; }

/* ─── Service Status badges ──────────────────────────────────────────────── */
.svc-pending  { background: #f1f5f9; color: #475569; }
.svc-billed   { background: #dbeafe; color: #1d4ed8; }
.svc-paid     { background: #dcfce7; color: #15803d; }
.svc-denied   { background: #fee2e2; color: #b91c1c; }
.svc-credited { background: #fef3c7; color: #92400e; }

/* ─── Alert urgency rows ─────────────────────────────────────────────────── */
tr.urg-overdue  td:first-child { border-left: 3px solid var(--danger); }
tr.urg-critical td:first-child { border-left: 3px solid var(--warning); }
tr.urg-warning  td:first-child { border-left: 3px solid var(--accent); }
tr.urg-upcoming td:first-child { border-left: 3px solid var(--info); }

/* ─── Document Folders ───────────────────────────────────────────────────── */
.folder-item {
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
}
.folder-item:hover  { background: var(--primary-light); }
.folder-item.active { background: var(--primary-light); border-left-color: var(--primary); font-weight: 600; color: var(--primary); }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ─── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

/* ─── Mobile hamburger button ─────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 6px;
  border-radius: var(--radius);
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.mobile-menu-btn svg { width: 22px; height: 22px; display: block; }
.mobile-menu-btn:hover { background: var(--bg); }

/* Sidebar overlay backdrop */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.open { display: block; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Show hamburger ── */
  .mobile-menu-btn { display: flex; }

  /* ── Sidebar: mobile slide-in drawer ── */
  #app { display: block; height: 100vh; height: 100dvh; overflow: hidden; position: relative; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }

  /* Restore full sidebar labels (override old icon-only rules) */
  .sidebar-logo .logo-sub  { display: block; }
  .nav-item span           { display: inline; }
  .sidebar-section-label   { display: block; }
  .user-info               { display: block; }
  .nav-item { justify-content: flex-start; padding: 12px 20px; font-size: 14px; }
  .nav-item svg { width: 20px; height: 20px; }

  /* ── Main area takes full width ── */
  .main {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ── Topbar ── */
  .topbar { padding: 0 12px; gap: 10px; min-height: 48px; }
  .topbar-title { font-size: 16px; font-weight: 700; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn span { display: none; } /* hide button text, keep icon */
  .topbar-actions .btn { padding: 8px 10px; min-height: 36px; }
  .topbar-actions .btn svg { margin: 0; }

  /* ── Page: scrollable content area ── */
  .page { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }

  /* ── Login box ── */
  #login-screen { align-items: flex-start; padding-top: 40px; }
  .login-box {
    width: calc(100% - 32px);
    max-width: 380px;
    padding: 32px 22px 28px;
  }

  /* ── Stats grid ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 12px; cursor: pointer; }
  .stat-card:active { transform: scale(0.97); }

  /* ── Form rows ── */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .form-row-2 { grid-template-columns: 1fr; }

  /* ── Form inputs: bigger touch targets ── */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="tel"], input[type="number"], input[type="date"],
  input[type="search"], select, textarea {
    font-size: 16px !important; /* prevents iOS zoom */
    min-height: 42px;
    padding: 8px 12px;
  }

  /* ── Buttons: bigger touch targets ── */
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; font-size: 12px; }

  /* ── Search box: fluid width ── */
  .search-box { flex: 1; }
  .search-box input { width: 100%; min-width: 0; }

  /* ── Filter bar: wrap on mobile ── */
  .filter-bar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .filter-bar select { min-width: 0; flex: 1; }
  .filter-bar > * { min-width: 0; }

  /* ── Tables: scrollable with touch ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
  tbody td, thead th { padding: 10px 12px; white-space: nowrap; }
  /* Larger touch targets for table rows */
  tbody tr { cursor: pointer; }
  tbody tr:active { background: var(--primary-light); }

  /* ── Tabs: horizontal scroll with bigger touch targets ── */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0; gap: 0; }
  .tab { flex-shrink: 0; padding: 10px 14px; font-size: 13px; min-height: 40px; display: flex; align-items: center; }
  /* Hide scrollbar on tabs */
  .tabs::-webkit-scrollbar { display: none; }
  .tabs { -ms-overflow-style: none; scrollbar-width: none; }
  /* Page-level tab bar (Billing module) */
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-bar { -ms-overflow-style: none; scrollbar-width: none; }
  .tab-btn  { flex-shrink: 0; padding: 10px 14px; font-size: 13px; min-height: 40px; }

  /* ── Cards ── */
  .card { border-radius: var(--radius); }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px 10px; }

  /* ── Client header bar: wrap ── */
  .client-header-bar { flex-wrap: wrap; gap: 10px; padding: 14px; }
  .client-header-bar .btn { font-size: 12px; padding: 6px 12px; flex: 1; min-width: 0; text-align: center; }

  /* ── Profile two-col grid → single column ── */
  .profile-grid { grid-template-columns: 1fr !important; }

  /* ── Documents layout: stack ── */
  .docs-layout { flex-direction: column !important; }
  .docs-folders { width: 100% !important; }

  /* ── Date edit rows: stack on narrow screens ── */
  .date-edit-row { flex-wrap: wrap; gap: 4px; }
  .date-edit-label { min-width: 100px; font-size: 11px; }
  .date-edit-row input[type="date"] { min-width: 140px; }

  /* ── Modals: slide-up from bottom ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .modal-lg, .modal-sm {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    animation: slideUp .25s ease;
  }
  @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .modal-body  { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-header { padding: 14px 14px 10px; }
  .modal-footer { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .modal-footer .btn { flex: 1; min-width: 100px; }

  /* ── Toast: full-width ── */
  .toast-container { left: 10px; right: 10px; top: 10px; }
  .toast { min-width: unset; max-width: 100%; }

  /* ── Upload zone: tighter ── */
  .upload-zone { padding: 24px 16px; }

  /* ── Section heading ── */
  .section-heading { padding: 8px 0 6px; margin-bottom: 10px; }

  /* ── Pagination: centered and touch-friendly ── */
  .pagination { justify-content: center; flex-wrap: wrap; gap: 4px; }
  .pagination .btn { min-width: 36px; min-height: 36px; padding: 6px 10px; }

  /* ── Mobile card list style for key data ── */
  .mobile-card-list { display: flex; flex-direction: column; gap: 10px; }
  .mobile-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    cursor: pointer;
    transition: background .1s;
  }
  .mobile-card-item:active { background: var(--surface-2); }
  .mobile-card-item .mc-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
  .mobile-card-item .mc-sub { font-size: 12px; color: var(--text-muted); }
  .mobile-card-item .mc-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

  /* ── Sticky topbar on scroll ── */
  .topbar { position: sticky; top: 0; z-index: 50; }

  /* ── Better spacing for task items ── */
  .task-row, .hover-row { padding: 12px 14px; }
  .hover-row:active { background: var(--primary-light); }

  /* ── Case notes / timeline: full-width ── */
  .note-card, .timeline-item { padding: 12px; }

  /* ── Alert items: larger touch targets ── */
  .alert-item { padding: 12px 14px; min-height: 48px; }

  /* ── Hide less important table columns on mobile ── */
  .mobile-hide { display: none !important; }
  /* Show inline sub-info on mobile */
  .mobile-sub { display: inline !important; }

  /* ── Pull-down visual hint for scrollable areas ── */
  .page::after {
    content: '';
    display: block;
    height: 60px;
    flex-shrink: 0;
  }
}

/* ── Extra-small phones ── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .page { padding: 10px; }
  .topbar { padding: 0 10px; }
  .client-name { font-size: 17px; }
  .btn-lg { padding: 10px 16px; font-size: 14px; min-height: 44px; }
  .stat-value { font-size: 22px; }
  .ra-summary-grid { grid-template-columns: 1fr 1fr; }
  /* Modals go completely full-screen on tiny phones */
  .modal, .modal-lg, .modal-sm {
    max-height: 98vh;
    border-radius: 12px 12px 0 0;
  }
  /* FAB: tuck closer to corner on small screens */
  #fab-new-task { bottom: 16px; right: 16px; width: 52px; height: 52px; font-size: 24px; }
  /* Reconciliation section headers: smaller */
  .recon-section-header { font-size: 12px; padding: 8px 12px; }
  /* Card headers with inline actions: stack vertically */
  .card-header { flex-wrap: wrap; gap: 8px; }
  /* Client header buttons: stack vertically */
  .client-header-bar { flex-direction: column; align-items: stretch; }
  .client-header-bar > div { display: flex; flex-wrap: wrap; gap: 6px; }
  .client-header-bar .btn { flex: 1; justify-content: center; }
  /* Tabs: even more compact */
  .tab { padding: 8px 10px; font-size: 12px; }
  /* Filter bar: full width selects */
  .filter-bar { flex-direction: column; }
  .filter-bar select, .filter-bar .search-box { width: 100%; }
}

/* ── Searchable Select ─────────────────────────────────────────────────────── */
.ss-wrap { position: relative; }
.ss-input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--surface); cursor: pointer; }
.ss-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ss-dropdown { position: absolute; top: calc(100% + 2px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 220px; overflow-y: auto; z-index: 500; display: none; }
.ss-dropdown.open { display: block; }
.ss-option { padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 4px; }
.ss-option:hover, .ss-option.focused { background: var(--primary-light); color: var(--primary); }
.ss-option.placeholder { color: var(--text-muted); font-style: italic; }

/* ── Inline date edit rows ─────────────────────────────────────────────────── */
.date-edit-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border-light, #f1f5f9); }
.date-edit-row:last-child { border-bottom: none; }
.date-edit-label { min-width: 140px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; flex-shrink: 0; }
.date-edit-row input[type="date"] { flex: 1; padding: 4px 8px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; background: var(--surface); min-width: 0; }
.date-urgency-tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px; white-space: nowrap; flex-shrink: 0; }
.date-urgency-tag.red    { background: #fee2e2; color: #b91c1c; }
.date-urgency-tag.yellow { background: #fef9c3; color: #854d0e; }
.date-urgency-tag.green  { background: #d1fae5; color: #065f46; }
/* legacy aliases */
.date-urgency-tag.overdue  { background: #fee2e2; color: #b91c1c; }
.date-urgency-tag.critical { background: #fee2e2; color: #b91c1c; }
.date-urgency-tag.warning  { background: #fef9c3; color: #854d0e; }
.date-urgency-tag.upcoming { background: #d1fae5; color: #065f46; }


/* ── Click-to-call phone links ─────────────────────────────────────────────── */
a[href^="tel:"] {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
a[href^="tel:"]:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ── Mobile: table scroll hint shadow ───────────────────────────────────── */
.table-wrap {
  position: relative;
}
@media (max-width: 768px) {
  /* Bulk assign bar: full-width selects */
  #bulk-bar select { min-width: 0 !important; flex: 1; }
  #bulk-bar label  { flex: 1; min-width: 200px; }

  /* EDI Settings: single column on mobile */
  #edi-settings-form > div[style*="grid-template-columns"] {
    display: block !important;
  }
  #edi-settings-form > div > .card { margin-bottom: 16px; }

  /* RA summary grid: tighter on mobile */
  .ra-summary-grid { grid-template-columns: 1fr 1fr 1fr; }

  /* Client header action buttons: wrap */
  .client-header-bar .btn { font-size: 12px; padding: 5px 10px; }

  /* Topbar actions: show only icon buttons, hide text labels */
  .topbar-actions .btn-sm { padding: 5px 8px; }

  /* Hover row highlight */
  .hover-row:active { background: var(--primary-light); }
}

@media (max-width: 480px) {
  /* RA summary: 2 col on tiny screens */
  .ra-summary-grid { grid-template-columns: 1fr 1fr; }

  /* Recon section action buttons: stack */
  .recon-section td div[style*="display:flex"] { flex-direction: column; gap: 4px; }
  .recon-section .btn { width: 100%; }
}
