/* Global chrome + base element styles shared by every page. */

* { box-sizing: border-box; }

/*
 * Light/dark theme tokens. assets/js/theme.js toggles [data-theme="dark"] on <html> (and
 * persists the choice in localStorage) — every color below is consumed via var() so the
 * whole app repaints from this one switch. Not used by login.php, which has its own
 * standalone background and no theme toggle.
 */
:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --text-muted: #444;
  --surface: #ffffff;
  --surface-alt: #f5f5f5;
  --stripe: #fafafa;
  --border: #ddd;
  --border-strong: #ccc;
  --nav-hover-bg: #f2f4f8;
  --nav-active-bg: #e8edfc;
  --status-ok-bg: #e6f6ea;
  --status-ok-border: #34a853;
  --status-fail-bg: #fdecea;
  --status-fail-border: #d93025;
  --pill-bg: #d3ddf3;
  --pill-color: #1b3a6b;
  --pill-border: #aec0e6;
  --overlay-bg: rgba(255, 255, 255, .75);
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --text: #e7e9ec;
  --text-muted: #a7adba;
  --surface: #1c1f24;
  --surface-alt: #242830;
  --stripe: #1a1d22;
  --border: #333844;
  --border-strong: #444a58;
  --nav-hover-bg: #242830;
  --nav-active-bg: #1e2c4d;
  --status-ok-bg: #163a25;
  --status-ok-border: #2f8f4d;
  --status-fail-bg: #3a1c1a;
  --status-fail-border: #d9453a;
  --pill-bg: #23304d;
  --pill-color: #a9c1f5;
  --pill-border: #33487a;
  --overlay-bg: rgba(20, 22, 26, .75);
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }

.page {
  margin: 0 auto;
  padding: 1rem 2rem 2rem;
}

/* Status banners */
.status { padding: .75rem 1rem; border-radius: 6px; margin-bottom: .5rem; }
.ok { background: var(--status-ok-bg); border: 1px solid var(--status-ok-border); }
.fail { background: var(--status-fail-bg); border: 1px solid var(--status-fail-border); }

/* Base table look, reused by every data table in the app */
table { border-collapse: collapse; width: 100%; margin-top: 1rem; font-size: .9rem; }
th, td { border: 1px solid var(--border); padding: .5rem .6rem; text-align: left; vertical-align: top; }
th { background: var(--surface-alt); font-weight: 600; }
tr:nth-child(even) { background: var(--stripe); }

/*
 * The sortable.js CDN theme (sortable-tablesort) sets its own header/stripe colors via CSS
 * custom properties on .sortable. ".page .sortable" outranks its own ".sortable" selector on
 * specificity, so this wins regardless of whether app.css or the CDN stylesheet loads first —
 * matches the site's normal table colors instead of the library's default gray/stripe theme.
 * Referencing our own theme tokens here means dark mode reaches sortable.js's tables too.
 */
.page .sortable {
  --th-bg: var(--surface-alt);
  --th-color: var(--text);
  --stripe-bg: var(--stripe);
  --stripe-color: var(--text);
  --stripe-bg-odd: var(--surface);
  --stripe-color-odd: var(--text);
}

/*
 * sortable.js also hardcodes "thead th { font-weight: normal }" (not a CSS variable, so the
 * override above doesn't touch it) at specificity (.sortable thead th) — this needs to be at
 * least as specific to win, so it matches ".page .sortable" above rather than the plain "th"
 * rule further up.
 */
.page .sortable thead th {
  font-weight: 600;
}

/* Generic section divider, e.g. between mailchimp.php's search results and its stats section. */
.divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/*
 * Collapsible column group — global_search.php's "Mostrar columnas de viajes SW" checkbox toggles
 * this class on the results table (assets/js/global-search-columns.js) to hide its CF USD/Nro
 * Files/Último Viaje/Último Destino columns without a page reload, since those are only meaningful
 * for the SW-matched rows and can be clutter when most results aren't SW matches.
 */
.hide-sw-travel-cols .col-sw-travel { display: none; }

/*
 * ApexCharts' donut/pie legend (e.g. mailchimp.php's audiences chart) — renderPieChart()'s legend
 * formatter (assets/js/charts.js) puts a literal "\n" between the series name and its value/%, but
 * the library's legend text is a plain <span> that collapses whitespace by default. pre-line makes
 * that \n actually break the line instead of getting swallowed.
 */
.apexcharts-legend-text { white-space: pre-line !important; line-height: 1.5; vertical-align: middle; }
.apexcharts-legend-series { display: flex !important; align-items: center; }

code { background: var(--surface-alt); padding: 1px 5px; border-radius: 3px; }

details { margin: 0; }
details > summary { cursor: pointer; color: #1a56db; font-size: .85rem; }

/*
 * index.php's tool-picker cards. flex (not grid) so 3 cards (non-admin) or 4 (admin, "Usuarios"
 * included) both stay on one row, each taking an equal share of the width — a fixed
 * grid-template-columns count would need to vary by is_admin(), flex doesn't care how many
 * children there are.
 */
.dashboard-cards { display: flex; gap: 1.25rem; margin-top: 1.5rem; }
.dashboard-card {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.dashboard-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, .12); border-color: var(--border-strong); }
.dashboard-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1b3a6b 0%, #0b1c3d 100%);
  color: #fff;
}
.dashboard-card h3 { margin: 0; font-size: 1.05rem; }
.dashboard-card p { margin: 0; font-size: .85rem; color: var(--text-muted); }

/* Small "big number" stat cards, e.g. dashboard.php's per-source counts. */
.stat-cards { display: flex; gap: 1.25rem; margin-top: 1.5rem; flex-wrap: wrap; }
.stat-card {
  flex: 0 1 180px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
}
.stat-card-label { font-size: .85rem; color: var(--text-muted); margin-bottom: .5rem; }
.stat-card-value { font-size: 2.25rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card-error { margin-top: .5rem; font-size: .8rem; color: var(--status-fail-border); }

/*
 * "Ver detalles" toggle below dashboard.php's stat cards — a plain <details>, so open/close needs
 * no JS. The summary is styled as a .pill-btn (list-style/marker suppressed so it doesn't also show
 * the browser's own disclosure triangle); which of the two label spans is visible flips purely via
 * the [open] attribute selector, swapping "Ver detalles" for "Ocultar detalles" once expanded.
 */
.dashboard-details { margin-top: 1.5rem; }
.dashboard-details summary { margin-bottom: .75rem; list-style: none; }
.dashboard-details summary::-webkit-details-marker { display: none; }
.dashboard-details .details-label-open { display: none; }
.dashboard-details[open] .details-label-closed { display: none; }
.dashboard-details[open] .details-label-open { display: inline; }

/*
 * Row of chart columns below a results/stats table (mailchimp.php's audiences chart,
 * global_search.php's summary chart) — each column holds one chart + its own centered title, so
 * more charts can be added as siblings later without touching this layout. Was mailchimp.php-only
 * (assets/css/mailchimp.css) until global_search.php needed the same layout too.
 */
.chart-columns { display: flex; flex-wrap: wrap; gap: 2rem; margin-top: 1.75rem; }
.chart-column { flex: 1 1 320px; max-width: 480px; }
.chart-column h2 { text-align: center; margin-bottom: .5rem; }

/* Filter/search forms, reused by any page with a "type something, click a button" form */
form.filters { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
form.filters label { display: block; font-size: .85rem; margin-bottom: .3rem; color: var(--text-muted); }
form.filters input[type=text],
form.filters input[type=email],
form.filters select {
  padding: .5rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: .9rem;
  width: 160px;
  background: var(--surface);
  color: var(--text);
}
form.filters input[type=text].wide { width: 320px; }

/*
 * Any form.filters control that sits inline (no label-above-input column of its own — e.g. the
 * "Cruzar con HubSpot" checkbox below, or hubspot_leads.php's quick-date-range button) needs a
 * spacer to line up with the text fields: form.filters' align-items: flex-end lines up each
 * field's INPUT (not the label above it) with the Buscar button's bottom, so a bare centered
 * control lands too high — centering against the whole label+input column pulls the middle
 * upward by the label's height. .filters-inline-spacer is an invisible label — reusing
 * `form.filters label`'s own sizing so it's guaranteed to match exactly — that occupies the same
 * height as a real label, so whatever follows it starts at the same vertical offset the inputs do.
 */
.filters-inline-spacer { visibility: hidden; }

/* "Cruzar con HubSpot" checkbox in busqueda_sw.php's search form. */
.filters-checkbox { display: flex; flex-direction: column; padding-top: .3rem; }
.filters-checkbox-inline { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.filters-checkbox-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .6rem;
  margin-bottom: 0;
  font-size: .9rem;
  color: var(--text);
  cursor: pointer;
}
.filters-checkbox input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

/*
 * global_search.php's per-source Todos/Sí/No filters (assets/js/global-search-filters.js) — one
 * small card per source, reusing .stat-cards/.stat-card (dashboard.php's own stat tiles) rather
 * than a new card component, with a Todos/Sí/No radio group standing in for each card's usual
 * big number. .source-filter-cards trims the standalone .stat-cards margin-top since this section
 * already has spacing from what's above it (the error banners / results count).
 *
 * These cards get their own (shorter) padding rather than .stat-card's default 1.5rem all round —
 * a radio row is much shorter than a stat card's big number, so the same vertical padding just
 * left dead space. flex: 0 0 auto (rather than .stat-card's own 0 1 180px) stops the card from
 * being squeezed narrower than its content needs, which is what was pushing "No" onto its own
 * line — the card now sizes to fit "Todos"/"Sí"/"No" on one row instead of shrinking to a fixed
 * basis and wrapping.
 */
.source-filter-cards .stat-card { flex: 0 0 auto; padding: .6rem 1rem; }
.source-filter-options { display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: center; gap: .6rem; margin-top: .5rem; }
.source-filter-options label { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--text); cursor: pointer; white-space: nowrap; }
.source-filter-options input[type=radio] { width: 15px; height: 15px; cursor: pointer; }

form.filters button:not(.filters-icon-btn),
.btn {
  position: relative;
  z-index: 0;
  display: inline-block;
  padding: .55rem 1.2rem;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(135deg, #1b3a6b 0%, #0b1c3d 100%);
  color: #fff;
  font-size: .9rem;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s ease, box-shadow .15s ease;
}
/*
 * A CSS gradient can't be smoothly transitioned directly (browsers don't interpolate between
 * two different gradients), so the "animated hover" is a second gradient layer that fades in
 * via opacity — that animates perfectly. z-index: -1 keeps it behind the button's own text.
 */
form.filters button:not(.filters-icon-btn)::after,
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(135deg, #2c5090 0%, #16305c 100%);
  opacity: 0;
  transition: opacity .25s ease;
}
form.filters button:not(.filters-icon-btn):hover,
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
form.filters button:not(.filters-icon-btn):hover::after,
.btn:hover::after { opacity: 1; }

/* "All fields" detail table, reused by any page listing HubSpot records (rendered inside a modal) */
.detail-block { margin: .6rem 0 .2rem; }
.detail-table { margin-top: 0; font-size: .85rem; }
.detail-table th { width: 220px; background: var(--surface-alt); }

/* Text-styled trigger button, e.g. to open the "all fields" modal */
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: #1a56db;
  cursor: pointer;
  font-size: .85rem;
  text-decoration: underline;
}
.link-button:hover { color: #1442ad; }

/* Row of pill-style actions in a table cell (e.g. Editar/Ver logins/Ver búsquedas/Eliminar in users.php) */
.table-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.table-actions form { margin: 0; display: contents; }

.pill-btn {
  position: relative;
  z-index: 0;
  display: inline-flex;
  align-items: center;
  padding: .3rem .85rem;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-color);
  border: 1px solid var(--pill-border);
  font-size: .72rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease;
}
.pill-btn::after {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(135deg, #1b3a6b 0%, #0b1c3d 100%);
  opacity: 0;
  transition: opacity .2s ease;
}
.pill-btn:hover { color: #fff; border-color: #0b1c3d; }
.pill-btn:hover::after { opacity: 1; }

/* "Ficha HubSpot" trigger in the Detalles column (hubspot_leads.php / busqueda_hubspot.php) */
:root[data-theme="dark"] .pill-btn-fields { color: #fff; }

/* Match/no-match indicator: busqueda_sw.php's Hubspot column and busqueda_hubspot.php's SW column */
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status-dot-ok { background: var(--status-ok-border); }
.status-dot-fail { background: var(--status-fail-border); }
.status-dot-unknown { background: var(--text-muted); }

/*
 * Keeps a status-dot and the pill button beside it (busqueda_sw.php's Hubspot/Mailchimp columns,
 * busqueda_hubspot.php's/hubspot_leads.php's SW column, dashboard.php's/global_search.php's
 * match columns, etc.) from wrapping onto separate lines when their table column narrows — the
 * dot and button are just two adjacent inline elements otherwise, with an ordinary break
 * opportunity in the whitespace between them.
 */
td:has(.status-dot) { white-space: nowrap; }

/*
 * Full-page loading overlay shown by assets/js/search-loading.js while a form.filters submit is
 * navigating away — covers pages like busqueda_sw.php where the server-side work (e.g. the
 * HubSpot batch match) can take several seconds, so the page doesn't just sit blank/unresponsive.
 */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  background: var(--overlay-bg);
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid var(--border-strong);
  border-top-color: #1b3a6b;
  animation: loading-spin .8s linear infinite;
}
:root[data-theme="dark"] .loading-spinner { border-top-color: #6f93d6; }
@keyframes loading-spin { to { transform: rotate(360deg); } }
.loading-overlay-text { color: var(--text-muted); font-size: .9rem; }

/* users.php create/edit modal form — explicit rows (Nombre / Email / Usuario+Contraseña / Nivel) */
.user-form { display: flex; flex-direction: column; gap: 1rem; }
.user-form-row { display: flex; gap: 1rem; }
.user-form-row > div { flex: 1; display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.user-form label { font-size: .85rem; color: var(--text-muted); }
.user-form input[type=text],
.user-form input[type=email],
.user-form input[type=password],
.user-form select {
  padding: .5rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: .9rem;
  width: 100%;
  background: var(--surface);
  color: var(--text);
}
.user-form button[type=submit] { align-self: flex-start; margin-top: .3rem; }

/* Password field with a show/hide toggle (eye icon) */
.password-wrapper { position: relative; display: flex; }
.password-wrapper input { padding-right: 2.3rem; }
.toggle-password {
  position: absolute;
  right: .4rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  padding: .2rem;
  line-height: 0;
  color: var(--text-muted);
  cursor: pointer;
}
.toggle-password:hover { color: var(--text); }

/* Confirm dialog (window.confirmModal(), assets/js/modal.js) */
.modal-confirm-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }
.btn-cancel {
  background: var(--nav-hover-bg);
  color: var(--text-muted);
  border: 0;
  padding: .55rem 1.2rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
}
.btn-cancel:hover { background: var(--border); }
.btn-danger {
  background: linear-gradient(135deg, #e0453a 0%, #b3261e 100%);
  color: #fff;
  border: 0;
  padding: .55rem 1.2rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
}
.btn-danger:hover { background: linear-gradient(135deg, #c8392f 0%, #8f1e18 100%); }

/* Modal dialog (assets/js/modal.js) */
body.modal-open { overflow: hidden; }
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { margin: 0; font-size: 1.05rem; }
.modal-close {
  background: none;
  border: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: .25rem .5rem;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  overflow-x: auto;
}
.modal-body .detail-table { width: 100%; }
.modal-body h4 { margin: 1rem 0 .4rem; font-size: .95rem; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1.5rem;
  padding: .6rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}

.topbar .brand { display: flex; align-items: center; }
.topbar .brand img { height: 28px; width: auto; display: block; }
/* The logo is navy-on-transparent, unreadable on a dark background — brightness(0) flattens
   it to a black silhouette (keeping its transparency), then invert(1) flips that to white. */
:root[data-theme="dark"] .topbar .brand img { filter: brightness(0) invert(1); }

/*
 * #nav-toggle (the hamburger button) only renders visibly under the mobile media query below —
 * above it, .topbar-collapse (nav + topbar-user) just sits inline next to the brand, same layout
 * as before this was ever split into two pieces. See assets/js/nav-toggle.js for the toggle logic
 * and the "@media (max-width: 768px)" block further down for the collapsed/dropdown version.
 */
#nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.nav-toggle-icon.icon-close { display: none; }
#nav-toggle[aria-expanded="true"] .nav-toggle-icon.icon-menu { display: none; }
#nav-toggle[aria-expanded="true"] .nav-toggle-icon.icon-close { display: block; }

.topbar-collapse { display: flex; align-items: center; gap: 1.5rem; flex: 1; min-width: 0; }

.topbar nav { display: flex; gap: .25rem; margin-left: 1rem; }
.topbar nav a {
  padding: .45rem .9rem;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .9rem;
  transition: background-color .18s ease, color .18s ease;
}
.topbar nav a:hover { background: var(--nav-hover-bg); color: var(--text); }
.topbar nav a.active { background: var(--nav-active-bg); color: #1a56db; font-weight: 600; }
:root[data-theme="dark"] .topbar nav a.active { color: #fff; }

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .6rem;
}

/*
 * Global search — an always-visible small text input in the topbar, sits just to the left of the
 * theme toggle. Submits a plain GET to global_search.php; the magnifying-glass icon is the form's
 * own submit button (not a toggle for anything), so no JS is needed to wire this up at all.
 */
.topbar-search { display: flex; align-items: center; gap: .35rem; }
.topbar-search input {
  width: 140px;
  padding: .4rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
}
.topbar-search button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.topbar-search button:hover { background: var(--nav-hover-bg); color: var(--text); }

/*
 * Light/dark toggle (assets/js/theme.js), sits just to the left of the username — a sliding
 * switch: a sun icon fixed at the track's left, a moon fixed at the right, and a round thumb
 * that slides between them and swaps color depending on the active theme.
 */
#theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 44px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-alt);
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}
#theme-toggle:hover { border-color: var(--text-muted); }
.theme-toggle-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.theme-toggle-icon.icon-sun { left: 6px; }
.theme-toggle-icon.icon-moon { right: 6px; }
.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1b3a6b 0%, #0b1c3d 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  transition: transform .22s ease, background .22s ease;
}
:root[data-theme="dark"] .theme-toggle-thumb {
  transform: translateX(20px);
  background: linear-gradient(135deg, #ffd77a 0%, #e8a93a 100%);
}

/* Username trigger — opens the "my profile" modal (assets/js/profile-modal.js) */
.topbar-user-name {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .4rem .6rem;
  border-radius: 6px;
  background: none;
  border: 0;
  font-size: .9rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease;
}
.topbar-user-name:hover { background: var(--nav-hover-bg); color: var(--text); }

.logout-link {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .7rem;
  border-radius: 6px;
  background: var(--nav-hover-bg);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .9rem;
  transition: background-color .18s ease, color .18s ease;
}
.logout-link:hover { background: var(--status-fail-bg); color: var(--status-fail-border); }

/*
 * Wraps a <table> so it scrolls horizontally instead of squeezing/breaking its own layout on a
 * narrow screen — used around every results/list table in the app (hubspot_leads.php,
 * busqueda_hubspot.php, busqueda_sw.php, users.php) rather than changing the table's own
 * display/layout, which risks breaking sortable.js or the tfoot/colspan totals rows. Harmless at
 * any width — it only visibly scrolls once the table's natural width exceeds the container's.
 */
.table-scroll { overflow-x: auto; }

/*
 * Responsive layout, mobile phones and small tablets. 768px (the classic tablet-portrait
 * breakpoint) rather than something wider — a wider cutoff (900px was tried first) caught normal,
 * non-maximized desktop/laptop browser windows too, which isn't the intent here.
 * assets/js/nav-toggle.js's MOBILE_BREAKPOINT constant must be kept in sync with this value.
 */
@media (max-width: 768px) {
  .topbar { padding: .6rem 1rem; gap: .75rem; }
  #nav-toggle { display: flex; }

  /*
   * .topbar-collapse becomes the dropdown panel under the hamburger button instead of sitting
   * inline — position: absolute relies on .topbar's own position: sticky already establishing a
   * containing block (sticky elements do this the same way relative/absolute ones do), so no
   * extra position rule is needed on .topbar itself.
   */
  .topbar-collapse {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .15);
    padding: .5rem 1rem 1rem;
    /* 64px is a safe estimate of the topbar's own height (padding + logo/button row) — mixing
       vh with the containing block's % height in one calc() doesn't resolve predictably here,
       since .topbar has no explicit height for percentages to resolve against. Just a ceiling
       for very short viewports (e.g. a phone in landscape); overflow-y handles the rest. */
    max-height: calc(100vh - 64px);
    overflow-y: auto;
  }
  .topbar-collapse.open { display: flex; }

  .topbar nav { flex-direction: column; gap: .15rem; margin-left: 0; }
  .topbar nav a { padding: .65rem .75rem; }

  .topbar-user {
    margin-left: 0;
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
  }

  /* index.php's tool-picker cards: one per row instead of squeezing 3-4 into a phone's width. */
  .dashboard-cards { flex-direction: column; }

  /* .chart-columns' desktop columns (mailchimp.php, global_search.php) stack full-width instead
     of trying to sit side by side in a narrower gap. */
  .chart-columns { gap: 1.25rem; }
  .chart-column { flex: 1 1 100%; max-width: 100%; }

  /* Page content and modal edge padding — the desktop values (2rem/2rem) eat too much of a
     narrow viewport's width. */
  .page { padding: 1rem 1rem 1.5rem; }
  .modal-overlay { padding: 1rem; }

  /* form.filters (search/date-range forms): stack fields full-width instead of the desktop
     side-by-side row, which either wraps awkwardly or forces horizontal scrolling on the form
     itself at phone widths. align-items: stretch replaces flex-end since the cross-axis is now
     horizontal (column layout), not vertical. */
  form.filters { flex-direction: column; align-items: stretch; gap: .75rem; }
  form.filters input[type=text],
  form.filters input[type=email],
  form.filters select,
  form.filters input[type=text].wide { width: 100%; }
  form.filters button:not(.filters-icon-btn) { width: 100%; }

  /* users.php's create/edit modal form: the Usuario+Contraseña row is too tight to share once
     the modal itself is only as wide as a phone viewport allows. */
  .user-form-row { flex-direction: column; }
}
