/* =============================================
   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; }

.app-layout .app-content {
  flex: 1;
  padding: 2rem;
  overflow-x: hidden;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  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%;
}
/* 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;
}

/* =============================================
   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: none;
  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-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;
}

/* 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 {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 0.2rem;
}

.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.75rem;
  max-height: 350px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  gap: 1rem;
}

.feed-brand {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent-cyan);
}

.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.875rem;
  table-layout: auto;
}

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

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

.data-table td {
  padding: 0.6rem 0.75rem;
  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
   ============================================= */
.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;
}

/* =============================================
   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: 1.5rem;
  }

  .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;
    gap: 0.5rem;
  }

  .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;
  }
}
