/* =============================================
   PMEDIA - App CSS (Zona privada / Dashboard)
   ============================================= */

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg-primary);
}

.app-main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Bloqueig total d'scroll horitzontal a nivell de pagina.
   Si algun fill es massa ample, haura de tenir el seu propi overflow:auto. */
html, body { overflow-x: hidden; max-width: 100vw; }
.app-layout, .app-main-wrapper { max-width: 100vw; min-width: 0; overflow-x: hidden; }

/* Botons d'accio a l'ultima cel·la d'una fila: sempre inline, mai wrap.
   Si el titol es massa llarg, s'amaga amb ellipsis (l'usuari obre l'ad
   clicant la fila igualment). */
.data-table td:last-child,
.feed-item-actions,
.ad-card-actions {
  white-space: nowrap;
}
.data-table td:last-child > * {
  display: inline-flex !important;
  vertical-align: middle;
}
/* Cel·les amb text llarg: truncar amb ellipsis perque els botons no
   siguin empesos ni wrappejats */
.data-table td[style*="max-width"] {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-layout .app-content {
  flex: 1;
  padding: 2rem;
  overflow-x: hidden;
  width: 100%;
  min-width: 0;
  max-width: 1600px; /* prevent excessive stretch on 27"+ monitors */
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

/* Fix global: grid/flex children poden desbordar per defecte (min-width:auto).
   Assegura que .chart-card i .kpi-card es cenyeixen al contenidor. */
.chart-card, .kpi-card, .kpi-grid > *, .charts-row > * {
  min-width: 0;
}

/* Taules dins chart-card: respectar amplada del contenidor */
.chart-card table {
  max-width: 100%;
  width: 100%;
}

/* Formularis responsius: cada camp es pot contraure i el select mai sobrepassa */
.form-group { min-width: 0; }
.form-group .form-control,
.form-group select.form-control,
.form-group input.form-control,
.form-group textarea.form-control {
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}
@media (max-width: 640px) {
  /* A mobil, els search-grid passen a 1 columna perque els selects no es tallin */
  .search-grid { grid-template-columns: 1fr !important; }
  .form-group[style*="grid-column"] { grid-column: 1 / -1 !important; }
}
/* Wrapper amb overflow per taules massa amples (preserva legibilitat) */
.chart-card > div:has(> table),
.chart-card > table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.app-layout.authenticated .app-content {
  padding-top: calc(56px + 1.5rem);
}

.app-layout.authenticated .app-main-wrapper {
  margin-left: 260px;
  transition: margin-left 0.2s ease;
}

/* Sidebar collapsed (només icones) */
.app-layout.sidebar-collapsed .sidebar { width: 64px; }
.app-layout.sidebar-collapsed.authenticated .app-main-wrapper { margin-left: 64px; }
.app-layout.sidebar-collapsed .app-topbar { left: 64px; }
.app-layout.sidebar-collapsed .sidebar-link {
  padding: 0.6rem 0;
  justify-content: center;
  gap: 0;
}
.app-layout.sidebar-collapsed .sidebar-link.active {
  margin: 0 0.4rem;
  padding: 0.6rem 0;
}
/* Amaga TOT el text dels links (font-size:0). Les icones SVG tenen mida
   pròpia amb width/height, no depenen de font-size, així que es mantenen. */
.app-layout.sidebar-collapsed .sidebar-link { font-size: 0; }
.app-layout.sidebar-collapsed .sidebar-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.app-layout.sidebar-collapsed .sidebar-link::after { font-size: 0.8rem; } /* tooltip */
.app-layout.sidebar-collapsed .sidebar-section-title { display: none; }
.app-layout.sidebar-collapsed .sidebar-header > div { display: none; }
.app-layout.sidebar-collapsed .sidebar-bottom-user { padding: 0.4rem 0; justify-content: center; }
.app-layout.sidebar-collapsed .sidebar-bottom-info { display: none; }
/* Tooltip al hover (mostra el text via title attribute) */
.app-layout.sidebar-collapsed .sidebar-link { position: relative; }
.app-layout.sidebar-collapsed .sidebar-link::after {
  content: attr(data-label);
  position: absolute;
  left: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  border: 1px solid var(--border-color);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 200;
}
.app-layout.sidebar-collapsed .sidebar-link:hover::after { opacity: 1; }

/* Toggle button */
.sidebar-toggle {
  position: absolute;
  top: 16px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  z-index: 110;
  transition: transform 0.2s;
}
.app-layout.sidebar-collapsed .sidebar-toggle { display: none; }
.sidebar-toggle:hover { background: var(--accent-cyan); color: white; }
@media (max-width: 768px) { .sidebar-toggle { display: none; } }

/* =============================================
   TOP BAR
   ============================================= */
.app-topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 260px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  z-index: 90;
  gap: 0.75rem;
}

.topbar-left {
  display: none;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo-mobile {
  display: none;
}

.topbar-hamburger {
  display: flex;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.topbar-left {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
}

.topbar-hamburger:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.topbar-breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}


.topbar-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.topbar-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.topbar-install-btn {
  display: none;
  height: 32px;
  padding: 0 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--gradient-main);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  gap: 0.35rem;
  align-items: center;
  white-space: nowrap;
  transition: all var(--transition);
}

.topbar-install-btn.visible {
  display: flex;
}

.topbar-install-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: none;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}

.sidebar-header {
  height: 56px;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  border-bottom: none;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.1rem;
}

/* Sidebar bottom (user + logout, outside nav) */
.sidebar-bottom {
  flex-shrink: 0;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-color);
}

.sidebar-bottom-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1.5rem;
}

.sidebar-bottom-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gradient-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.6rem;
  flex-shrink: 0;
}

.sidebar-bottom-info {
  overflow: hidden;
}

.sidebar-bottom-name {
  font-weight: 600;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-bottom-email {
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-install-link {
  display: none !important;
}

/* Sortable columns */
.sortable-table th[data-sort-key]{position:relative;padding-right:1.4em !important;}
.sortable-table th[data-sort-key]:hover{background:rgba(255,255,255,0.04);}
.sortable-table th[data-sort-key]::after{
  content:'⇅';
  position:absolute;
  right:0.4em;top:50%;transform:translateY(-50%);
  opacity:0.35;font-size:0.85em;
}
.sortable-table th.sort-asc::after{content:'↑';opacity:1;color:var(--accent-cyan);}
.sortable-table th.sort-desc::after{content:'↓';opacity:1;color:var(--accent-cyan);}

/* FAQ Accordion */
.faq-item.open .faq-answer { max-height: 300px !important; }
.faq-item.open .faq-toggle svg { transform: rotate(180deg); }
.faq-toggle:hover { background: rgba(255,255,255,0.02) !important; }

/* PWA Install Modal Steps */
.pwa-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.pwa-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-cyan);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (display-mode: standalone) {
  .sidebar-install-link {
    display: none !important;
  }
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 1rem;
}

.sidebar-section-title {
  padding: 0.5rem 1.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.03);
}

.sidebar-link.active {
  color: white;
  background: var(--accent-red);
  border-radius: var(--radius-md);
  margin: 0 0.75rem;
  padding: 0.6rem 0.75rem;
}

/* =============================================
   LOGIN
   ============================================= */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-error {
  color: var(--accent-red);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.75rem;
  background: rgba(233, 30, 99, 0.1);
  border-radius: var(--radius-sm);
}

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* =============================================
   PAGE HEADER
   ============================================= */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

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

.header-status {
  display: flex;
  gap: 0.75rem;
}

.status-badge {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.status-active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-db {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-blue);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* =============================================
   DASHBOARD FILTERS
   ============================================= */
.dashboard-filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-width: 150px;
}

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

/* Unified control sizing inside filter-group */
.filter-group .form-control,
.filter-group .form-control-sm,
.filter-group .country-single-toggle,
.filter-group .country-ms-toggle {
  height: 36px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  box-sizing: border-box;
}

.filter-group .btn {
  height: 36px;
  padding: 0 1rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.form-control-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

/* =============================================
   KPI CARDS
   ============================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  transition: all var(--transition);
  border-left: 4px solid transparent;
  position: relative;
  overflow: visible; /* permet que help-bubble tooltips es vegin */
  z-index: 1;
}
/* Quan es mostra un help-bubble, la card puja sobre qualsevol element
   de la row següent (fixa el tooltip amagat sota validacio/KPI). */
.kpi-card:has(.help-bubble:hover),
.kpi-card:has(.help-bubble.open),
.kpi-card:has(.help-bubble:focus),
.chart-card:has(.help-bubble:hover),
.chart-card:has(.help-bubble.open),
.chart-card:has(.help-bubble:focus) {
  z-index: 10000;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
  border-radius: inherit;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.kpi-card:hover::after {
  opacity: 1;
}

.kpi-cyan { border-left-color: #00d4ff; }
.kpi-cyan::after { background: linear-gradient(135deg, rgba(0,212,255,0.05) 0%, transparent 60%); }
.kpi-blue { border-left-color: #3b82f6; }
.kpi-blue::after { background: linear-gradient(135deg, rgba(59,130,246,0.05) 0%, transparent 60%); }
.kpi-indigo { border-left-color: #6366f1; }
.kpi-indigo::after { background: linear-gradient(135deg, rgba(99,102,241,0.05) 0%, transparent 60%); }
.kpi-purple { border-left-color: #8b5cf6; }
.kpi-purple::after { background: linear-gradient(135deg, rgba(139,92,246,0.05) 0%, transparent 60%); }
.kpi-green { border-left-color: #10b981; }
.kpi-green::after { background: linear-gradient(135deg, rgba(16,185,129,0.05) 0%, transparent 60%); }
.kpi-orange { border-left-color: #f59e0b; }
.kpi-orange::after { background: linear-gradient(135deg, rgba(245,158,11,0.05) 0%, transparent 60%); }

.kpi-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.kpi-value {
  /* clamp: mai mes petit que 1rem ni mes gran que 1.65rem; escala amb viewport */
  font-size: clamp(1rem, 1.1rem + 0.6vw, 1.65rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 0.2rem;
  /* Evita overflow horitzontal: si el text es mes ample que la card, redueix
     l'espai entre caracters abans de partir-se. Amb numeros llargs (>=7
     caracters, ex 1.000.000) encara es retalla una mica el font-size final. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Auto-shrink progressiu segons la longitud del contingut (numeros grans).
   Cal que el JS posi l'atribut data-len amb el nombre de caracters, o que el
   nombre tingui simplement molts caracters. Usem un patro via :has() que es
   suportat a Chrome/Safari moderns; fallback a 1.5rem (regla base). */
.kpi-value:is(:has(:empty)) { /* no-op placeholder per mantenir el selector valid */ }

/* Si l'ample del contenidor es estret (mobil o card petita), baixem la
   font-size base perque 6-7 digits encaixin sense retallar-se. */
@media (max-width: 1100px) {
  .kpi-value { font-size: clamp(0.95rem, 1rem + 0.4vw, 1.45rem); }
}
@media (max-width: 640px) {
  .kpi-value { font-size: clamp(0.9rem, 0.95rem + 0.3vw, 1.3rem); }
}

.kpi-sparkline {
  height: 30px;
  margin: 0.4rem auto 0;
  max-width: 90px;
}

.kpi-sparkline canvas {
  width: 100% !important;
  height: 100% !important;
}

.kpi-change {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.kpi-change.positive {
  color: var(--accent-green);
}

.kpi-change.negative {
  color: var(--accent-red);
}

.kpi-trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-full);
  font-size: 0.6rem;
  font-weight: 700;
}

.kpi-trend-badge.up {
  background: rgba(16,185,129,0.12);
  color: #10b981;
}

.kpi-trend-badge.down {
  background: rgba(239,68,68,0.12);
  color: #ef4444;
}

/* =============================================
   CHARTS
   ============================================= */
.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  /* align-items per defecte stretch: cards de la mateixa fila mateixa alcada.
     El contingut ha d'expandir-se (flex:1) per omplir el card, no deixar buits. */
}

/* Chart cards amb layout intern flexible perque el contingut ompli sempre */
.chart-card {
  display: flex;
  flex-direction: column;
}
.chart-card > h3,
.chart-card > .chart-card-header,
.chart-card > .chart-help {
  flex-shrink: 0;
}
.chart-card > :not(h3):not(.chart-help):not(.chart-card-header) {
  flex: 1 1 auto;
  min-height: 0;
}

/* Contenidors dinamics: ompliran l'espai restant del card */
.feed-container,
#top5Container,
#alertsContainer,
#rankingContainer,
#topPortalsContainer {
  flex: 1 1 auto;
  min-height: 260px;
  overflow-y: auto;
}
.feed-container { max-height: none; }

.chart-card {
  overflow: visible; /* permet que help-bubble tooltips es vegin */
  max-width: 100%;
  position: relative;
  z-index: 1;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.chart-card:hover {
  border-color: rgba(0,212,255,0.2);
  box-shadow: 0 0 15px rgba(0,212,255,0.05);
}

/* Help/description text under titles and charts */
/* Language selector (topbar dropdown) — text-only, no flags */
.lang-selector { position: relative; display: inline-flex; }
.lang-selector-toggle {
  height: 32px;
  padding: 0 0.5rem 0 0.55rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1;
  transition: all var(--transition);
  white-space: nowrap;
}
.lang-selector-toggle:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.lang-selector-toggle .lang-selector-code { color: inherit; }
.lang-selector-toggle .lang-selector-caret {
  opacity: 0.7;
  transition: transform 0.15s;
}
.lang-selector.open .lang-selector-toggle {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.lang-selector.open .lang-selector-caret { transform: rotate(180deg); }

.lang-selector-dropdown {
  display: none;
  position: fixed;
  min-width: 200px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  z-index: 100000;
  padding: 0.4rem;
}
.lang-selector.open .lang-selector-dropdown { display: block; }
/* Portal version: appended to body to escape any stacking context */
.lang-selector-portal {
  display: block !important;
  z-index: 100000 !important;
}
.lang-selector-option {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.1s;
}
.lang-selector-option:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}
.lang-selector-option.active {
  background: rgba(0, 212, 255, 0.1);
  color: var(--text-primary);
  font-weight: 600;
}
.lang-selector-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  flex-shrink: 0;
}
.lang-selector-option.active .lang-selector-badge {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.lang-selector-name { flex: 1; }

/* Responsive: keep visible on mobile (used to be dropped) */
@media (max-width: 480px) {
  .lang-selector-toggle {
    padding: 0 0.4rem;
    font-size: 0.65rem;
  }
  .lang-selector-toggle svg:first-of-type { display: none; }
}

/* Country single-select dropdown (for filters) */
.country-single { position: relative; display: block; }
.country-single-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 36px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  box-sizing: border-box;
}
.country-single-toggle:hover { border-color: var(--accent-cyan); }
.country-single-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.country-single-toggle svg { transition: transform 0.2s; flex-shrink: 0; margin-left: 4px; }
.country-single.open .country-single-toggle svg { transform: rotate(180deg); }
.country-single-dropdown {
  display: none !important;
  position: fixed;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10000;
  padding: 0.3rem;
}
.country-single.open .country-single-dropdown { display: block !important; }
.country-single-option {
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.country-single-option:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

/* Flag icons inline sizing (via flag-icons CSS library) */
.fi { box-shadow: 0 0 0 1px rgba(0,0,0,0.08); }

/* Country multi-select dropdown */
.country-ms { position: relative; display: block; }
.country-ms-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 36px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  box-sizing: border-box;
}
.country-ms-toggle:hover { border-color: var(--accent-cyan); }
.country-ms-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.country-ms-dropdown {
  display: none !important;
  position: fixed;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10000;
  padding: 0.4rem;
  min-width: 240px;
}
.country-ms.open .country-ms-dropdown { display: block !important; }
.country-ms.open .country-ms-toggle svg { transform: rotate(180deg); }
.country-ms-toggle svg { transition: transform 0.2s; }
.country-ms-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.country-ms-option:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.country-ms-option input { margin: 0; }
.country-ms-loading { padding: 0.5rem; color: var(--text-muted); font-size: 0.85rem; text-align: center; }

/* Help bubble inline icon with tooltip */
.help-bubble {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  margin-left: 6px;
  vertical-align: middle;
  transition: all 0.15s;
  outline: none;
  /* Evitar que herenci el text-transform:uppercase dels kpi-label */
  text-transform: none;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
  flex-shrink: 0;
}
.help-bubble svg { width: 12px; height: 12px; }
.help-bubble:hover,
.help-bubble:focus,
.help-bubble.open {
  background: transparent;
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}
.help-bubble-tooltip {
  display: none !important;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 260px;
  max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 9999;
  text-align: left;
  white-space: normal;
  font-style: normal;
  /* Reset styles inherited from parents (kpi-label majuscules, font gran, etc) */
  text-transform: none !important;
  font-size: 0.8rem !important;
  font-weight: 400 !important;
  letter-spacing: 0 !important;
  line-height: 1.5 !important;
  color: var(--text-primary);
}
/* Only enable hover on true hover-capable devices (not touch) */
@media (hover: hover) and (pointer: fine) {
  .help-bubble:hover .help-bubble-tooltip { display: block !important; }
}
.help-bubble.open .help-bubble-tooltip {
  display: block !important;
}
.help-bubble-text {
  display: block;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}
.help-bubble-more {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--accent-cyan);
  font-weight: 600;
  text-decoration: none;
  border-top: 1px solid var(--border-color);
  padding-top: 0.4rem;
  margin-top: 0.1rem;
  width: 100%;
}
.help-bubble-more:hover { text-decoration: underline; }

@media (max-width: 768px) {
  .help-bubble-tooltip {
    left: auto;
    right: 0;
    transform: none;
    min-width: 220px;
  }
}

.help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  font-style: italic;
  opacity: 0.8;
}

/* App footer */
.app-footer {
  padding: 1rem 2rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-footer a {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.app-footer a:hover {
  color: var(--accent-cyan);
}

.chart-help {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
  font-style: italic;
  opacity: 0.7;
}

.chart-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* =============================================
   FEED
   ============================================= */
.feed-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 350px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  border-radius: 0;
  gap: 0.85rem;
  transition: background var(--transition);
}

.feed-item:last-child { border-bottom: none; }
.feed-item:hover { background: var(--bg-input); }

.feed-item-info {
  min-width: 0;
  flex: 1 1 auto;
}

.feed-brand {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent-cyan);
  letter-spacing: 0.02em;
}

.feed-model {
  font-size: 0.85rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-pub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.feed-type-badge {
  padding: 0.2rem 0.5rem;
  background: rgba(0, 212, 255, 0.1);
  color: var(--accent-cyan);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

/* =============================================
   RANKING
   ============================================= */
.ranking-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
}

.ranking-item + .ranking-item {
  border-top: 1px solid var(--border-color);
}

.ranking-pos {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ranking-info {
  flex: 1;
}

.ranking-brand {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.ranking-bar-bg {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.ranking-bar {
  height: 100%;
  background: var(--gradient-main);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.ranking-count {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent-cyan);
  min-width: 30px;
  text-align: right;
}

/* =============================================
   PLACEHOLDER
   ============================================= */
.placeholder-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 4rem 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.placeholder-card h3 {
  font-size: 1.25rem;
  font-weight: 600;
}

.placeholder-card p {
  color: var(--text-muted);
  max-width: 400px;
}

/* =============================================
   DATA TABLES
   ============================================= */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  table-layout: auto;
}

.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table th {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 2px solid var(--border-color);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

.data-table tr.row-clickable:hover td {
  background: rgba(0,212,255,0.05);
  cursor: pointer;
}

.data-table code {
  background: var(--bg-input);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

/* =============================================
   MODAL
   ============================================= */
/* Skeleton loaders (modal i altres) */
.sk-line, .sk-block {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--bg-card) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: sk-shimmer 1.4s linear infinite;
}
@keyframes sk-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  padding: 0.25rem;
}

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

/* =============================================
   FORM EXTRAS
   ============================================= */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-cyan);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* =============================================
   IMAGE GALLERY
   ============================================= */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.image-gallery-item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  aspect-ratio: 4/3;
}

.image-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-gallery-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =============================================
   DROP ZONE (screenshot upload)
   ============================================= */
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.15s;
}
.drop-zone.dragover { border-color: var(--accent-cyan); background: rgba(0,212,255,0.05); }
.drop-zone:hover { border-color: var(--accent-cyan); }
.drop-zone-icon { font-size: 2rem; opacity: 0.6; margin-bottom: 0.5rem; }
.drop-zone .mobile-only { display: none; }
@media (max-width: 768px) {
  .drop-zone .mobile-only { display: inline-flex; }
}

/* =============================================
   PAGINATION
   ============================================= */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.pagination button {
  padding: 0.4rem 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-family);
  font-size: 0.85rem;
  transition: all var(--transition);
}

.pagination button:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.pagination button.active {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: var(--bg-primary);
  font-weight: 600;
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* =============================================
   BADGES
   ============================================= */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-paper { background: rgba(249,115,22,0.15); color: #f97316; }
.badge-digital { background: rgba(59,130,246,0.15); color: #3b82f6; }
.badge-online { background: rgba(16,185,129,0.15); color: #10b981; }
.badge-social { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.badge-admin { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge-client { background: rgba(0,212,255,0.15); color: #00d4ff; }

/* =============================================
   BRAND LOGOS
   ============================================= */
.brand-logo {
  height: 32px;
  width: auto;
  max-width: 100px;
  object-fit: contain;
  border-radius: 4px;
}

.brand-logo-sm {
  height: 24px;
  width: auto;
  max-width: 80px;
  object-fit: contain;
  border-radius: 4px;
}

.brand-logo-lg {
  height: 48px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  border-radius: 4px;
}

/* =============================================
   TOAST
   ============================================= */
.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  transform: translateX(100%);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 350px;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #0284c7; }
.toast-warning { background: #d97706; }

/* =============================================
   MOBILE MENU TOGGLE
   ============================================= */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.mobile-menu-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.mobile-menu-btn.active {
  background: var(--accent-cyan);
  color: var(--bg-primary);
  border-color: var(--accent-cyan);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

.sidebar-overlay.show {
  display: block;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .mobile-menu-btn {
    display: none !important;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 150;
    top: 56px;
    height: calc(100vh - 56px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .app-layout.authenticated .app-main-wrapper {
    margin-left: 0;
  }

  .app-topbar {
    left: 0;
    z-index: 160;
  }

  .topbar-left {
    display: flex;
  }

  .topbar-hamburger {
    display: flex;
  }

  .topbar-logo-mobile {
    display: flex;
  }

  .sidebar-install-link:not(.hidden) {
    display: flex !important;
  }


  .app-layout.authenticated .app-content {
    padding: 1rem;
    padding-top: calc(56px + 0.5rem);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .kpi-value {
    font-size: clamp(0.9rem, 0.95rem + 0.3vw, 1.3rem);
  }

  .kpi-label {
    font-size: 0.6rem;
  }

  .charts-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .dashboard-filters {
    flex-direction: column;
    gap: 0.75rem;
  }

  /* Touch-friendly filter controls on mobile */
  .filter-group .form-control,
  .filter-group .form-control-sm,
  .filter-group .country-single-toggle,
  .filter-group .country-ms-toggle,
  .filter-group .btn {
    height: 40px;
    font-size: 0.9rem;
  }

  .page-header {
    flex-direction: column;
    gap: 0.5rem;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  .header-status {
    flex-wrap: wrap;
  }

  .chart-card {
    padding: 1rem;
  }

  .data-table {
    font-size: 0.75rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.4rem 0.5rem;
  }

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

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

  .search-actions {
    flex-direction: column;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-content {
    padding: 1.25rem;
    margin: 0.5rem;
    max-height: 95vh;
  }

  .modal-overlay {
    padding: 0.5rem;
  }

  .login-card {
    padding: 1.5rem;
  }

  .feed-item {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.55rem 0.65rem;
    gap: 0.4rem;
  }

  .ranking-brand {
    font-size: 0.8rem;
  }
}

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

  .kpi-card {
    padding: 1rem;
  }

  .pagination {
    flex-wrap: wrap;
  }

  .btn {
    font-size: 0.875rem;
    padding: 0.7rem 1.25rem;
  }
}

/* =============================================
   VALIDATION GALLERY (full-screen overlay)
   ============================================= */
/* =============================================
   VALIDATION GALLERY — tema per defecte FOSC.
   Overrides per tema clar més avall ([data-theme="light"]).
   ============================================= */
.validation-gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(10, 15, 28, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  color: #fff;
  animation: vgFadeIn 0.22s ease-out;
}
@keyframes vgFadeIn {
  from { opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }
  to   { opacity: 1; }
}
.vg-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: rgba(15, 15, 20, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  flex-wrap: wrap;
}
.vg-toolbar .vg-counter {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  min-width: 130px;
  color: #e2e8f0;
}
.vg-toolbar .vg-spacer { flex: 1; }
.vg-toolbar button {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.vg-toolbar button:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255,255,255,0.22); }
.vg-toolbar .vg-btn-validate { background: rgba(34,197,94,0.25); border-color: rgba(34,197,94,0.5); }
.vg-toolbar .vg-btn-doubt { background: rgba(239,68,68,0.22); border-color: rgba(239,68,68,0.5); color: #fecaca; }
.vg-toolbar .vg-btn-delete { background: rgba(148,163,184,0.15); border-color: rgba(148,163,184,0.3); }
.vg-toolbar .vg-btn-close { background: rgba(255,255,255,0.05); }

/* Status HERO — estat actual de l'anunci gran i clar (colors funcionen tant en fosc com en clar) */
.vg-status-hero {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
  border: 2px solid;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.vg-status-hero .vg-status-icon { font-size: 1.3rem; line-height: 1; }
.vg-status-hero.is-pending   { background: rgba(245,158,11,0.18); color: #fbbf24; border-color: #f59e0b; }
.vg-status-hero.is-doubt     { background: rgba(239,68,68,0.18);  color: #fca5a5; border-color: #ef4444; }
.vg-status-hero.is-validated { background: rgba(34,197,94,0.18);  color: #86efac; border-color: #22c55e; }

/* ===== Overrides tema CLAR ===== */
[data-theme="light"] .validation-gallery-overlay {
  background: rgba(248, 250, 252, 0.97);
  color: #0f172a;
}
[data-theme="light"] .vg-toolbar {
  background: #ffffff;
  border-bottom-color: #e2e8f0;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}
[data-theme="light"] .vg-toolbar .vg-counter { color: #334155; }
[data-theme="light"] .vg-toolbar button {
  background: #f1f5f9; color: #0f172a; border-color: #cbd5e1;
}
[data-theme="light"] .vg-toolbar button:hover { background: #e2e8f0; border-color: #94a3b8; }
[data-theme="light"] .vg-toolbar .vg-btn-validate { background: #dcfce7; border-color: #22c55e; color: #15803d; font-weight: 600; }
[data-theme="light"] .vg-toolbar .vg-btn-validate:hover { background: #bbf7d0; }
[data-theme="light"] .vg-toolbar .vg-btn-doubt { background: #fee2e2; border-color: #ef4444; color: #b91c1c; font-weight: 600; }
[data-theme="light"] .vg-toolbar .vg-btn-doubt:hover { background: #fecaca; }
[data-theme="light"] .vg-toolbar .vg-btn-delete { background: #f1f5f9; border-color: #94a3b8; color: #475569; }
[data-theme="light"] .vg-toolbar .vg-btn-delete:hover { background: #e2e8f0; }
[data-theme="light"] .vg-toolbar .vg-btn-close { background: #f1f5f9; }
[data-theme="light"] .vg-status-hero { box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05); }
[data-theme="light"] .vg-status-hero.is-pending   { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
[data-theme="light"] .vg-status-hero.is-doubt     { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
[data-theme="light"] .vg-status-hero.is-validated { background: #dcfce7; color: #166534; border-color: #22c55e; }
.vg-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  padding: 1.25rem 1.5rem;
  overflow: hidden;
  min-height: 0;
}
.vg-image-wrap {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 45%;
  min-width: 0;
}
.vg-image-wrap img {
  max-width: 100%;
  max-height: 48vh;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.55);
}
.vg-image-placeholder {
  font-size: 6rem;
  opacity: 0.3;
}
.vg-info {
  max-width: 460px;
  min-width: 280px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  font-size: 0.92rem;
  color: #e2e8f0;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 16px;
  padding: 1.15rem 1.35rem;
  max-height: 70vh;
  overflow-y: auto;
}
.vg-info .vg-info-title {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #ffffff;
  line-height: 1.3;
}
.vg-info .vg-info-meta {
  color: #7f8ca1;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}
.vg-info .vg-info-row {
  padding: 0.45rem 0.7rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
}
.vg-info a { color: #22d3ee; word-break: break-all; }
.vg-nav-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vg-nav-btn:hover { background: rgba(255, 255, 255, 0.2); }
.vg-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.vg-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #94a3b8;
}
.vg-include-doubts {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: #cbd5e1;
  cursor: pointer;
}

/* ===== Overrides tema CLAR per la resta de la galeria ===== */
[data-theme="light"] .vg-image-wrap img {
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  background: #fff;
}
[data-theme="light"] .vg-image-placeholder { color: #94a3b8; }
[data-theme="light"] .vg-info {
  color: #0f172a;
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}
[data-theme="light"] .vg-info .vg-info-title { color: #0f172a; font-weight: 700; }
[data-theme="light"] .vg-info .vg-info-meta { color: #64748b; }
[data-theme="light"] .vg-info .vg-info-row { background: #f8fafc; border: 1px solid #e2e8f0; }
[data-theme="light"] .vg-info a { color: #0284c7; }
[data-theme="light"] .vg-nav-btn {
  background: #ffffff; border-color: #cbd5e1; color: #0f172a;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
[data-theme="light"] .vg-nav-btn:hover { background: #f1f5f9; }
[data-theme="light"] .vg-empty { color: #64748b; }
[data-theme="light"] .vg-include-doubts { color: #334155; }

/* Paid / Earned badges (tema fosc per defecte) */
.vg-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid transparent;
}
.vg-badge-paid   { background: rgba(34,211,238,0.25); color: #22d3ee; border-color: rgba(34,211,238,0.4); }
.vg-badge-earned { background: rgba(148,163,184,0.2); color: #94a3b8; border-color: rgba(148,163,184,0.3); }
[data-theme="light"] .vg-badge-paid   { background: #e0f2fe; color: #0369a1; border-color: #7dd3fc; }
[data-theme="light"] .vg-badge-earned { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
@media (max-width: 768px) {
  .vg-content {
    flex-direction: column-reverse; /* info a dalt, imatge a sota en mobil */
    gap: 1rem;
    padding: 0.75rem;
    align-items: stretch;
  }
  .vg-image-wrap { max-width: 100%; flex: 0 0 auto; }
  .vg-image-wrap img { max-height: 40vh; }
  .vg-image-placeholder { font-size: 4rem; }
  .vg-info {
    max-width: 100%; min-width: 0; width: 100%;
    padding: 1rem;
    font-size: 0.88rem;
  }
  .vg-info .vg-info-title { font-size: 1.1rem; }
  /* Estat actual sticky al capdamunt del panell — sempre visible al mobil */
  .vg-info .vg-status-hero {
    position: sticky; top: -1.05rem; z-index: 2;
    margin: -1.05rem -1.05rem 0.25rem -1.05rem;
    border-radius: 0 0 12px 12px;
    font-size: 1.05rem;
    padding: 0.8rem 1rem;
  }
  .vg-toolbar { padding: 0.5rem; gap: 0.35rem; font-size: 0.8rem; }
  .vg-toolbar button { padding: 0.4rem 0.55rem; font-size: 0.78rem; }
  .vg-toolbar .vg-counter { min-width: auto; font-size: 0.78rem; }
  .vg-toolbar .vg-include-doubts { font-size: 0.72rem; }
}
@media (max-width: 480px) {
  .vg-toolbar {
    /* Ordre dels botons: esquerra/dreta/comptador | dubte/validar/eliminar | tancar */
    gap: 0.25rem;
    padding: 0.4rem;
  }
  .vg-toolbar button {
    padding: 0.4rem 0.5rem;
    font-size: 0.72rem;
  }
  /* Amaga labels de text als botons accio; nomes emojis */
  .vg-toolbar .vg-btn-validate,
  .vg-toolbar .vg-btn-doubt,
  .vg-toolbar .vg-btn-delete,
  .vg-toolbar #vgEdit,
  .vg-toolbar .vg-btn-close {
    font-size: 0; /* amaga text */
    padding: 0.45rem 0.55rem;
  }
  .vg-toolbar .vg-btn-validate::before { content: '✅'; font-size: 1rem; }
  .vg-toolbar .vg-btn-doubt::before    { content: '❓'; font-size: 1rem; }
  .vg-toolbar .vg-btn-delete::before   { content: '🗑'; font-size: 1rem; }
  .vg-toolbar #vgEdit::before          { content: '✏️'; font-size: 1rem; }
  .vg-toolbar .vg-btn-close::before    { content: '✕'; font-size: 0.95rem; font-weight:700; }
  /* Checkboxes de 'inclou dubtes/validats': mida reduida */
  .vg-toolbar .vg-include-doubts {
    flex: 0 1 auto;
    font-size: 0.68rem;
    gap: 0.25rem;
  }
  .vg-toolbar .vg-include-doubts input { transform: scale(0.9); }
  .vg-image-wrap img { max-height: 35vh; }
  .vg-info { padding: 0.85rem; }
  .vg-info .vg-info-title { font-size: 1rem; }
}

/* =============================================
   VALIDATION — filters + actions bar en UNA sola fila
   (només a desktop — al mobil deixem que s'apilin com a la resta de la UI)
   ============================================= */
@media (min-width: 769px) {
  #valFiltersBar {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: flex-end;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #valFiltersBar .filter-group {
    flex: 1 1 auto;
    min-width: 120px;
  }
  #valFiltersBar .val-filter-actions {
    flex: 0 0 auto;          /* Buscar+Netejar no es redueix */
    min-width: auto;
    flex-direction: row !important;  /* botons costat-a-costat (override column del .filter-group) */
    align-items: stretch;
    gap: 6px;
  }
  #valFiltersBar .val-filter-actions > .btn { flex: 0 0 auto; white-space: nowrap; }
  #valActionsBar,
  #trashBar {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 0.5rem;
  }
  #valActionsBar > .btn,
  #trashBar > .btn { flex-shrink: 0; }
  #valActionsBar > #valPendingCount,
  #trashBar > #trashCount { margin-left: auto; flex-shrink: 0; white-space: nowrap; }
}
/* A mobil: layout natural (column per .dashboard-filters, wrap per .chart-card) */
@media (max-width: 768px) {
  #valActionsBar,
  #trashBar { flex-wrap: wrap !important; gap: 0.4rem; display: flex; }
  #valActionsBar > #valPendingCount,
  #trashBar > #trashCount { flex-basis: 100%; text-align: center; margin-top: 0.25rem; }
  /* Els botons Buscar / Netejar ocupen la seva linia sencera, repartits 50/50 */
  #valFiltersBar .val-filter-actions {
    flex-direction: row !important;
    gap: 0.5rem;
  }
  #valFiltersBar .val-filter-actions > .btn { flex: 1 1 0; }
}

/* Informes: dues columnes 50/50 (selectors + preview) a desktop; 1 col a mobil */
.informes-grid { align-items: stretch; }
.informes-grid > .chart-card { height: 100%; }
@media (max-width: 768px) {
  .informes-grid {
    grid-template-columns: 1fr !important;
  }
  .informes-grid > .chart-card { height: auto; }
}

/* Support inbox: barra de filtres amb píndoles (altura controlada) */
.sup-filter-bar {
  display: flex !important;
  flex: 0 0 32px !important;
  align-self: flex-start;
  align-items: stretch;
  height: 32px !important;
  max-height: 32px !important;
  min-height: 32px !important;
  gap: 3px;
  margin-bottom: 0.75rem;
  background: var(--bg-input);
  padding: 3px;
  border-radius: 8px;
  box-sizing: border-box;
  width: 100%;
}
.sup-filter-btn {
  flex: 1 1 0;
  height: 100% !important;
  max-height: 26px;
  padding: 0 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.sup-filter-btn:hover { color: var(--text-primary); }
.sup-filter-btn.is-active {
  background: var(--accent-cyan);
  color: #0a0f1c;
  font-weight: 700;
}

/* =============================================
   USERS MGMT — responsive mòbil
   ============================================= */
/* Capçalera: botó "Crear usuari" en nova línia al mobil */
@media (max-width: 768px) {
  .page-header { flex-direction: column; align-items: stretch !important; gap: 0.75rem; }
  .page-header > div:last-child { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .page-header > div:last-child > .btn { flex: 1 1 auto; }
}
/* Sub-tabs més compactes */
@media (max-width: 768px) {
  .sub-tabs .sub-tab-btn { padding: 0.5rem 0.6rem !important; font-size: 0.8rem !important; }
}
/* Taula d'usuaris: compactem paddings i les accions es poden apilar */
@media (max-width: 768px) {
  .users-table td,
  .users-table th { padding: 0.4rem 0.45rem !important; font-size: 0.72rem !important; }
  .users-table td:last-child { white-space: normal; }
  .users-table td:last-child .btn { padding: 0.2rem 0.4rem; font-size: 0.68rem; margin: 1px 2px 1px 0; }
}
/* A molt estret, amaga columna 'Creat el' (no crítica) */
@media (max-width: 560px) {
  .users-table th:nth-child(6),
  .users-table td:nth-child(6) { display: none; }
  .users-table { min-width: 560px !important; }
}
/* Modals (crear/editar usuari): ocupen tot el viewport al mobil */
@media (max-width: 540px) {
  .modal-overlay .modal-content { max-width: 100% !important; margin: 0; width: 100%; max-height: 100vh; border-radius: 0; }
  .modal-overlay { padding: 0 !important; }
}
/* Dashboard-filters al mobil ja s'apilen via regla previa; ajustem la última row (netejar) */
@media (max-width: 768px) {
  .dashboard-filters .filter-group[style*="justify-content:flex-end"] { justify-content: stretch !important; }
  .dashboard-filters .filter-group[style*="justify-content:flex-end"] > .btn { width: 100%; }
}

/* ===== Role: Editor — sections matrix (user create/edit modals) ===== */
.sections-matrix .sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.45rem 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}
.sections-matrix .section-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-primary);
}
.sections-matrix .section-check input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  cursor: pointer;
  flex-shrink: 0;
}
@media (max-width: 560px) {
  .sections-matrix .sections-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 0.5rem;
  }
}
@media (max-width: 380px) {
  .sections-matrix .sections-grid { grid-template-columns: 1fr; }
}
