/* ============================================================
   MotherBeast Dashboard — Claude Code Inspired Design System
   Warm terracotta on dark brown, cream text, monospace data
   ============================================================ */

/* --- CSS Variables ---------------------------------------- */
:root {
  --bg-primary: #1a1815;
  --bg-secondary: #201d18;
  --bg-tertiary: #2a2520;
  --bg-input: #151310;
  --bg-hover: #302b25;

  --text-primary: #e8e6e3;
  --text-secondary: #C4A584;
  --text-muted: #9e9488;
  --text-inverse: #1a1815;

  --accent: #C15F3C;
  --accent-hover: #D97757;
  --accent-muted: rgba(193, 95, 60, 0.15);
  --accent-glow: rgba(193, 95, 60, 0.3);

  --success: #98C379;
  --success-bg: rgba(152, 195, 121, 0.12);
  --warning: #E67D22;
  --warning-bg: rgba(230, 125, 34, 0.12);
  --danger: #ff6b6b;
  --danger-bg: rgba(255, 107, 107, 0.12);
  --info: #61AFEF;
  --info-bg: rgba(97, 175, 239, 0.12);

  --border: #2a2520;
  --border-hover: #3a3530;
  --border-accent: #C15F3C;

  --priority-critical: #ff4444;
  --priority-high: #E67D22;
  --priority-medium: #f0c040;
  --priority-low: #98C379;

  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 4px 20px rgba(193, 95, 60, 0.12);
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* --- Reset & Base ---------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }

/* --- Layout ---------------------------------------------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.sidebar-brand span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* --- Sidebar Search ---------------------------------------- */
.sidebar-search {
  padding: 8px 14px 4px;
}
.sidebar-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.sidebar-search-icon {
  position: absolute;
  left: 8px;
  color: var(--text-muted);
  pointer-events: none;
}
.sidebar-search-input {
  width: 100%;
  padding: 6px 10px 6px 28px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-family: var(--font-main);
  outline: none;
  transition: border-color var(--transition);
}
.sidebar-search-input::placeholder {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.sidebar-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}

.sidebar-nav {
  flex: 1;
  list-style: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover, .sidebar-nav a:focus-visible {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sidebar-nav a.active {
  color: var(--accent);
  background: var(--accent-muted);
  border-left-color: var(--accent);
}

.sidebar-nav .nav-icon {
  width: 24px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.main {
  flex: 1;
  margin-left: 220px;
  padding: 28px 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-header h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* --- Cards ----------------------------------------------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.card-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.2;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 4px;
}

/* Stat cards grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
}

.stat-card .stat-icon {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.stat-card .stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* --- Progress Bar ---------------------------------------- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Stacked status bar */
.status-bar {
  display: flex;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-tertiary);
}

.status-bar .seg-completed { background: var(--success); }
.status-bar .seg-pending { background: var(--warning); }
.status-bar .seg-error { background: var(--danger); }
.status-bar .seg-skipped { background: var(--text-muted); }

/* --- Priority & Flag Badges ----------------------------- */
.priority-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.priority-dot.critical { background: var(--priority-critical); box-shadow: 0 0 6px var(--priority-critical); }
.priority-dot.high { background: var(--priority-high); }
.priority-dot.medium { background: var(--priority-medium); }
.priority-dot.low { background: var(--priority-low); }

.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.priority-badge.critical { background: rgba(255, 68, 68, 0.15); color: var(--priority-critical); }
.priority-badge.high { background: rgba(230, 125, 34, 0.15); color: var(--priority-high); }
.priority-badge.medium { background: rgba(240, 192, 64, 0.15); color: var(--priority-medium); }
.priority-badge.low { background: rgba(152, 195, 121, 0.15); color: var(--priority-low); }

.flag-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.flag-pill.no-id { background: rgba(255, 68, 68, 0.2); color: var(--danger); }
.flag-pill.old-id { background: rgba(230, 125, 34, 0.2); color: var(--warning); }
.flag-pill.foreign { background: rgba(97, 175, 239, 0.2); color: var(--info); }
.flag-pill.company { background: rgba(196, 165, 132, 0.2); color: var(--text-secondary); }
.flag-pill.early { background: rgba(180, 130, 255, 0.2); color: #b482ff; }

/* Lead count badges (for dashboard) */
.lead-counts {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.lead-count {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lead-count .count {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
}

.lead-count .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

/* --- Tables ---------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  background: var(--bg-tertiary);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background-color var(--transition);
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody tr.clickable {
  cursor: pointer;
}

tbody tr.clickable:hover {
  background: var(--bg-hover);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* --- Sortable Table Headers ------------------------------ */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

th.sortable:hover {
  color: var(--text-primary);
}

th.sortable.sort-active {
  color: var(--accent);
}

th.sortable .sort-label {
  margin-right: 2px;
}

th.sortable .sort-arrow {
  font-size: 0.65rem;
  color: var(--accent);
}

.cell-mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.cell-rtl {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.cell-score {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}

/* --- Forms & Inputs -------------------------------------- */
input, select, textarea {
  font-family: var(--font-main);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color var(--transition);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238a8078' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
}

/* --- Buttons --------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.3);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.2);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled, .btn.htmx-request {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none;
}

/* Button inline spinner (htmx loading) */
.btn .btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.htmx-request .btn-spinner,
.btn.loading .btn-spinner {
  display: inline-block;
}

.htmx-request .btn-label,
.btn.loading .btn-label {
  opacity: 0.7;
}

/* --- Tabs (Alpine.js) ------------------------------------ */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 20px;
}

.tab-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-secondary);
  color: var(--accent);
  box-shadow: var(--shadow);
}

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

/* --- Upload Zone ----------------------------------------- */
.upload-zone {
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-zone:hover, .upload-zone-active {
  border-color: var(--accent);
  background: rgba(193, 95, 60, 0.08);
}

/* --- Toast Notifications --------------------------------- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 3s forwards;
  box-shadow: var(--shadow-lg);
}

.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(152, 195, 121, 0.3); }
.toast.error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(255, 107, 107, 0.3); }
.toast.warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(230, 125, 34, 0.3); }
.toast.info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(97, 175, 239, 0.3); }

@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* --- Health Badge ---------------------------------------- */
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.health-dot.valid { background: var(--success); box-shadow: 0 0 6px var(--success); }
.health-dot.expired { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* --- Extract Log ----------------------------------------- */
.extract-log {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  max-height: 400px;
  overflow-y: auto;
}

.extract-log .log-line {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.extract-log .log-line:last-child {
  border-bottom: none;
}

.extract-log .log-success { color: var(--success); }
.extract-log .log-error { color: var(--danger); }
.extract-log .log-warning { color: var(--accent); }
.extract-log .log-info { color: var(--text-muted); }

/* --- Keep/Deny Icon Buttons ------------------------------ */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  padding: 0;
  line-height: 1;
}

.btn-icon.btn-keep:hover {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(152, 195, 121, 0.4);
}

.btn-icon.btn-deny:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.4);
}

/* --- Ownership Breakdown --------------------------------- */
.ownership-counts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ownership-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

.ownership-pill.private { background: rgba(193, 95, 60, 0.15); color: var(--accent); }
.ownership-pill.public { background: rgba(97, 175, 239, 0.15); color: var(--info); }
.ownership-pill.mixed { background: rgba(240, 192, 64, 0.15); color: var(--priority-medium); }
.ownership-pill.other { background: rgba(138, 128, 120, 0.15); color: var(--text-muted); }

/* --- Login Page ------------------------------------------ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: 1.4rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

.login-card .error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.login-card input {
  margin-bottom: 16px;
}

.login-card .btn {
  width: 100%;
  justify-content: center;
  padding: 10px;
}

/* --- Utility Classes ------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hidden { display: none !important; }

/* --- Loading / htmx indicator ---------------------------- */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Notes History --------------------------------------- */
.notes-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}

.note-entry {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8rem;
  line-height: 1.5;
}

.note-bullet {
  width: 6px;
  height: 6px;
  min-width: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
}

.note-text {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* --- Status Badges (lead detail) ------------------------- */
.status-badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status-new { background: var(--info-bg); color: var(--info); }
.status-investigating { background: var(--success-bg); color: var(--success); }
.status-closed { background: rgba(180,130,255,0.15); color: #b482ff; }
.status-rejected { background: var(--danger-bg); color: var(--danger); }

/* --- Timeline (lead detail history) ---------------------- */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 8px 0;
  max-height: 350px;
  overflow-y: auto;
}

.timeline-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 12px;
  position: relative;
  font-size: 0.78rem;
  line-height: 1.5;
  border-left: 2px solid var(--border);
  margin-left: 6px;
}

.timeline-entry:last-child {
  border-left-color: transparent;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-top: 4px;
  position: relative;
  left: -17px;
  margin-right: -8px;
}

.timeline-text {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  word-break: break-word;
}

/* Status change entries */
.timeline-status .timeline-text {
  font-weight: 600;
}

.timeline-keep .timeline-dot { background: var(--success); }
.timeline-keep .timeline-text { color: var(--success); }

.timeline-dismiss .timeline-dot { background: var(--danger); }
.timeline-dismiss .timeline-text { color: var(--danger); }

.timeline-close .timeline-dot { background: #b482ff; }
.timeline-close .timeline-text { color: #b482ff; }

.timeline-reopen .timeline-dot { background: var(--info); }
.timeline-reopen .timeline-text { color: var(--info); }

/* Comment entries */
.timeline-comment .timeline-dot { background: var(--accent); }
.timeline-comment .timeline-text { color: var(--text-secondary); font-weight: 400; }

/* --- Company Card Popup ---------------------------------- */
.company-card-popup {
  animation: fadeIn 0.15s ease;
}
.company-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.company-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.company-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  flex: 1;
}
.company-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.company-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.company-card-row .label {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.company-card-row .value {
  font-size: 0.8rem;
  text-align: right;
}
.company-pill-clickable {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.company-pill-clickable:hover {
  filter: brightness(1.2);
}

/* --- Search Bar ------------------------------------------ */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-bar input {
  flex: 1;
  min-width: 0;
}

/* --- Block Tags ------------------------------------------ */
.block-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-muted);
  border: 1px solid var(--accent);
  color: var(--accent-hover);
  padding: 3px 8px 3px 10px;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 600;
}

.block-tag-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 1.1rem;
  line-height: 1;
  transition: color 0.15s;
}

.block-tag-remove:hover {
  color: var(--danger);
}

/* --- Modal Overlay / Popup ------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: modal-fade-in 0.2s ease;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  animation: modal-slide-in 0.25s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.modal-row:last-child { border-bottom: none; }
.modal-row .label { color: var(--text-muted); }
.modal-row .value { color: var(--text-primary); font-weight: 500; }
.modal-row .value.rtl { direction: rtl; text-align: right; }

/* ============================================================
   Unified form components for modals
   These deliberately use higher-specificity selectors
   (label.form-field, label.form-checkbox-row, etc.) so the
   global `label{}` rule's display:block + uppercase + 600 weight
   stops cascading into form rows that need flex layouts and
   normal text rendering.
   ============================================================ */

/* Size variants for modal-content */
.modal-content--sm { max-width: 420px; }
.modal-content--md { max-width: 560px; }
.modal-content--lg { max-width: 680px; }

/* Form container — vertical stack of fields */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Horizontal row of fields */
.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.form-row > .form-field { flex: 1 1 0; min-width: 0; }
.form-row > .form-field.is-narrow  { flex: 0 1 110px; }
.form-row > .form-field.is-grow-2  { flex: 2 1 0; }

/* A single labeled field — RESET label cascade */
label.form-field,
.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: inherit;
  font-weight: 400;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0;
  min-width: 0;
}

.form-field-label {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0;
}

.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="tel"],
.form-field input[type="url"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field input[type="search"],
.form-field input[type="password"],
.form-field select,
.form-field textarea,
.form-input {
  padding: 7px 10px;
  font-size: 0.86rem;
  font-family: var(--font-main);
  color: var(--text-primary);
  /* background-color (not shorthand) so the global select{} rule's
     background-image / repeat / position survive — otherwise the
     chevron arrow tiles across the whole select. */
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-field select { padding-right: 32px; }
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}
.form-field input[type="text"][dir="rtl"],
.form-field input.is-rtl { text-align: right; }
.form-field input.is-mono,
.form-field .is-mono { font-family: var(--font-mono); }
.form-field textarea { resize: vertical; min-height: 56px; }
.form-field-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Fieldset — replaces inline-styled fieldsets */
.form-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 10px 12px 12px;
  margin: 0;
}
.form-fieldset legend {
  padding: 0 6px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

/* Section header inside a form */
.form-section-head {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 4px 0 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* A checkbox row inside a form — fixes the heir modal "empty label" bug.
   Higher specificity (label.form-checkbox-row) defeats the global label{}
   rule that would otherwise force display:block + uppercase + 600 weight. */
label.form-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  font-size: 0.86rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-primary);
  margin-bottom: 0;
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: background var(--transition);
}
label.form-checkbox-row:hover { background: var(--bg-hover); }
label.form-checkbox-row input[type="checkbox"],
label.form-checkbox-row input[type="radio"] {
  flex: 0 0 auto;
  width: 16px; height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.form-checkbox-row-icon {
  display: inline-flex;
  color: var(--text-muted);
  flex: 0 0 auto;
}
.form-checkbox-row-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.form-checkbox-row-label.is-rtl {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}
.form-checkbox-row-kind {
  flex: 0 0 auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}
label.form-checkbox-row input[type="checkbox"]:checked ~ .form-checkbox-row-label,
label.form-checkbox-row input[type="radio"]:checked ~ .form-checkbox-row-label {
  color: var(--accent);
  font-weight: 500;
}

/* When a checkbox-row has a trailing select (task modal "Linked to"),
   the label should hug its content and the select gets the remaining width. */
label.form-checkbox-row:has(.form-checkbox-row-select) .form-checkbox-row-label {
  flex: 0 0 auto;
}
.form-checkbox-row-select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 26px 4px 8px;       /* room for the chevron */
  font-size: 0.78rem;
  background-color: var(--bg-input); /* not shorthand — keep chevron */
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  font-family: var(--font-main);
}
label.form-checkbox-row.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
label.form-checkbox-row.is-disabled input,
label.form-checkbox-row.is-disabled .form-checkbox-row-select {
  cursor: not-allowed;
}
.form-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  overflow-y: auto;
}

/* A row of compact inline action buttons (bottom of modal) */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.form-actions.has-danger {
  justify-content: space-between;
}
.form-actions-group {
  display: flex;
  gap: 8px;
}

/* --- Gush Autocomplete Dropdown -------------------------- */
.gush-autocomplete {
  position: relative;
}

.gush-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 2px;
  animation: dropdown-in 0.15s ease;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.gush-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.gush-dropdown-item:last-child { border-bottom: none; }

.gush-dropdown-item:hover {
  background: var(--accent-muted);
}

.gush-dropdown-item .gush-num {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
}

.gush-dropdown-item .gush-loc {
  color: var(--text-secondary);
  direction: rtl;
  flex: 1;
  text-align: right;
}

.gush-dropdown-item .gush-pending {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* --- Mobile ---------------------------------------------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: 60px;
    border-right: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    padding: 0;
    z-index: 100;
  }

  .sidebar-brand { display: none; }
  .sidebar-search { display: none; }
  .sidebar-footer { display: none; }

  .sidebar-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
  }

  .sidebar-nav a {
    flex-direction: column;
    padding: 8px 4px;
    font-size: 0.65rem;
    border-left: none;
    border-top: 3px solid transparent;
    gap: 2px;
  }

  .sidebar-nav a.active {
    border-left-color: transparent;
    border-top-color: var(--accent);
  }

  .sidebar-nav .nav-label { display: block; }

  .main {
    margin-left: 0;
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
  }

  .page-header h2 {
    font-size: 1.1rem;
  }

  /* Modal full-screen on phone */
  .modal-content, .modal-content--sm, .modal-content--md, .modal-content--lg {
    width: 100%; max-width: 100%; max-height: 95vh; border-radius: var(--radius-sm); padding: 16px;
  }

  /* Layout + touch polish */
  .page-header { flex-wrap: wrap; gap: 8px; }
  .filters, .filter-row, .flex.gap-2 { flex-wrap: wrap; }
  .btn, .btn-sm { min-height: 38px; }
  .topnav-notif .notif-bell, .topnav-user-btn { min-height: 40px; }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Sticky table headers for scrollable tables */
.table-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 2;
}

/* Resizable table columns */
.table-resizable th {
  position: relative;
  overflow: hidden;
}
.table-resizable th .col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
}
.table-resizable th .col-resizer:hover,
.table-resizable th .col-resizer.resizing {
  background: var(--accent);
}

/* Block grid layout */
.block-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.block-grid .card {
  margin-bottom: 0;
  height: 100%;
}

/* Multi-select tag input */
.tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 32px;
  align-items: center;
  cursor: text;
}
.tag-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}
.tag-input-wrap input,
.tag-input-wrap select {
  border: none;
  background: transparent;
  outline: none;
  box-shadow: none;
  flex: 1;
  min-width: 60px;
  padding: 2px 4px;
  font-size: 0.8rem;
  color: var(--text-primary);
  background-image: none;
}
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-muted);
  color: var(--accent-hover);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  white-space: nowrap;
}
.tag-pill .tag-remove {
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
}
.tag-pill .tag-remove:hover {
  opacity: 1;
  color: var(--danger);
}

/* Checkbox column for table */
.cell-check {
  width: 28px;
  text-align: center;
  padding: 0 4px !important;
}
.cell-check input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

/* Bulk actions bar — floating bottom bar */
.bulk-actions {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
.bulk-actions .bulk-count {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-hover);
}

/* Undo action in table */
.undo-link {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.75rem;
  text-decoration: underline;
}
.undo-link:hover {
  color: var(--accent-hover);
}

/* ============================================================
   Block Cards Grid — Leads page block view
   ============================================================ */

.tabs-row {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 2px solid var(--border);
}
.tab-item {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.tab-item:hover {
  color: var(--text-primary);
}
.tab-item.tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  background: var(--accent-muted);
  color: var(--accent);
  border-radius: 10px;
}

.block-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.block-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.block-card:hover {
  border-color: var(--accent-muted);
  box-shadow: 0 2px 12px rgba(193, 95, 60, 0.1);
}
.block-card.expanded {
  border-color: var(--accent);
  grid-column: 1 / -1;
  cursor: default;
}

.block-card-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.block-card-gush {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}
.block-card-locality {
  font-size: 0.85rem;
  color: var(--text-secondary);
  direction: rtl;
}

.block-card-stats {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.block-card-priorities {
  display: flex;
  gap: 8px;
  align-items: center;
}
.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}
.priority-badge.critical {
  color: var(--priority-critical);
}
.priority-badge.high {
  color: var(--priority-high);
}

/* Block row layout (leads page) */
.block-row {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.block-row:hover {
  border-color: var(--accent-muted);
  box-shadow: 0 1px 8px rgba(193, 95, 60, 0.08);
}
.block-row.expanded {
  border-color: var(--accent);
  cursor: default;
}
.block-row-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.block-card-expanded {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.block-card-expanded select {
  width: auto;
  padding: 3px 28px 3px 8px;
  font-size: 0.72rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

.block-leads-container table {
  font-size: 0.78rem;
}

/* Leads table inside block cards — compact style */
.leads-block-table {
  font-size: 0.78rem;
}
.leads-block-table th {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 4px 5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.leads-block-table td {
  padding: 4px 5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* ID Type and ID Number hidden via inline style in template */

/* ============================================================
   UI Polish — Accessibility, Skeletons, Scrollbars, States
   ============================================================ */

/* --- Custom Scrollbars ----------------------------------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}

/* --- Skeleton Loading ------------------------------------ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-hover) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton-line {
  height: 14px;
  margin-bottom: 8px;
  width: 100%;
}

.skeleton-line:last-child {
  width: 60%;
}

.skeleton-card {
  height: 100px;
  border-radius: var(--radius);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Empty States ---------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state-text {
  font-size: 0.85rem;
  max-width: 320px;
  line-height: 1.5;
}

/* --- Focus-visible for all interactive elements ---------- */
a:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
.tab-btn:focus-visible,
.tab-item:focus-visible,
.block-card:focus-visible,
.btn-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Improved btn-icon hover (Keep/Deny) ----------------- */
.btn-icon {
  position: relative;
}

.btn-icon::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.btn-icon:hover::after {
  opacity: 1;
}

/* Don't show tooltip if no title */
.btn-icon:not([title])::after {
  display: none;
}

/* --- Lead count badges hover ----------------------------- */
.lead-count {
  transition: border-color var(--transition), box-shadow var(--transition);
}

.lead-count:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}

/* --- Progress bar smooth fill transition ----------------- */
.status-bar > div {
  transition: width 0.5s ease;
}

/* --- Block card expanded animation ----------------------- */
.block-card-expanded {
  animation: expand-in 0.2s ease;
}

@keyframes expand-in {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 2000px; }
}

/* --- Reduced motion preference --------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Toast container improvements ------------------------ */
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
  max-width: 420px;
}

.toast-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
}

.toast-dismiss:hover {
  opacity: 1;
}

/* --- Breadcrumbs ----------------------------------------- */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  margin-bottom: 16px;
  color: var(--text-muted);
}

.breadcrumbs a {
  color: var(--text-muted);
  transition: color var(--transition);
}

.breadcrumbs a:hover {
  color: var(--accent);
}

.breadcrumbs .separator {
  color: var(--border-hover);
  font-size: 0.7rem;
}

.breadcrumbs .current {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ============================================================
   Theme Variants — switchable via data-theme on <html>
   Override only the CSS variables, everything else inherits.
   ============================================================ */

/* --- Theme: Premium Gold ----------------------------------- */
[data-theme="gold"] {
  --bg-primary: #0f0e0c;
  --bg-secondary: #1a1816;
  --bg-tertiary: #242120;
  --bg-input: #0a0908;
  --bg-hover: #2a2725;

  --text-primary: #f0ece8;
  --text-secondary: #c9b99a;
  --text-muted: #8a8178;

  --accent: #CA8A04;
  --accent-hover: #EAB308;
  --accent-muted: rgba(202, 138, 4, 0.15);
  --accent-glow: rgba(202, 138, 4, 0.25);

  --border: #242120;
  --border-hover: #3a3530;
  --border-accent: #CA8A04;

  --shadow-glow: 0 4px 20px rgba(202, 138, 4, 0.12);
}

/* --- Theme: Midnight Indigo -------------------------------- */
[data-theme="indigo"] {
  --bg-primary: #0c0c1a;
  --bg-secondary: #141428;
  --bg-tertiary: #1e1e38;
  --bg-input: #080812;
  --bg-hover: #262648;

  --text-primary: #e8e8f0;
  --text-secondary: #a0a0cc;
  --text-muted: #7878a0;

  --accent: #7C3AED;
  --accent-hover: #9B5AFF;
  --accent-muted: rgba(124, 58, 237, 0.15);
  --accent-glow: rgba(124, 58, 237, 0.25);

  --border: #1e1e38;
  --border-hover: #2e2e50;
  --border-accent: #7C3AED;

  --info: #818CF8;
  --info-bg: rgba(129, 140, 248, 0.12);

  --shadow-glow: 0 4px 20px rgba(124, 58, 237, 0.12);
}

/* --- Theme: Ocean Slate ------------------------------------ */
[data-theme="ocean"] {
  --bg-primary: #0B1120;
  --bg-secondary: #0F172A;
  --bg-tertiary: #1E293B;
  --bg-input: #070D18;
  --bg-hover: #283548;

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;

  --accent: #3B82F6;
  --accent-hover: #60A5FA;
  --accent-muted: rgba(59, 130, 246, 0.15);
  --accent-glow: rgba(59, 130, 246, 0.25);

  --success: #22C55E;
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #EF4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #38BDF8;
  --info-bg: rgba(56, 189, 248, 0.12);

  --border: #1E293B;
  --border-hover: #334155;
  --border-accent: #3B82F6;

  --priority-critical: #EF4444;
  --priority-high: #F59E0B;
  --priority-medium: #FBBF24;
  --priority-low: #22C55E;

  --shadow-glow: 0 4px 20px rgba(59, 130, 246, 0.12);
}

/* --- Theme: Ember (warm orange on charcoal) ---------------- */
[data-theme="ember"] {
  --bg-primary: #151210;
  --bg-secondary: #1c1816;
  --bg-tertiary: #282320;
  --bg-input: #100e0c;
  --bg-hover: #322b26;

  --text-primary: #f0ebe5;
  --text-secondary: #d4a574;
  --text-muted: #9c8a78;

  --accent: #F97316;
  --accent-hover: #FB923C;
  --accent-muted: rgba(249, 115, 22, 0.15);
  --accent-glow: rgba(249, 115, 22, 0.3);

  --border: #282320;
  --border-hover: #3a3430;
  --border-accent: #F97316;

  --shadow-glow: 0 4px 20px rgba(249, 115, 22, 0.12);
}

/* --- Theme: Sand (warm light) ------------------------------ */
[data-theme="sand"] {
  --bg-primary: #FAF7F2;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F0EBE3;
  --bg-input: #FFFFFF;
  --bg-hover: #EDE7DD;

  --text-primary: #2C2418;
  --text-secondary: #6B5B4A;
  --text-muted: #9A8B7A;
  --text-inverse: #FFFFFF;

  --accent: #B85C38;
  --accent-hover: #D4724E;
  --accent-muted: rgba(184, 92, 56, 0.1);
  --accent-glow: rgba(184, 92, 56, 0.15);

  --success: #3D8B37;
  --success-bg: rgba(61, 139, 55, 0.1);
  --warning: #C47F17;
  --warning-bg: rgba(196, 127, 23, 0.1);
  --danger: #C53030;
  --danger-bg: rgba(197, 48, 48, 0.08);
  --info: #2B6CB0;
  --info-bg: rgba(43, 108, 176, 0.08);

  --border: #E2DDD5;
  --border-hover: #D4CEC4;
  --border-accent: #B85C38;

  --priority-critical: #C53030;
  --priority-high: #C47F17;
  --priority-medium: #B7940A;
  --priority-low: #3D8B37;

  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 4px 16px rgba(184, 92, 56, 0.08);
}

/* --- Theme: Paper (clean light blue-gray) ------------------ */
[data-theme="paper"] {
  --bg-primary: #F8FAFC;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F1F5F9;
  --bg-input: #FFFFFF;
  --bg-hover: #E2E8F0;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  --accent: #2563EB;
  --accent-hover: #3B82F6;
  --accent-muted: rgba(37, 99, 235, 0.08);
  --accent-glow: rgba(37, 99, 235, 0.12);

  --success: #16A34A;
  --success-bg: rgba(22, 163, 74, 0.08);
  --warning: #D97706;
  --warning-bg: rgba(217, 119, 6, 0.08);
  --danger: #DC2626;
  --danger-bg: rgba(220, 38, 38, 0.06);
  --info: #0284C7;
  --info-bg: rgba(2, 132, 199, 0.06);

  --border: #E2E8F0;
  --border-hover: #CBD5E1;
  --border-accent: #2563EB;

  --priority-critical: #DC2626;
  --priority-high: #D97706;
  --priority-medium: #CA8A04;
  --priority-low: #16A34A;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 4px 16px rgba(37, 99, 235, 0.06);
}

/* --- Light theme fixes ------------------------------------- */
/* Select arrow needs darker stroke on light backgrounds */
[data-theme="sand"] select,
[data-theme="paper"] select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  /* Defensive: if a downstream rule used `background:` shorthand and
     reset repeat/position to defaults, this re-applies them so the
     chevron doesn't tile across the whole select. */
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* Input borders more visible on light */
[data-theme="sand"] input,
[data-theme="sand"] select,
[data-theme="sand"] textarea,
[data-theme="paper"] input,
[data-theme="paper"] select,
[data-theme="paper"] textarea {
  border-color: var(--border-hover);
}

/* Sticky table headers match light surface */
[data-theme="sand"] .table-wrap thead th,
[data-theme="paper"] .table-wrap thead th {
  background: var(--bg-tertiary);
}

/* Sidebar slightly tinted on light */
[data-theme="sand"] .sidebar {
  background: #F0EBE3;
  border-right-color: #E2DDD5;
}

[data-theme="paper"] .sidebar {
  background: #F1F5F9;
  border-right-color: #E2E8F0;
}

/* Health dot glow toned down */
[data-theme="sand"] .health-dot.valid,
[data-theme="paper"] .health-dot.valid {
  box-shadow: 0 0 4px var(--success);
}

[data-theme="sand"] .health-dot.expired,
[data-theme="paper"] .health-dot.expired {
  box-shadow: 0 0 4px var(--danger);
}

/* Priority dot glow toned down */
[data-theme="sand"] .priority-dot.critical,
[data-theme="paper"] .priority-dot.critical {
  box-shadow: 0 0 4px var(--priority-critical);
}

/* Modal overlay lighter */
[data-theme="sand"] .modal-overlay,
[data-theme="paper"] .modal-overlay {
  background: rgba(0, 0, 0, 0.4);
}

/* Scrollbar lighter */
[data-theme="sand"],
[data-theme="paper"] {
  scrollbar-color: var(--border-hover) transparent;
}

[data-theme="sand"] ::-webkit-scrollbar-thumb,
[data-theme="paper"] ::-webkit-scrollbar-thumb {
  background: var(--border-hover);
}

/* --- Theme Picker Component -------------------------------- */
.theme-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 90px;
}

.theme-swatch:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
}

.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.theme-swatch-colors {
  display: flex;
  gap: 3px;
  height: 24px;
}

.theme-swatch-colors span {
  width: 20px;
  height: 24px;
  border-radius: 3px;
}

.theme-swatch-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ================================================================
   Hot Leads — Star Button
   ================================================================ */
.btn-star {
  font-size: 1rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: all var(--transition);
  border-radius: var(--radius-sm);
}

.btn-star.starred {
  color: #f0c040;
  text-shadow: 0 0 6px rgba(240, 192, 64, 0.4);
}

.btn-star:hover {
  color: #f0c040;
  background: rgba(240, 192, 64, 0.1);
}

/* ================================================================
   Notification Bell
   ================================================================ */
.notif-bell {
  position: relative;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  display: inline-flex;
  align-items: center;
}

.notif-bell:hover {
  color: var(--text-primary);
}

.notif-count {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--danger);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  font-family: var(--font-mono);
  line-height: 1;
}

/* ================================================================
   Notification Dropdown
   ================================================================ */
.notif-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 200;
  margin-bottom: 8px;
}

.notif-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.notif-list {
  max-height: 340px;
  overflow-y: auto;
}

.notif-item {
  display: block;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition);
}

.notif-item:hover {
  background: rgba(255, 255, 255, 0.03);
  text-decoration: none;
  color: var(--text-secondary);
}

.notif-item.unread {
  border-left: 3px solid var(--accent);
  background: rgba(193, 95, 60, 0.05);
}

.notif-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
}

.notif-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.notif-message {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  direction: rtl;
}

/* ============================================================
   Shared case-tab toolbar / group-by widgets
   These were previously duplicated in each tab partial's <style>
   block, which meant htmx swaps between tabs lost the styles.
   Live here so they persist across tab swaps.
   ============================================================ */

/* Toolbar row at the top of a tab (matches case_detail.html tab strip) */
.tasks-toolbar,
.expenses-toolbar,
.deceased-toolbar,
.heirs-toolbar,
.cit-toolbar,
.docs-toolbar,
.chrono-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tasks-toolbar-hint,
.expenses-toolbar-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
}
/* "Show completed / Show paid" pill toggle — must beat the global label{} */
label.tasks-toolbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-bottom: 0;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-tertiary);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--transition), color var(--transition);
}
label.tasks-toolbar-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}
label.tasks-toolbar-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
  width: 14px;
  height: 14px;
}

/* Group-by chips widget (shared by Tasks, Expenses, all-tasks-expenses, Cases) */
.tasks-group-by-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.tasks-group-by-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.62rem;
  display: inline-block;
  font-weight: 600;
  margin-bottom: 0;
  color: var(--text-muted);
}
.tasks-group-by-chips {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.tasks-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-muted);
  border: 1px solid rgba(193, 95, 60, 0.40);
  border-radius: 12px;
  padding: 2px 4px 2px 10px;
  font-family: inherit;
  font-size: 0.74rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
}
.tasks-group-chip:hover { background: rgba(193, 95, 60, 0.22); }
.tasks-group-chip-label { color: var(--accent); font-weight: 500; }
.tasks-group-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  font-weight: 600;
  border: none;
}
.tasks-group-chip-x:hover { background: rgba(224, 108, 117, 0.20); color: #e06c75; }
.tasks-group-by-add {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 2px 10px;
  font-family: inherit;
  font-size: 0.74rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}
.tasks-group-by-add:hover { border-color: var(--accent); color: var(--accent); }

/* ================================================================
   TOP NAVIGATION  (replaces sidebar; legacy .sidebar-* rules kept above
   for safe rollback — unused while .topnav is in base.html)
   ================================================================ */

/* Layout: stack topnav above main, drop the sidebar offset */
.app { flex-direction: column; }
.main { margin-left: 0; padding: 24px 32px; }

.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(26, 24, 21, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
[data-theme="sand"] .topnav,
[data-theme="paper"] .topnav {
  background: rgba(244, 241, 234, 0.92);
}

.topnav-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 24px;
  max-width: 1800px;
  margin: 0 auto;
}

/* Brand */
.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex-shrink: 0;
}
.topnav-brand:hover { text-decoration: none; color: var(--text-primary); }
.topnav-logo {
  width: 32px;
  height: 32px;
  display: block;
  flex: none;
}
/* Blackletter wordmark */
.topnav-name {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.5px;
}

/* Primary links */
.topnav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 18px;
}
.topnav-links a,
.topnav-more-btn {
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  line-height: 1.4;
}
.topnav-links a:hover,
.topnav-more-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.topnav-links a:focus-visible,
.topnav-more-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.topnav-links a.active,
.topnav-more-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}

/* "More" dropdown */
.topnav-more { position: relative; }
.topnav-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.topnav-menu a {
  display: block;
  padding: 8px 12px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-decoration: none;
  border-radius: 5px;
  transition: background var(--transition), color var(--transition);
  font-weight: 500;
}
.topnav-menu a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.topnav-menu a.active {
  color: var(--accent);
  background: var(--accent-muted);
}

/* Right cluster */
.topnav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Search box */
.topnav-search {
  position: relative;
  display: flex;
  align-items: center;
}
.topnav-search svg {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.topnav-search input {
  padding: 7px 12px 7px 32px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: var(--font-main);
  outline: none;
  width: 240px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.topnav-search input::placeholder { color: var(--text-muted); }
.topnav-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
  width: 280px;
}

/* Health badge in top bar — compact */
.topnav-health {
  display: flex;
  align-items: center;
  padding: 0 4px;
  cursor: default;
}
.topnav-health .health-badge { font-size: 0.7rem; }

/* Notification bell wrapper */
.topnav-notif { position: relative; }

/* Notif dropdown override — flip to open DOWNWARD from top nav */
.topnav-notif-dropdown {
  bottom: auto;
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  margin-bottom: 0;
}

/* User pill */
.topnav-user { position: relative; }
.topnav-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  font-family: var(--font-main);
}
.topnav-user-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-hover);
}
.topnav-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}
.topnav-username {
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topnav-user-menu {
  right: 0;
  left: auto;
}

/* Mobile — collapse to a tighter row, hide search, hide username text */
@media (max-width: 1100px) {
  .topnav-search input { width: 160px; }
  .topnav-search input:focus { width: 200px; }
}
@media (max-width: 880px) {
  .topnav-inner { gap: 10px; padding: 9px 14px; }
  .topnav-links { gap: 0; margin-left: 6px; }
  .topnav-links a, .topnav-more-btn { padding: 7px 8px; font-size: 0.82rem; }
  .topnav-search { display: none; }
  .topnav-username { display: none; }
  .topnav-brand .topnav-name { display: none; }
}

/* ================================================================
   MOBILE HAMBURGER + DRAWER  (<=768px)
   ================================================================ */
.topnav-hamburger { display: none; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); }
.topnav-drawer, .topnav-drawer-backdrop { display: none; }
.topnav-drawer-sep { height: 1px; background: var(--border); margin: 6px 0; }
@media (min-width: 769px) { .topnav-drawer, .topnav-drawer-backdrop, .topnav-hamburger { display: none !important; } }
@media (max-width: 768px) {
  .topnav-hamburger { display: inline-flex; align-items: center; margin-left: auto; }
  .topnav-links { display: none; }
  .topnav-search { display: none; }
  .topnav-drawer-backdrop { position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.5); z-index: 90; }
  .topnav-drawer { position: fixed; top: 56px; left: 0; right: 0; z-index: 95; display: flex; flex-direction: column;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 10px; gap: 2px; max-height: calc(100vh - 56px); overflow-y: auto; }
  .topnav-drawer a { padding: 12px 12px; border-radius: var(--radius-sm); color: var(--text-primary); text-decoration: none; font-size: 0.95rem; }
  .topnav-drawer a.active { color: var(--accent); background: var(--accent-muted); }
  .topnav-drawer-search input { width: 100%; padding: 10px 12px; margin-bottom: 6px; background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary); border-radius: var(--radius-sm); }
}

/* ===== Dashboard command center (sleek & deep, theme-aware) ===== */
.dash { display: flex; flex-direction: column; gap: 16px; }

/* --- KPI strip: flat inline stats, grouped by subject (restrained accent tie-in) --- */
.dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.dash-kpi-groups { border: 1px solid var(--border); border-radius: var(--radius, 8px); background: var(--bg-secondary); padding: 4px 20px; margin-bottom: 4px; }
.dash-kpi-group { display: flex; align-items: flex-start; gap: 24px; padding: 15px 0; border-bottom: 1px solid var(--border); }
.dash-kpi-group:last-child { border-bottom: 0; }
/* (1) group label picks up the accent — mirrors the widget-head icons below */
.dash-kpi-group-title { flex: 0 0 80px; margin: 0; padding-top: 4px; font-size: 0.58rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; color: var(--accent); }
.dash-kpi-group-row { display: flex; flex-wrap: wrap; flex: 1; min-width: 0; }
.dash-kpi { display: block; padding-right: 26px; margin-right: 26px; border-right: 1px solid var(--border); text-decoration: none; color: inherit; }
.dash-kpi:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.dash-kpi-val { font-family: var(--font-mono, ui-monospace, monospace); font-size: 1.55rem; font-weight: 700; line-height: 1; color: var(--text-primary); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.dash-kpi-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 7px; }
.dash-kpi-sub { color: var(--text-muted); font-variant-numeric: tabular-nums; }
/* (2) clickable stat — accent label + arrow, matching the "All →" widget links */
.dash-kpi--link .dash-kpi-label { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); }
.dash-kpi--link .dash-kpi-sub { color: var(--accent); opacity: 0.85; }
.dash-kpi-arrow { font-size: 0.9em; }
.dash-kpi--link:hover .dash-kpi-val { color: #fff; }
/* (3) the single thin progress bar — accent fill */
.dash-kpi-bar { margin-top: 8px; height: 3px; width: 120px; border-radius: 999px; background: var(--border); overflow: hidden; }
.dash-kpi-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transform-origin: left; animation: dash-grow .9s cubic-bezier(.2,.8,.2,1) both; }
@media (max-width: 760px) {
  .dash-kpi-group { flex-direction: column; gap: 10px; }
  .dash-kpi-group-title { flex: none; padding-top: 0; }
}

/* --- 3-column grid --- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: start; }
.dash-grid--2col { grid-template-columns: 1.55fr 1fr; }
@media (max-width: 900px) { .dash-grid--2col { grid-template-columns: 1fr; } }
.dash-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* --- Widget cards (glass) --- */
.dash-widget {
  padding: 16px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: transform .18s ease, box-shadow .18s ease;
}
.dash-widget:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover), inset 0 1px 0 rgba(255,255,255,0.06); }
.dash-widget--feed { max-height: 640px; overflow-y: auto; }
.dash-widget--feed:hover { transform: none; }
.dash-widget-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 0.74rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-primary); margin: -2px 0 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.dash-widget-head-l { display: inline-flex; align-items: center; gap: 8px; }
.dash-widget-head-l svg { color: var(--accent); }
.dash-widget-link { font-size: 0.7rem; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--accent); }

/* --- Lists (work queue / tasks) --- */
.dash-list { display: flex; flex-direction: column; }
.dash-list-row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text-primary); border-radius: var(--radius-sm); transition: background .14s ease, transform .14s ease; }
.dash-list-row:hover { background: var(--accent-muted); transform: translateX(2px); }
.dash-list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dash-list-title { font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-list-sub { font-size: 0.72rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.dash-list-score { font-size: 0.82rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; text-shadow: 0 0 12px var(--accent-glow); }
.dash-badge { font-size: 0.6rem; font-weight: 800; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.dash-prio-critical { background: var(--priority-critical); color:#fff; }
.dash-prio-high { background: var(--priority-high); color:#fff; }
.dash-prio-medium { background: var(--priority-medium); color:#1c1714; }
.dash-prio-low { background: var(--priority-low); color:#1c1714; }
.dash-empty { padding: 22px 6px; text-align: center; color: var(--text-secondary); font-size: 0.82rem; }
.dash-task-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.dash-task-dot.is-overdue { background: var(--priority-critical); box-shadow: 0 0 8px var(--priority-critical); }
.dash-task-due { font-size: 0.72rem; font-weight: 700; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash-task-due.is-overdue { color: var(--priority-critical); }
.task-highlight { animation: task-flash 2.4s ease; outline: 2px solid var(--accent); outline-offset: -2px; }
@keyframes task-flash { 0% { background: var(--accent-muted); } 100% { background: transparent; } }

/* --- Charts --- */
.dash-chart { margin-bottom: 16px; } .dash-chart:last-child { margin-bottom: 0; }
.dash-chart-title { font-weight: 700; font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 10px; }
.dash-bar-row, .dash-funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.dash-bar-label { width: 64px; font-size: 0.72rem; color: var(--text-secondary); flex: none; }
.dash-bar-track { flex: 1; height: 9px; background: var(--border); border-radius: 999px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.25); }
.dash-bar-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); box-shadow: 0 0 10px var(--accent-glow); transform-origin: left; animation: dash-grow .9s cubic-bezier(.2,.8,.2,1) both; }
.dash-bar-val { width: 34px; text-align: right; font-size: 0.76rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.dash-funnel-bar { background: linear-gradient(90deg, var(--accent-hover), var(--accent)); color:#fff; font-size:0.72rem; font-weight:800; padding: 5px 10px; border-radius: 7px; white-space: nowrap; box-shadow: 0 0 12px var(--accent-glow); font-variant-numeric: tabular-nums; animation: dash-kpi-in .6s ease both; }

.dash-quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

@keyframes dash-grow { from { transform: scaleX(0); opacity:.4; } to { transform: scaleX(1); opacity:1; } }
@keyframes dash-kpi-in { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

@media (max-width: 980px) {
  .dash-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .dash-kpi, .dash-bar-fill, .dash-funnel-bar, .dash-kpi-bar > span { animation: none !important; }
  .dash-kpi:hover, .dash-widget:hover, .dash-list-row:hover { transform: none; }
}

/* Block/parcel chips (case detail hero + edit modal) */
.parcel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.parcel-chip { display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px; border: 1px solid var(--border);
  border-radius: 6px; font-variant-numeric: tabular-nums; }
.parcel-chip-x { border: 0; background: none; color: var(--text-muted, #8a8076);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.parcel-chip-x:hover { color: var(--danger, #e06c75); }
.case-delete-btn:hover { color: var(--danger, #e06c75); border-color: var(--danger, #e06c75); }

/* Group-by / inline-edit popover (the menu is position:fixed, appended to body).
   Defined globally so pages without an inline copy (e.g. All Tasks & Expenses)
   still get a styled, above-the-sticky-header menu. Sticky thead is z-index 2. */
.cell-edit-pop {
  z-index: 1000;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55);
  padding: 4px;
  max-height: 280px;
  overflow-y: auto;
  font-family: inherit;
  display: flex;
  flex-direction: column;
}
.cell-edit-pop-item {
  background: transparent;
  border: none;
  text-align: left;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cell-edit-pop-item:hover,
.cell-edit-pop-item.is-focus {
  background: var(--bg-hover);
  color: var(--accent);
}
.cell-edit-pop-item.is-current {
  background: rgba(193,95,60,0.10);
  font-weight: 500;
}
.cell-edit-pop-item.is-current.is-focus,
.cell-edit-pop-item.is-current:hover { background: var(--bg-hover); }

tr.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-muted, rgba(110,168,254,0.08)); }

/* Keep-alive toggle chip in the top nav (next to the auth badge) */
.keepalive-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 8px;
  padding: 3px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
}
.keepalive-toggle:hover { background: rgba(127, 127, 127, 0.08); }
