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

:root {
  /* Sidebar */
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e7eb;
  --sidebar-text: #6b7280;
  --sidebar-text-hover: #111827;
  --sidebar-text-active: #111827;
  --sidebar-active-bg: #eef0ff;
  --sidebar-width: 240px;

  /* Content area */
  --content-bg: #f5f6fa;
  --card-bg: #ffffff;
  --topbar-bg: #ffffff;

  /* Text */
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  /* Borders */
  --border: #e5e7eb;
  --border-light: #f3f4f6;

  /* Accent */
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);

  /* Status */
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;

  /* Misc */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-topbar: 0 1px 0 var(--border);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Legacy aliases (used by chat bubble, etc.) */
  --bg-secondary: #f3f4f6;
  --bg-card: #ffffff;
  --border-glass: var(--border);
  --border-accent: var(--accent);
}

html { font-size: 14px; }

/* ─── Global Form Elements ──────────────────────────────────────────── */
input, select, textarea, button {
  border-radius: var(--radius-sm);
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font);
  font-size: 0.82rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

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

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

/* ─── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  height: 64px;
  border-bottom: 1px solid var(--sidebar-border);
  text-decoration: none;
}
.logo-img {
  height: 100%;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.logo-text {
  font-size: 0.9rem; font-weight: 700;
  color: #111827;
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-text);
  padding: 1rem 0.75rem 0.3rem;
  opacity: 0.5;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all var(--transition);
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  letter-spacing: 0.005em;
}
.nav-item:hover {
  color: var(--sidebar-text-hover);
  background: rgba(255,255,255,0.06);
}
.nav-item.active {
  color: var(--accent);
  background: var(--sidebar-active-bg);
  font-weight: 600;
  border-left: 2px solid var(--accent);
  padding-left: calc(0.75rem - 2px);
}
.nav-item.active .nav-icon { color: var(--accent); opacity: 1; }
.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--sidebar-text);
  opacity: 0.8;
  transition: color var(--transition), opacity var(--transition);
}
.nav-item:hover .nav-icon { opacity: 1; color: var(--sidebar-text-hover); }

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-footer .meta-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 0.5rem;
  line-height: 1.4;
}
.btn-logout-sidebar {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: none; border: none;
  font-family: var(--font); font-size: 0.82rem; font-weight: 500;
  cursor: pointer; width: 100%; text-align: left;
  transition: all var(--transition);
}
.btn-logout-sidebar:hover { color: var(--text-primary); background: #f3f4f6; }

/* ─── Main Content ──────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-topbar);
}
.topbar-title {
  font-size: 1rem; font-weight: 600;
  color: var(--text-primary);
}
.topbar-right {
  display: flex; align-items: center; gap: 0.875rem;
}
.meta-text { color: var(--text-muted); font-size: 0.78rem; }

/* ─── Main Area ─────────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 1.75rem 2rem;
  max-width: 1440px;
  width: 100%;
}

.tab-panel { display: none; animation: fadeIn 0.25s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.panel-header { margin-bottom: 1.5rem; }
.panel-header h2 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text-primary); }
.subtitle { color: var(--text-secondary); font-size: 0.875rem; margin-top: 0.25rem; }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(99,102,241,0.3);
}
.btn-secondary {
  background: var(--card-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border-light); color: var(--text-primary); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-icon { font-size: 1rem; }
.btn-row { display: flex; gap: 0.75rem; margin-top: 1rem; }

/* ─── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.375rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.25rem;
}
.card h3 {
  font-size: 0.9rem; font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* ─── KPI Cards ─────────────────────────────────────────────────────── */
.kpi-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 1.75rem;
}
.kpi-label {
  font-size: 0.72rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem;
  font-weight: 600;
}
.kpi-value { font-size: 1.875rem; font-weight: 800; color: var(--accent); }
.kpi-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.375rem; line-height: 1.4; }
.kpi-small { font-size: 1rem; font-weight: 600; }

/* ─── Tables ────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

#new-arr-revenue-table {
  table-layout: fixed;
  min-width: 1100px;
}
#new-arr-revenue-table th:first-child,
#new-arr-revenue-table td:first-child { width: 140px; }
#new-arr-revenue-table th:not(:first-child):not(:nth-last-child(-n+2)),
#new-arr-revenue-table td:not(:first-child):not(:nth-last-child(-n+2)) { width: 72px; }
#new-arr-revenue-table th:nth-last-child(2),
#new-arr-revenue-table td:nth-last-child(2) { width: 100px; }
#new-arr-revenue-table th:last-child,
#new-arr-revenue-table td:last-child { width: 60px; }

#new-arr-owner-table,
#new-arr-country-table { table-layout: fixed; }
#new-arr-owner-table th:first-child, #new-arr-owner-table td:first-child,
#new-arr-country-table th:first-child, #new-arr-country-table td:first-child { width: 180px; }
#new-arr-owner-table th:not(:first-child):not(:last-child),
#new-arr-owner-table td:not(:first-child):not(:last-child),
#new-arr-country-table th:not(:first-child):not(:last-child),
#new-arr-country-table td:not(:first-child):not(:last-child) { width: 120px; }
#new-arr-owner-table th:last-child, #new-arr-owner-table td:last-child,
#new-arr-country-table th:last-child, #new-arr-country-table td:last-child { width: 60px; }

thead tr { background: #f9fafb; }
thead th {
  padding: 0.6rem 0.75rem;
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}
.table-note {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-style: italic;
}

.warning-banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #fff8e1;
  border: 1px solid #f5c842;
  border-left: 4px solid #f5c842;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.82rem;
  color: #7a5c00;
  line-height: 1.5;
}
.warning-banner::before {
  content: "⚠";
  font-size: 1rem;
  flex-shrink: 0;
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: #fafbff; }
tbody tr.row-total {
  font-weight: 700;
  background: #f5f6ff;
  border-top: 1px solid var(--border);
}
tbody tr.row-goal { color: var(--success); }
tbody tr.row-section-header {
  font-weight: 700;
  color: var(--accent);
  background: #f5f6ff;
}
.cell-positive { color: var(--success); font-weight: 600; }
.cell-negative { color: var(--danger); font-weight: 600; }
.cell-warning { color: var(--warning); }
.cell-muted { color: var(--text-muted); }
.cell-right { text-align: right; }
.cell-highlight { background: #fff3e0; color: #e65100; font-weight: 600; }

/* ─── Chart Containers ──────────────────────────────────────────────── */
.chart-container { position: relative; height: 300px; width: 100%; }
.chart-container canvas { max-height: 100%; }

/* ─── Grid Layouts ──────────────────────────────────────────────────── */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ─── Filter Bar ────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
}
.filter-group {
  display: flex; flex-direction: column; gap: 0.3rem;
  flex: 1; min-width: 140px;
}
.filter-group label {
  font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted);
}
.filter-group select,
.filter-group input[type="text"],
.filter-bar select,
.filter-bar input[type="text"],
.chart-builder-controls select,
.chart-builder-controls input[type="text"] {
  width: 100%;
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font); font-size: 0.82rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.filter-group select:focus,
.filter-group input[type="text"]:focus,
.filter-bar select:focus,
.filter-bar input[type="text"]:focus,
.chart-builder-controls select:focus,
.chart-builder-controls input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.filter-group input::placeholder,
.filter-bar input::placeholder,
.chart-builder-controls input::placeholder { color: var(--text-muted); }
.filter-bar .btn { align-self: flex-end; white-space: nowrap; }

/* ─── Goals Editor ──────────────────────────────────────────────────── */
#goals-editor {
  width: 100%;
  background: #f9fafb;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  resize: vertical; line-height: 1.5;
}
#goals-editor:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Badge ─────────────────────────────────────────────────────────── */
.badge {
  padding: 0.2rem 0.65rem;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* ─── Chart Builder ─────────────────────────────────────────────────── */
.chart-builder-controls {
  display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
}
.chart-builder-controls .filter-group { flex: 1; min-width: 140px; }

/* ─── Report Generator ──────────────────────────────────────────────── */
.report-generator-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.5rem; }
.report-filter-wide { grid-column: 1 / -1; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-top: 0.4rem; }
.checkbox-label {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.82rem; color: var(--text-secondary); cursor: pointer;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); }

.chart-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem; margin-bottom: 0.5rem;
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: var(--radius-sm); flex-wrap: wrap;
}
.chart-row select, .chart-row input[type="text"] {
  flex: 1; min-width: 100px;
  padding: 0.35rem 0.6rem;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: 0.8rem; width: auto;
}
.chart-row-remove {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: 0 0.25rem; flex-shrink: 0;
}
.chart-row-remove:hover { color: var(--danger); }

/* ─── Report Section Cards ───────────────────────────────────────────── */
.report-block-label {
  display: block; font-size: 0.75rem; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
}
.report-section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.6rem;
}
.report-section-card {
  position: relative; display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.75rem 0.875rem; border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
  background: var(--card-bg); user-select: none;
}
.report-section-card:hover { border-color: var(--accent-light); background: var(--accent-glow); }
.report-section-card.is-checked { border-color: var(--accent); background: var(--accent-glow); }
.report-section-card input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.report-section-card .section-icon {
  color: var(--text-muted); margin-bottom: 0.25rem; display: flex;
  transition: color 0.15s;
}
.report-section-card.is-checked .section-icon { color: var(--accent); }
.report-section-card .section-name {
  font-size: 0.82rem; font-weight: 700; color: var(--text-primary); transition: color 0.15s;
}
.report-section-card.is-checked .section-name { color: var(--accent); }
.report-section-card .section-desc {
  font-size: 0.72rem; font-weight: 400; color: var(--text-muted); line-height: 1.35;
}
.report-section-card.is-checked .section-desc { color: var(--accent); opacity: 0.75; }

/* ─── Report Filter Bar ──────────────────────────────────────────────── */
.report-filter-bar {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem;
  align-items: flex-end; margin-top: 1.25rem;
}
.report-filter-bar .filter-group { flex: 0 0 auto; }

/* ─── Report Quarter Buttons ─────────────────────────────────────────── */
.report-q-btns { display: flex; gap: 0.35rem; margin-top: 0.35rem; }
.report-q-btn { padding: 0.3rem 0.65rem; font-size: 0.77rem; }

/* ─── Chat Message Bubbles ──────────────────────────────────────────── */
.chat-message { display: flex; }
.chat-message-user { justify-content: flex-end; }
.chat-message-assistant { justify-content: flex-start; }
.message-bubble {
  max-width: 78%; padding: 0.6rem 0.9rem;
  border-radius: var(--radius); font-size: 0.86rem;
  line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.chat-message-user .message-bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.chat-message-assistant .message-bubble {
  background: #f3f4f6; border: 1px solid var(--border);
  color: var(--text-primary); border-bottom-left-radius: 4px;
}
.message-thinking { display: flex; align-items: center; gap: 5px; padding: 0.7rem 1rem; min-height: 38px; }
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); animation: dotBounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}
.chat-send-btn { flex-shrink: 0; align-self: flex-end; }
.chat-error { color: var(--danger); font-size: 0.8rem; }

/* ─── Floating Chat Bubble ──────────────────────────────────────────── */
.chat-bubble-btn {
  position: fixed; bottom: 48px; right: 32px;
  width: 58px; height: 58px; border-radius: 50%;
  background: none;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(100,0,220,0.45); z-index: 1000;
  transition: transform 0.2s, box-shadow 0.2s;
  padding: 0; overflow: hidden;
}
.chat-bubble-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(100,0,220,0.6); }
.chat-bubble-logo { width: 58px; height: 58px; display: block; flex-shrink: 0; object-fit: contain; border-radius: 50%; background: #fff; padding: 6px; }

.chat-bubble-panel {
  position: fixed; bottom: 112px; right: 32px;
  width: 480px; height: calc(100vh - 120px); max-height: 780px; min-height: 500px;
  background: #ffffff; border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 8px 40px rgba(0,0,0,0.14);
  z-index: 999; display: flex; flex-direction: column; overflow: hidden;
}
.hidden { display: none !important; }

.chat-bubble-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.875rem 1rem; border-bottom: 1px solid var(--border);
  background: #181c2e; flex-shrink: 0;
}
#chat-bubble-title { font-weight: 600; font-size: 0.875rem; flex: 1; color: #fff; }
.chat-bubble-username { font-size: 0.72rem; color: var(--accent-light); }
#chat-bubble-close {
  background: none; border: none; color: rgba(255,255,255,0.5);
  cursor: pointer; font-size: 1.4rem; padding: 0; line-height: 1;
}
#chat-bubble-close:hover { color: #fff; }

.chat-name-prompt {
  display: flex; flex-direction: column; align-items: stretch;
  justify-content: center; flex: 1 1 0; gap: 1rem; padding: 2rem; text-align: center;
  min-height: 0;
}
.chat-name-prompt p { color: var(--text-secondary); font-size: 0.95rem; margin: 0; }
.chat-name-prompt input {
  padding: 0.6rem 0.875rem;
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary); font-size: 0.9rem;
  width: 100%; box-sizing: border-box;
}
.chat-name-prompt input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

#chat-bubble-body { display: flex; flex-direction: column; flex: 1 1 0; overflow: hidden; min-height: 0; }

.chat-bubble-messages {
  flex: 1; overflow-y: auto; padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.5rem; min-height: 0;
}

.chat-bubble-input-area {
  display: flex; gap: 0.5rem; padding: 0.75rem 1rem;
  border-top: 1px solid var(--border); align-items: flex-end; flex-shrink: 0;
  background: #fafafa;
}
.chat-bubble-input-area textarea {
  flex: 1; padding: 0.5rem 0.75rem;
  background: #ffffff; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary); font-size: 0.85rem;
  resize: none; max-height: 80px; font-family: inherit;
}
.chat-bubble-input-area textarea:focus { outline: none; border-color: var(--accent); }

/* ─── Multi-Select Dropdown ─────────────────────────────────────────── */
.multiselect { position: relative; }
.multiselect-btn {
  width: 100%; text-align: left;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.45rem 0.75rem;
  cursor: pointer; font-size: 0.82rem; color: var(--text-primary);
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem; font-family: var(--font);
  transition: border-color var(--transition);
}
.multiselect-btn:hover { border-color: var(--accent); }
.multiselect-btn .ms-caret { color: var(--text-muted); font-size: 0.65rem; flex-shrink: 0; transition: transform 0.15s; }
.multiselect.open .ms-caret { transform: rotate(180deg); }
.multiselect-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 400;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  min-width: 100%; width: max-content; max-width: 260px;
  max-height: 220px; overflow-y: auto;
}
.multiselect-option {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.38rem 0.75rem; cursor: pointer; font-size: 0.82rem;
  color: var(--text-primary); user-select: none;
  transition: background var(--transition);
}
.multiselect-option:hover { background: #f5f6fa; }
.multiselect-option input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.multiselect-divider { border: none; border-top: 1px solid var(--border); margin: 2px 0; }

/* ─── Footer ────────────────────────────────────────────────────────── */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 2rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
  background: var(--card-bg);
}

/* ─── Hamburger Button ──────────────────────────────────────────────── */
.hamburger-btn {
  display: none;
  align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  padding: 0.375rem; color: var(--text-primary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background var(--transition);
}
.hamburger-btn:hover { background: var(--border-light); }

/* ─── Sidebar Overlay ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 190;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* ─── SQL Deficit Section ───────────────────────────────────────────── */
.deficit-summary-bar {
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: #3730a3;
  line-height: 1.5;
}

.deficit-card {
  padding: 1rem 1.125rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.55;
}
.deficit-card--red {
  background: #fef2f2;
  border: 1px solid #fecaca;
}
.deficit-card--green {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}
.deficit-card-title {
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 0.4rem;
}
.deficit-card--red .deficit-card-title { color: #b91c1c; }
.deficit-card--green .deficit-card-title { color: #15803d; }
.deficit-card-body {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.deficit-card--red .deficit-card-body { color: #dc2626; }
.deficit-card--green .deficit-card-body { color: #16a34a; }

.deficit-flag { font-size: 1rem; vertical-align: middle; margin-right: 0.25rem; }

.accion-badge {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.accion-ok {
  background: #dcfce7;
  color: #15803d;
}
.accion-urgent {
  background: #fee2e2;
  color: #b91c1c;
}
.accion-critical {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 700;
}

.cell-muted { color: var(--text-muted); font-weight: 400; font-size: 0.85em; }

/* ─── Sidebar transition ────────────────────────────────────────────── */
.sidebar {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .hamburger-btn { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }
  .sidebar.sidebar-open { transform: translateX(0); }

  .main-content { margin-left: 0; }
  .topbar { padding: 0.75rem 1rem; }
  .main { padding: 1rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.5rem; }
  .report-generator-grid { grid-template-columns: 1fr; }
  .report-filter-wide { grid-column: auto; }

  .footer { flex-direction: column; gap: 0.25rem; text-align: center; padding: 0.875rem 1rem; }

  /* Chat bubble full-screen on mobile */
  .chat-bubble-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    border-radius: 0;
    border: none;
  }
  .chat-bubble-btn {
    bottom: 20px;
    right: 16px;
    width: 52px; height: 52px;
  }
  .chat-bubble-logo { width: 50px; height: 50px; }
}

@media (max-width: 480px) {
  .topbar-right .meta-text { display: none; }
  .topbar-right .badge { display: none; }
  .panel-header h2 { font-size: 1.125rem; }
  .kpi-value { font-size: 1.25rem; }
  .kpi-card { padding: 1.25rem; }
  .card { padding: 1rem; }
  .filter-bar { gap: 0.75rem; }
  .btn-row { flex-wrap: wrap; }
  .btn { padding: 0.5rem 0.875rem; }
}

/* ─── Overview: Executive Summary KPI Grid ──────────────────────────── */
.summary-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-top: 0.5rem;
}

.summary-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}

.summary-card:hover { box-shadow: var(--shadow-md); }

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

.summary-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
  margin: 0.25rem 0;
}

.summary-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  min-height: 1.5rem;
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2em 0.55em;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-up   { background: #dcfce7; color: #15803d; }
.badge-down { background: #fee2e2; color: #b91c1c; }
.badge-neutral { background: #fef9c3; color: #a16207; }

.summary-card-sub {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 0.125rem;
}

.summary-loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-muted);
  padding: 3rem 0;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .summary-kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .summary-kpi-grid { grid-template-columns: 1fr; }
  .summary-card-value { font-size: 1.5rem; }
}

/* ─── Status Badges (achievement tables) ────────────────────────────── */
.status-badge {
  display: inline-flex; align-items: center;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  font-size: 0.68rem; font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.status-ok     { background: #dcfce7; color: #15803d; }
.status-risk   { background: #fef9c3; color: #a16207; }
.status-behind { background: #fee2e2; color: #b91c1c; }

.row-subtotal td { font-weight: 600; border-top: 1px solid var(--border, #e5e7eb); background: #f8f9fa; }
.row-section-header td { font-weight: 700; background: #f1f3f5; color: #6b7280; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── People Tab ───────────────────────────────────────── */
.people-selector{display:flex;gap:.5rem;flex-wrap:wrap;align-items:center;margin-bottom:1.5rem}
.people-group{display:flex;align-items:center;gap:.4rem}
.people-group+.people-group{margin-left:.75rem;padding-left:.75rem;border-left:1px solid #e5e7eb}
.people-group-label{font-size:.68rem;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:var(--text-muted)}
.people-btn{padding:.35rem .9rem;border-radius:999px;border:2px solid #e5e7eb;background:white;font-size:.83rem;font-weight:600;cursor:pointer;transition:var(--transition);color:var(--text-secondary)}
.people-btn:hover{border-color:var(--accent);color:var(--accent)}
.people-btn.active{border-color:transparent;color:white}
.person-hero{display:flex;align-items:center;gap:1.5rem;background:var(--card-bg);padding:1.5rem 2rem;border-radius:var(--radius);box-shadow:var(--shadow-card);margin-bottom:1.25rem}
.person-avatar{width:68px;height:68px;border-radius:50%;object-fit:cover;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-size:1.4rem;font-weight:800;color:white}
.person-hero-info{flex:1}
.person-name{font-size:1.35rem;font-weight:700;color:var(--text-primary)}
.person-role-badge{display:inline-block;font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.05em;padding:.18rem .6rem;border-radius:999px;margin-top:.3rem}
.person-role-ae{background:#eef0ff;color:var(--accent)}
.person-role-sdr{background:#dcfce7;color:var(--success)}
.person-hero-metric{text-align:right}
.person-hero-metric-value{font-size:1.75rem;font-weight:800;color:var(--text-primary);line-height:1.1}
.person-hero-metric-label{font-size:.7rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.04em;margin-bottom:.35rem}
.person-kpi-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(155px,1fr));gap:1rem;margin-bottom:1.25rem}
.person-kpi-card{background:var(--card-bg);border-radius:var(--radius);padding:1.1rem 1.2rem;box-shadow:var(--shadow-card)}
.person-kpi-label{font-size:.68rem;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:var(--text-muted);margin-bottom:.35rem}
.person-kpi-value{font-size:1.35rem;font-weight:800;color:var(--text-primary);line-height:1.1}
.person-kpi-sub{font-size:.73rem;color:var(--text-secondary);margin-top:.3rem}
.progress-bar-wrap{height:6px;background:#f1f5f9;border-radius:3px;overflow:hidden;margin-top:.5rem}
.progress-bar-fill{height:100%;border-radius:3px;transition:width .6s ease}
.person-grid{display:grid;grid-template-columns:1fr 1fr;gap:1.25rem}
@media(max-width:900px){.person-grid{grid-template-columns:1fr}}
.person-card{background:var(--card-bg);border-radius:var(--radius);padding:1.25rem;box-shadow:var(--shadow-card)}
.person-card h4{font-size:.78rem;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:var(--text-muted);margin-bottom:1rem}
.person-mini-table{width:100%;border-collapse:collapse;font-size:.82rem}
.person-mini-table th{text-align:left;padding:5px 4px;color:var(--text-muted);font-weight:600;font-size:.68rem;text-transform:uppercase}
.person-mini-table th.r{text-align:right}
.person-mini-table td{padding:7px 4px;border-top:1px solid #f1f5f9}
.person-mini-table td.r{text-align:right;font-weight:600}
.person-mini-table td.muted{color:var(--text-secondary)}

/* ─── Audit Notes ──────────────────────────────────────────────────── */
.btn-audit{display:flex;align-items:center;gap:.4rem;padding:.4rem .9rem;border-radius:6px;border:1.5px solid var(--border);background:white;color:var(--text-secondary);font-size:.82rem;font-weight:600;cursor:pointer;transition:var(--transition)}
.btn-audit:hover{border-color:var(--accent);color:var(--accent)}
.btn-audit.active{background:var(--accent);border-color:var(--accent);color:white}
/* Section-level hover in audit mode */
body.audit-mode .card:hover,body.audit-mode .table-wrapper:hover{outline:2px dashed rgba(99,102,241,.4);outline-offset:1px;cursor:crosshair}
/* Amount-level hover in audit mode */
body.audit-mode td.cell-right:hover,body.audit-mode td.r:hover,body.audit-mode .kpi-value:hover{outline:2px solid var(--accent);outline-offset:1px;cursor:crosshair;border-radius:3px}
.notes-count-chip{display:inline-flex;align-items:center;justify-content:center;min-width:16px;height:16px;padding:0 4px;font-size:.68rem;font-weight:700;background:var(--danger);color:white;border-radius:999px;margin-left:.25rem}
.notes-panel{position:fixed;top:0;right:0;width:320px;height:100vh;background:var(--card-bg);border-left:1px solid var(--border);box-shadow:-4px 0 24px rgba(0,0,0,.08);z-index:600;transform:translateX(100%);transition:transform .25s ease;display:flex;flex-direction:column}
.notes-panel.open{transform:translateX(0)}
.notes-panel-overlay{position:fixed;inset:0;background:rgba(0,0,0,.25);z-index:590;opacity:0;pointer-events:none;transition:opacity .25s}
.notes-panel-overlay.open{opacity:1;pointer-events:auto}
.notes-panel-header{display:flex;align-items:center;justify-content:space-between;padding:.9rem 1.1rem;border-bottom:1px solid var(--border);font-weight:700;font-size:.95rem;color:var(--text-primary)}
.notes-panel-close{background:none;border:none;font-size:1.3rem;cursor:pointer;color:var(--text-muted);line-height:1;padding:.1rem .3rem}
.notes-panel-close:hover{color:var(--text-primary)}
.notes-panel-body{flex:1;overflow-y:auto;padding:.75rem}
.notes-panel-item{padding:.8rem .9rem;border-radius:8px;border:1.5px solid var(--border);margin-bottom:.6rem;cursor:pointer;transition:border-color .15s,box-shadow .15s}
.notes-panel-item:hover{border-color:var(--accent);box-shadow:0 2px 8px rgba(99,102,241,.12)}
.notes-panel-item-high{border-left:4px solid var(--danger)}
.notes-panel-item-medium{border-left:4px solid var(--warning)}
.notes-panel-item-low{border-left:4px solid var(--success)}
.notes-panel-item-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:.35rem}
.notes-panel-section{font-size:.8rem;font-weight:700;color:var(--text-primary);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.notes-panel-priority{font-size:.65rem;font-weight:700;text-transform:uppercase;letter-spacing:.05em;padding:.15rem .5rem;border-radius:999px;margin-left:.5rem;flex-shrink:0}
.notes-priority-high{background:#fee2e2;color:var(--danger)}
.notes-priority-medium{background:#fef3c7;color:var(--warning)}
.notes-priority-low{background:#dcfce7;color:var(--success)}
.notes-panel-text{font-size:.82rem;color:var(--text-secondary);line-height:1.45;margin-bottom:.3rem}
.notes-panel-footer{display:flex;align-items:center;justify-content:space-between;margin-top:.35rem}
.notes-panel-date{font-size:.7rem;color:var(--text-muted)}
.notes-panel-item-actions{display:flex;gap:.3rem}
.notes-action-btn{background:none;border:1px solid var(--border);border-radius:4px;cursor:pointer;font-size:.7rem;padding:.15rem .45rem;color:var(--text-muted);transition:background .15s,color .15s,border-color .15s;line-height:1.4}
.notes-action-btn:hover{background:var(--bg-hover)}
.notes-done-btn:hover{background:#dcfce7;color:var(--success);border-color:var(--success)}
.notes-delete-btn:hover{background:#fee2e2;color:var(--danger);border-color:var(--danger)}
.notes-panel-item-done{opacity:.5}
.notes-panel-item-done .notes-panel-text{text-decoration:line-through}
.notes-panel-item-done .notes-panel-section{text-decoration:line-through}
.note-modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:700;align-items:center;justify-content:center}
.note-modal{background:white;border-radius:12px;width:420px;max-width:calc(100vw - 2rem);box-shadow:0 8px 40px rgba(0,0,0,.18);display:flex;flex-direction:column}
.note-modal-header{display:flex;align-items:center;justify-content:space-between;padding:.9rem 1.2rem;border-bottom:1px solid var(--border);font-weight:700;font-size:.95rem}
.note-modal-close{background:none;border:none;font-size:1.4rem;cursor:pointer;color:var(--text-muted);line-height:1;padding:.1rem .3rem}
.note-modal-close:hover{color:var(--text-primary)}
.note-modal-body{padding:1rem 1.2rem;display:flex;flex-direction:column}
.note-modal-footer{display:flex;align-items:center;gap:.6rem;padding:.8rem 1.2rem;border-top:1px solid var(--border)}
.note-label{font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:var(--text-muted);margin-bottom:.3rem}
.note-input{width:100%;padding:.5rem .7rem;border:1.5px solid var(--border);border-radius:6px;font-size:.85rem;color:var(--text-primary);outline:none;transition:border-color .15s}
.note-input:focus{border-color:var(--accent)}
.note-textarea{width:100%;padding:.5rem .7rem;border:1.5px solid var(--border);border-radius:6px;font-size:.85rem;color:var(--text-primary);resize:vertical;outline:none;font-family:inherit;transition:border-color .15s}
.note-textarea:focus{border-color:var(--accent)}
.note-priority-row{display:flex;gap:.5rem}
.note-priority-btn{flex:1;padding:.4rem;border:1.5px solid var(--border);border-radius:6px;background:white;font-size:.8rem;font-weight:600;cursor:pointer;transition:border-color .15s,background .15s}
.note-priority-btn:hover{border-color:var(--accent)}
.note-priority-btn.active{border-color:var(--accent);background:var(--accent-glow);color:var(--accent)}
.btn-danger{background:#fee2e2;color:var(--danger);border:1.5px solid #fecaca}
.btn-danger:hover{background:#fecaca}

/* ─── Conversion Funnel (Events Tab, Phase 3) ───────────────────────── */
.cf-sal-note {
  font-size: .65rem;
  color: var(--text-secondary, #64748b);
  margin-top: .4rem;
  white-space: nowrap;
  font-style: italic;
}


