:root {
  --brand: #b9491e;
  --brand-hover: #a13e1a;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-light: #f1f3f5;
  --bg: #f9fafb;
  --bg-card: #ffffff;
}

* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
h1, h2 { margin: 0; }

.topbar {
  background: #fff; color: var(--text); padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { font-size: 1.05em; color: var(--brand); font-weight: 700; }
.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar a { color: #374151; text-decoration: none; font-size: 14px; transition: color 0.15s; }
.topbar a:hover { color: var(--brand); }
.topbar #user-info { font-size: 13px; color: var(--text-muted); }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }

section { margin-bottom: 24px; }
section h2 { margin-bottom: 8px; font-size: 1.05em; color: var(--text); font-weight: 600; }

table {
  width: 100%; border-collapse: collapse; background: var(--bg-card);
  border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border);
}
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border-light); text-align: start; font-size: 14px; }
th { background: #fafbfc; font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
tr:last-child td { border-bottom: none; }
tr.overdue td { background: #fef2f2; }

button {
  padding: 6px 12px; border: 1px solid var(--border); background: #fff; cursor: pointer;
  border-radius: 5px; font-size: 14px; color: var(--text);
  transition: all 0.15s;
}
button:hover { border-color: #cbd0d6; background: #fafbfc; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

input, select, textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 14px;
  width: 100%;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
}

#filters { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
#filters select { width: auto; min-width: 160px; }

.login-box {
  max-width: 360px; margin: 80px auto; padding: 28px;
  background: #fff; border-radius: 8px;
  border: 1px solid var(--border);
}
.login-box h1 { text-align: center; margin-bottom: 16px; font-size: 1.4em; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box .hint { font-size: 12px; color: #666; margin-top: 20px; text-align: center; }
.error { color: #c0392b; font-size: 13px; margin: 0; }

.alerts { margin-bottom: 12px; }
.alert {
  background: #fff3cd; border: 1px solid #ffd54f;
  padding: 8px 12px; border-radius: 4px; margin-bottom: 4px; font-size: 14px;
}

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff; padding: 20px; border-radius: 8px;
  min-width: 320px; max-width: 420px; width: 90%;
}
.modal-content h2 { margin-bottom: 12px; font-size: 1.1em; }
.modal-content label { display: block; margin-bottom: 10px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-card {
  background: #fff; padding: 14px 18px; border-radius: 6px; min-width: 130px;
  border: 1px solid var(--border);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 26px; font-weight: 600; color: var(--text); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge.sys-under-review { background: #f3e5f5; color: #6a1b9a; }
.badge.sys-open         { background: #e3f2fd; color: #1565c0; }
.badge.custom-active    { background: #fff9c4; color: #795548; }
.badge.custom-terminal  { background: #e8f5e9; color: #2e7d32; }

#lang-switcher {
  width: auto; min-width: 90px; padding: 4px 8px; font-size: 13px;
  background: #fff; color: var(--text); border: 1px solid var(--border);
}
#lang-switcher option { background: #fff; color: var(--text); }

.lang-switch-wrap { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.lang-switch-wrap #lang-switcher {
  background: #fff; color: #222; border: 1px solid #ccc;
}
.lang-switch-wrap #lang-switcher option { background: #fff; color: #222; }

html[dir="rtl"] body { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.inline-form input, .inline-form select { width: auto; min-width: 160px; }
#form-msg { font-size: 13px; margin-inline-start: 6px; }
#form-msg.success { color: #2e7d32; }
#form-msg.error { color: #c0392b; }

.region-card {
  background: #fff; border: 1px solid #e0e2e6; border-radius: 6px;
  padding: 12px; margin-bottom: 10px;
}
.region-head {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 8px; border-bottom: 1px solid #eef0f4; margin-bottom: 8px;
}
.region-head strong { flex: 1; }
.sub-region-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.sub-region-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px; background: #eef0f4; border-radius: 16px;
  font-size: 13px;
}
.sub-region-chip button {
  padding: 0 6px; font-size: 12px; background: transparent; border: none;
  cursor: pointer; color: #666;
}
.sub-region-chip button:hover { color: #c0392b; }

/* Toasts */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
html[dir="rtl"] #toast-container { right: auto; left: 20px; }
.toast {
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12); font-size: 14px;
  opacity: 0; transform: translateY(-10px); transition: all 0.2s ease;
  pointer-events: auto; max-width: 400px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: #2e7d32; }
.toast.toast-error   { background: #c62828; }
.toast.toast-info    { background: #1565c0; }

/* Global loading bar */
#global-loading-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 2px; background: linear-gradient(90deg, transparent 0%, var(--brand) 50%, transparent 100%);
  background-size: 200% 100%;
  z-index: 10000; pointer-events: none; opacity: 0;
  transition: opacity 0.15s;
}
#global-loading-bar.active { opacity: 1; animation: loading-slide 1.2s linear infinite; }
@keyframes loading-slide {
  0% { background-position: -100% 0; }
  100% { background-position: 100% 0; }
}

/* Confirm modal danger button */
button.danger { background: #c62828; color: #fff; border-color: #c62828; }
button.danger:hover { filter: brightness(1.1); }

/* Pagination */
.pagination {
  display: flex; gap: 6px; align-items: center; justify-content: flex-end;
  margin-bottom: 10px; font-size: 13px; color: #666;
}
.pagination button {
  padding: 4px 10px; font-size: 13px;
}
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination .page-info { margin-inline: 8px; }

/* CSV import */
.csv-example {
  background: #f5f6f8; border: 1px solid #e0e2e6; border-radius: 4px;
  padding: 8px; font-size: 12px; margin-bottom: 10px; overflow-x: auto;
}
.import-result {
  margin-top: 10px; padding: 10px; border-radius: 4px; font-size: 13px;
}
.import-result.success { background: #e8f5e9; color: #2e7d32; }
.import-result.error   { background: #ffebee; color: #c62828; }
.import-result ul { margin: 6px 0 0 0; padding-inline-start: 20px; font-size: 12px; }

.forgot-link { text-align: center; font-size: 13px; margin: 10px 0 4px; }
.forgot-link a { color: var(--brand); text-decoration: none; }
.forgot-link a:hover { text-decoration: underline; }

.footer-links { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-light); }
.footer-links a { color: var(--text-muted); text-decoration: none; margin: 0 4px; }
.footer-links a:hover { color: var(--brand); text-decoration: underline; }

/* ============ MOBILE RESPONSIVE ============ */
@media (max-width: 768px) {
  main { padding: 12px; }
  h1 { font-size: 1.15em; }
  h2 { font-size: 1em; }

  /* Topbar: stack on mobile */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px;
  }
  .topbar h1 { text-align: center; }
  .topbar nav {
    flex-wrap: wrap;
    gap: 8px 10px;
    justify-content: center;
    font-size: 13px;
  }
  .topbar nav a { padding: 2px 4px; }
  .topbar #user-info { order: -1; width: 100%; text-align: center; font-size: 12px; opacity: 0.8; }

  /* Filters: stack vertically */
  #filters { flex-direction: column; align-items: stretch; }
  #filters select, #filters input, #filters button { width: 100%; }

  /* Tables: horizontal scroll */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  th, td { padding: 6px 8px; font-size: 13px; }

  /* Modals: fit screen */
  .modal-content { min-width: 0; width: calc(100vw - 20px); max-width: calc(100vw - 20px); margin: 10px; padding: 14px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions button { width: 100%; }

  /* Login box */
  .login-box { margin: 20px auto; max-width: calc(100vw - 24px); }

  /* Stats cards */
  .stats { flex-direction: column; gap: 8px; }
  .stat-card { min-width: 0; width: 100%; }

  /* Inline forms */
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; min-width: 0; }

  /* Pagination */
  .pagination { justify-content: center; }

  /* Region cards */
  .region-card { padding: 10px; }
  .region-head { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  table { font-size: 12px; }
  .topbar nav { font-size: 12px; }
  button { padding: 6px 8px; font-size: 13px; }
  .badge { font-size: 11px; }
}

.phone-number { font-family: "Consolas", "Courier New", monospace; }
.btn-reveal { padding: 2px 8px; font-size: 12px; background: #eef0f4; border: 1px solid #c8ccd3; border-radius: 12px; cursor: pointer; }
.btn-reveal:hover { background: #d9dde3; }
.reveal-count { color: #c0392b; font-weight: 600; font-size: 13px; cursor: help; }
.note-dot { cursor: help; font-size: 13px; opacity: 0.8; }

.btn-budget-history {
  padding: 2px 8px; font-size: 12px; background: #fff3cd;
  border: 1px solid #ffd54f; border-radius: 12px; cursor: pointer;
}
.btn-budget-history:hover { background: #ffe69c; }

/* Subscription */
.subscription-alert {
  padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 14px;
  border: 1px solid;
}
.subscription-alert.warning { background: #fff3cd; border-color: #ffd54f; color: #f57f17; }
.subscription-alert.danger  { background: #ffebee; border-color: #ef9a9a; color: #c62828; }

.status-card {
  background: #fff; border-radius: 8px; padding: 24px;
  text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.status-card.status-none { background: #eef0f4; color: #666; }
.status-card .status-big { font-size: 58px; font-weight: 700; line-height: 1; }
.status-card .status-label { font-size: 14px; margin-top: 4px; opacity: 0.9; }
.status-card .status-dates { font-size: 14px; margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(0,0,0,0.1); display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.status-card .status-help { font-size: 13px; margin-top: 10px; opacity: 0.8; }
.status-loading { color: #888; font-size: 14px; padding: 20px; }

/* PWA install button */
.pwa-install-btn {
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 4px 10px;
  font-size: 13px;
}
.pwa-install-btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.checkbox-list {
  max-height: 150px; overflow-y: auto;
  border: 1px solid #ccc; border-radius: 4px;
  padding: 8px; background: #fafafa;
}
.checkbox-row {
  display: block; margin-bottom: 4px; font-size: 13px; cursor: pointer;
  padding: 2px 4px; border-radius: 3px;
}
.checkbox-row:hover { background: #eef0f4; }
.checkbox-row input { margin-inline-end: 6px; width: auto; }
.hint-text { color: #888; font-size: 13px; margin: 0; text-align: center; padding: 8px; }

.terminal-hint {
  margin: 0 0 10px;
  padding: 8px 10px;
  background: #fff3ec;
  border: 1px solid #f4c9b1;
  border-radius: 5px;
  font-size: 13px;
  color: var(--brand);
}

.returned-from {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  cursor: help;
  color: var(--text-muted);
  white-space: nowrap;
}
.returned-from-submit-final { color: #2e7d32; }
.returned-from-auto-overdue { color: #c62828; }

.history-table { margin-bottom: 12px; }
.history-table th, .history-table td { font-size: 13px; padding: 6px 10px; }
.history-lead-name { color: #666; margin-bottom: 10px; font-size: 14px; }

/* ===== Per-tenant feature toggles =====
   Body classes are added in dashboard.js after fetching tenant features.
   Anything tagged .feature-budget / .feature-region is hidden when the
   matching feature is disabled. */
.feature-budget-disabled .feature-budget { display: none !important; }
.feature-region-disabled .feature-region { display: none !important; }

/* ===== Analytics dashboard (manager-only) ===== */
#analytics { margin-bottom: 24px; }
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.analytics-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.analytics-label {
  font-size: 12px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 8px;
}
.analytics-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}
.analytics-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
.analytics-overdue {
  background: linear-gradient(135deg, #fff1f1 0%, #fff8f8 100%);
  border-color: #ffc4c4;
  text-align: center;
  justify-content: center;
}
.analytics-overdue .analytics-label { color: #b71c1c; }
.analytics-big-number {
  font-size: 60px;
  font-weight: 800;
  color: #c62828;
  line-height: 1;
  margin: 8px 0 6px;
}
.analytics-sub { font-size: 13px; color: #888; }

@media (max-width: 1024px) {
  .analytics-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .analytics-grid { grid-template-columns: 1fr; gap: 12px; }
  .analytics-big-number { font-size: 44px; }
  .analytics-card { min-height: 160px; }
}

/* ===== KPI cards (top of dashboard) ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.kpi-card-warning { border-color: #ffd0d0; background: linear-gradient(135deg, #fff5f5 0%, #fff 60%); }
.kpi-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}
.kpi-icon-total   { background: #eaf2ff; }
.kpi-icon-overdue { background: #ffeaea; }
.kpi-icon-today   { background: #eaffee; }
.kpi-icon-closed  { background: #f0eaff; }
.kpi-content { flex: 1; min-width: 0; }
.kpi-label {
  font-size: 12px;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  margin-bottom: 2px;
}
.kpi-value {
  font-size: 30px;
  font-weight: 800;
  color: #222;
  line-height: 1.1;
}
.kpi-trend {
  font-size: 12px;
  margin-top: 4px;
  color: #888;
}
.kpi-trend.up   { color: #2e7d32; }
.kpi-trend.down { color: #c62828; }
.kpi-card-warning .kpi-value { color: #c62828; }

.analytics-grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* ===== Overdue + Recent overview tables ===== */
.overview-section {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.overview-section-warning {
  border-color: #ffd0d0;
  background: linear-gradient(180deg, #fff8f8 0%, #fff 50%);
}
.overview-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.overview-section-header h2 {
  margin: 0;
  font-size: 17px;
  display: flex; align-items: center; gap: 8px;
}
.overview-icon { color: #c62828; }
.overview-count {
  background: #fee;
  color: #c62828;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
}
.overview-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.overview-table th, .overview-table td {
  text-align: start;
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.overview-table th { font-size: 12px; text-transform: uppercase; color: #888; font-weight: 600; }
.overview-table tr:last-child td { border-bottom: none; }
.overview-table .badge-days {
  background: #ffeaea;
  color: #c62828;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.overview-followup-btn {
  background: #fff;
  color: #c62828;
  border: 1px solid #ffb3b3;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.overview-followup-btn:hover { background: #fff0f0; }

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .analytics-grid-3 { grid-template-columns: 1fr; }
}
/* On phones keep KPIs as a 2×2 grid so the manager doesn't have to scroll
   through 4 stacked cards before reaching the data. Cards shrink instead. */
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-card { padding: 10px 12px; gap: 10px; }
  .kpi-icon { width: 38px; height: 38px; font-size: 18px; border-radius: 9px; }
  .kpi-label { font-size: 10px; }
  .kpi-value { font-size: 20px; }
  .kpi-trend { font-size: 10px; }

  .analytics-card { min-height: 220px; padding: 12px; }

  .overview-table { font-size: 13px; }
  .overview-table th, .overview-table td { padding: 8px 6px; }
  .overview-section { padding: 14px; }
}

/* ===== App layout: sidebar + topbar (chrome.js) ===== */
.app-layout { background: #f6f7f9; min-height: 100vh; margin: 0; padding: 0; }
body.app-layout { display: block; }

.app-sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: 220px;
  background: #fff;
  border-inline-end: 1px solid #ececec;
  display: flex;
  flex-direction: column;
  z-index: 30;
  overflow-y: auto;
}
.app-sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid #f0f0f0;
}
.app-sidebar-logo { width: 32px; height: 32px; border-radius: 8px; }
.app-sidebar-name { font-weight: 700; font-size: 16px; color: #222; }

.app-sidebar-nav {
  display: flex; flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  flex: 1;
}
.app-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  font-size: 14px;
  color: #555;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
}
.app-nav-item:hover { background: #f6f6f6; }
.app-nav-item.active {
  background: #fff5f0;
  color: var(--brand);
  font-weight: 600;
}
.app-nav-icon { font-size: 16px; width: 20px; display: inline-flex; justify-content: center; }

.app-sidebar-help { padding: 14px 16px; border-top: 1px solid #f0f0f0; }
.app-help-card {
  display: block;
  background: #fff5f0;
  border: 1px solid #ffe0d2;
  border-radius: 10px;
  padding: 12px 14px;
  text-decoration: none;
}
.app-help-title { font-size: 13px; color: #555; margin-bottom: 4px; }
.app-help-cta { color: var(--brand); font-weight: 600; font-size: 14px; }

.app-main {
  margin-inline-start: 220px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid #ececec;
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-hamburger {
  display: none;
  background: none;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 18px;
  cursor: pointer;
}
.app-page-title { font-size: 18px; margin: 0; font-weight: 700; }
.app-topbar-right { margin-inline-start: auto; display: flex; align-items: center; gap: 12px; }
.app-user-info { font-size: 13px; color: #555; }
.app-lang-switcher {
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 4px 8px;
  background: #fff;
  font-size: 13px;
}
.app-logout-btn {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.app-logout-btn:hover { background: #f6f6f6; }

.app-main > main,
.app-main > .container,
.app-main > section:not(.app-topbar) { padding-inline: 16px; }
.app-main > main { padding: 16px; }

.app-sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 25;
  display: none;
}
.app-sidebar-overlay.visible { display: block; }

@media (max-width: 900px) {
  /* Move the sidebar off-screen using inset-inline-start (a logical
     property) so RTL pushes it out the right edge and LTR pushes it
     out the left edge — without needing a separate transform rule. */
  .app-sidebar {
    inset-inline-start: -100%;
    transition: inset-inline-start 0.25s ease;
  }
  .app-sidebar.open { inset-inline-start: 0; }
  .app-main { margin-inline-start: 0; }
  .app-hamburger { display: inline-flex; align-items: center; justify-content: center; }
}

@media (max-width: 600px) {
  .app-topbar { padding: 0 14px; gap: 8px; }
  .app-page-title { font-size: 16px; }
  .app-user-info { display: none; }
  .app-main > main { padding: 14px; }
}

/* Hide the legacy in-page topbar — chrome.js owns layout now */
body.app-layout > header.topbar,
.app-main header.topbar { display: none; }

/* ===== Filter bar additions: date range, overdue toggle, export ===== */
.filter-date {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: #fff;
  color: #555;
}
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #555;
  user-select: none;
}
.filter-toggle input { display: none; }
.filter-toggle-track {
  position: relative;
  width: 36px; height: 20px;
  background: #d6d6d6;
  border-radius: 999px;
  transition: background 0.18s;
}
.filter-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.18s;
}
.filter-toggle input:checked + .filter-toggle-track { background: #c62828; }
.filter-toggle input:checked + .filter-toggle-track::after { transform: translateX(16px); }
[dir="rtl"] .filter-toggle input:checked + .filter-toggle-track::after { transform: translateX(-16px); }
.filter-toggle input:checked ~ .filter-toggle-label { color: #c62828; font-weight: 600; }

.export-btn {
  background: #fff;
  border: 1px solid #d8b4ff;
  color: #6b46c1;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.export-btn:hover { background: #f5efff; }

/* ===== Sortable table headers ===== */
.sortable {
  cursor: pointer;
  user-select: none;
}
.sortable:hover { background: #f6f6f6; }
.sort-arrow {
  display: inline-block;
  margin-inline-start: 6px;
  font-size: 11px;
  opacity: 0.35;
  color: #888;
}
.sortable.active .sort-arrow { opacity: 1; color: var(--brand); font-weight: 700; }

/* ===== Leads table: tighter density + horizontal scroll on narrow screens ===== */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.table-scroll > table {
  border: none;
  border-radius: 0;
  margin: 0;
}
#leads-table { font-size: 13px; }
#leads-table th,
#leads-table td {
  padding: 7px 10px;
  font-size: 13px;
  white-space: nowrap;
  vertical-align: top;
}
#leads-table th { font-size: 11px; }

/* Actions cell holds multiple buttons; let them wrap onto a second line
   on narrow screens instead of overflowing off the right edge. */
#leads-table td:last-child,
#leads-table th:last-child { white-space: normal; }
#leads-table td:last-child button {
  font-size: 12px;
  padding: 4px 8px;
  margin: 1px;
}

/* Source feature toggle: hide everything tagged .feature-source when off */
.feature-source-disabled .feature-source { display: none !important; }

/* Click-to-filter: clickable canvases get a hover hint */
.analytics-card.clickable .analytics-canvas-wrap { cursor: pointer; }
.analytics-card.clickable:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

#clear-filters-btn {
  background: #fff;
  border: 1px solid #e5e5e5;
  color: #555;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
#clear-filters-btn:hover { background: #f6f6f6; border-color: #c62828; color: #c62828; }
