/* ePerfectStore Flask App - Light Design System
   Inspired by perfectstore.app */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Core palette - light mode */
  --black: #0f172a;
  --black-soft: #ffffff;
  --black-card: #ffffff;
  --black-elevated: #f8fafc;
  --black-input: #ffffff;

  /* Orange accent - matching perfectstore.app */
  --orange: #ff6600;
  --orange-light: #ff8533;
  --orange-dark: #cc5200;
  --orange-glow: rgba(255, 102, 0, 0.12);
  --orange-subtle: rgba(255, 102, 0, 0.06);

  /* Text */
  --white: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;

  /* Borders */
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-active: rgba(255, 102, 0, 0.4);

  /* Status colors */
  --green: #16a34a;
  --green-dark: #15803d;
  --red: #dc2626;
  --yellow: #d97706;
  --blue: #2563eb;
  --purple: #7c3aed;
  --cyan: #0891b2;

  /* SOV event annotation colors (chart annotations + narrative) */
  --ev-price: #16a34a;          /* own price/promo and competitor price/promo */
  --ev-stockout-comp: #f59e0b;  /* competitor stockout */
  --ev-own-stockout: #dc2626;   /* own brand stockout */
  --ev-own: #2563eb;            /* own brand line color (annotated chart) */

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-orange: 0 4px 14px rgba(255, 102, 0, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f1f5f9;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

.sidebar {
  width: 260px;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform .3s ease;
}

.sidebar-brand {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.sidebar-brand .orange, .sidebar-brand .accent { color: var(--orange); }

.sidebar-nav a {
  display: block;
  padding: .65rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: .5rem;
  font-size: .9rem;
  font-weight: 500;
  margin-bottom: .15rem;
  transition: all .2s ease;
}
.sidebar-nav a:hover {
  background: var(--orange-subtle);
  color: var(--text-primary);
}
.sidebar-nav a.active {
  background: var(--orange-subtle);
  color: var(--orange);
  border-left: 3px solid var(--orange);
}

.sidebar-section-title {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .5rem 1rem;
  margin-top: 1.25rem;
}

.sidebar-user {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: auto;
  font-size: .85rem;
}
.sidebar-user strong { color: var(--text-primary); }

.main-content {
  margin-left: 260px;
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
  padding: 2rem;
  min-height: 100vh;
  background: #f1f5f9;
}

/* ---------- Page header ---------- */
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h2 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -1px;
  margin-bottom: .25rem;
}
.page-header .subtitle {
  color: var(--text-secondary);
  font-size: .9rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: box-shadow .3s ease;
}
.card:hover {
  box-shadow: var(--shadow-md);
}
.card-accent { border-left: 3px solid var(--orange); }

.card-header {
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- Section headers ---------- */
.section-header {
  font-size: 1.25rem;
  font-weight: 700;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--orange);
  margin: 2rem 0 1rem;
  color: var(--text-primary);
}

/* ---------- Metrics ---------- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.metrics-row { display: grid; gap: 1rem; margin-bottom: 1.5rem; }
.metrics-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.metrics-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.metrics-row.cols-4 { grid-template-columns: repeat(4, 1fr); }

.metric-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: box-shadow .3s ease;
}
.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--orange), #ef4444, #8b5cf6);
}
.metric-card:hover { box-shadow: var(--shadow-md); }

.metric-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -1px;
  display: block;
}
.metric-label {
  font-size: .8rem;
  color: var(--text-secondary);
  margin-top: .35rem;
  display: block;
}
.metric-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: .75rem;
}

/* ---------- Semaphore ---------- */
.semaphore-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }

.semaphore-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  position: relative;
}
.semaphore-value {
  font-size: 3rem;
  font-weight: 800;
  margin: 1rem 0 .5rem;
}
.semaphore-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.color-green { color: var(--green); }
.color-yellow { color: var(--yellow); }
.color-red { color: var(--red); }
.border-green { border-top: 3px solid var(--green); }
.border-yellow { border-top: 3px solid var(--yellow); }
.border-red { border-top: 3px solid var(--red); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: .6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all .2s ease;
  text-decoration: none;
  font-size: .85rem;
}
.btn-primary {
  background: var(--orange);
  color: var(--white);
}
.btn-primary:hover {
  background: var(--orange-light);
  box-shadow: var(--shadow-orange);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--black-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
  color: var(--text-primary);
}
.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-hover);
}
.btn-ghost:hover {
  background: var(--text-primary);
  color: var(--white);
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ---------- Forms / Filters ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: flex-end;
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: var(--black-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.filter-group {
  flex: 1;
  min-width: 140px;
}
.filter-group label {
  display: block;
  font-weight: 500;
  font-size: .75rem;
  margin-bottom: .3rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.filter-group select,
.filter-group input[type="text"],
.filter-group input[type="date"],
.filter-group input[type="number"] {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  background: var(--white);
  color: var(--text-primary);
  transition: border-color .2s, box-shadow .2s;
}
.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-glow);
}

/* ---------- Multi-select dropdown ---------- */
.ms-wrap { position: relative; }
.ms-toggle { width: 100%; padding: .45rem .6rem; background: var(--black-input); border: 1px solid var(--border-hover); border-radius: 6px; font-size: .8rem; font-family: 'Inter', sans-serif; cursor: pointer; text-align: left; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; justify-content: space-between; }
.ms-toggle:hover { border-color: var(--border-active); }
.ms-toggle .ms-count { background: var(--orange); color: #fff; border-radius: 10px; padding: 0 .45rem; font-size: .7rem; font-weight: 600; flex-shrink: 0; }
.ms-toggle .ms-arrow { flex-shrink: 0; margin-left: .25rem; font-size: .6rem; color: var(--text-tertiary); }
.ms-dropdown { display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: var(--black-card); border: 1px solid var(--border-hover); border-radius: 6px; margin-top: 2px; max-height: 240px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.ms-dropdown.open { display: block; }
.ms-search { width: 100%; padding: .4rem .6rem; border: none; border-bottom: 1px solid var(--border); font-size: .78rem; font-family: 'Inter', sans-serif; background: var(--black-elevated); color: var(--text-primary); box-sizing: border-box; }
.ms-search:focus { outline: none; }
.ms-actions { display: flex; border-bottom: 1px solid var(--border); }
.ms-actions button { flex: 1; padding: .3rem; font-size: .7rem; font-family: 'Inter', sans-serif; background: none; border: none; color: var(--orange); cursor: pointer; font-weight: 600; }
.ms-actions button:hover { background: var(--orange-subtle); }
.ms-actions button:first-child { border-right: 1px solid var(--border); }
.ms-option { display: flex; align-items: center; padding: .35rem .6rem; cursor: pointer; font-size: .8rem; gap: .4rem; }
.ms-option:hover { background: var(--orange-subtle); }
.ms-option input[type="checkbox"] { accent-color: var(--orange); margin: 0; flex-shrink: 0; }
.ms-option.hidden { display: none; }
#alert-modal .ms-dropdown { z-index: 1010; }

/* ---------- Tables ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}
.data-table thead th {
  background: var(--black-elevated);
  padding: .7rem .75rem;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table tbody td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}
.data-table tbody tr:hover { background: rgba(255, 102, 0, 0.03); }
.data-table tbody tr:nth-child(even) { background: #fafbfc; }

.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 600px;
  overflow-y: auto;
}

/* Frozen first columns for price channel table */
.frozen-table thead th:first-child,
.frozen-table tbody td:first-child {
  position: sticky;
  left: 0;
  background: var(--white);
  z-index: 2;
}
.frozen-table thead th:first-child { z-index: 3; background: var(--black-elevated); }

/* ---------- Alerts ---------- */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: .9rem;
  border: 1px solid;
}
.alert-info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.alert-success {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}
.alert-warning {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}
.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin: 1rem 0;
}
.pagination .btn { padding: .5rem 1rem; font-size: .85rem; }
.pagination .page-info { color: var(--text-secondary); font-size: .85rem; }

/* ---------- Chart containers ---------- */
.chart-container {
  position: relative;
  padding: .5rem;
  margin-bottom: 1rem;
}
.chart-container canvas { max-height: 400px; }

/* ---------- Grid layouts ---------- */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
.grid-equal-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }

/* ---------- Timeline (promo summary) ---------- */
.timeline-item { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }

.timeline-month {
  background: var(--orange);
  color: var(--white);
  padding: 1rem;
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
  box-shadow: var(--shadow-orange);
  align-self: start;
}

.timeline-section {
  background: var(--white);
  border-radius: 10px;
  padding: 1.25rem;
  border: 1px solid var(--border);
}
.timeline-section.competitor { border-left: 3px solid var(--orange); }
.timeline-section.client { border-left: 3px solid var(--green); }

.timeline-section-title {
  color: var(--white);
  padding: .55rem .75rem;
  border-radius: 6px;
  text-align: center;
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: .75rem;
}
.timeline-section-title.competitor { background: var(--orange); }
.timeline-section-title.client { background: var(--green-dark); }

.timeline-metric {
  display: flex;
  justify-content: space-between;
  padding: .45rem .75rem;
  background: var(--black-elevated);
  border-radius: 6px;
  margin-bottom: .35rem;
  font-size: .83rem;
  color: var(--text-secondary);
}
.timeline-metric strong { color: var(--text-primary); }

/* ---------- Product cards ---------- */
.product-card {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .2s, box-shadow .2s;
}
.product-card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-sm);
}
.product-card img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.product-card .product-info { flex: 1; }
.product-card .product-info strong {
  display: block;
  color: var(--text-primary);
  font-size: .85rem;
  margin-bottom: .25rem;
}
.product-card .product-info span {
  display: block;
  color: var(--text-secondary);
  font-size: .8rem;
}
.product-card .product-name { font-weight: 600; margin-bottom: .25rem; }
.product-card .product-price { color: var(--green); font-weight: 600; }
.product-card .product-unit-price { color: var(--text-secondary); font-size: .85rem; }

/* ---------- Image comparison ---------- */
.image-comparison {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: .75rem;
  border-bottom: 1px solid var(--border);
}
.image-comparison .arrow {
  font-size: 1.5rem;
  align-self: center;
  color: var(--text-tertiary);
}
.img-placeholder {
  width: 100px;
  height: 100px;
  background: var(--black-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  color: var(--text-tertiary);
}

/* ---------- Login page ---------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 40%, rgba(255, 102, 0, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 30%, rgba(239, 68, 68, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 50% 75%, rgba(139, 92, 246, 0.03) 0%, transparent 50%),
    #f1f5f9;
}
.login-card {
  background: var(--white);
  padding: 2.5rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
}
.login-card h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: .5rem;
  color: var(--text-primary);
  letter-spacing: -1px;
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: .9rem;
}
.login-card .form-group { margin-bottom: 1.25rem; }
.login-card label {
  display: block;
  font-weight: 500;
  margin-bottom: .4rem;
  color: var(--text-primary);
  font-size: .85rem;
}
.login-card input {
  width: 100%;
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: 'Inter', sans-serif;
  background: var(--white);
  color: var(--text-primary);
  transition: border-color .2s, box-shadow .2s;
}
.login-card input::placeholder { color: var(--text-tertiary); }
.login-card input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-glow);
}
.login-card .btn-primary {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  margin-top: .5rem;
  border-radius: 10px;
}

/* Microsoft SSO button */
.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  width: 100%;
  padding: .85rem 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  transition: all .2s ease;
}
.btn-microsoft:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
  background: var(--black-elevated);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
  color: var(--text-tertiary);
  font-size: .85rem;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Gradient divider line */
.gradient-line {
  height: 2px;
  background: linear-gradient(90deg, var(--orange), #ef4444, #8b5cf6);
  border: none;
  margin: 1.5rem 0;
  border-radius: 1px;
}

/* ---------- Flash messages ---------- */
.flash-messages { margin-bottom: 1rem; }
.flash {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: .5rem;
  font-size: .85rem;
  border: 1px solid;
}
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.flash-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.flash-info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

/* ---------- HTMX indicators ---------- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile header & sidebar overlay ---------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  align-items: center;
  padding: 0 1rem;
  gap: .75rem;
}
.mobile-brand {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.mobile-brand .orange, .mobile-brand .accent { color: var(--orange); }

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

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

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .mobile-header { display: flex; }
  .sidebar-overlay.active { display: block; }

  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
    padding-top: calc(56px + 1.5rem);
  }

  .grid-2, .grid-equal-2 { grid-template-columns: 1fr; }
  .semaphore-grid { grid-template-columns: 1fr; }
  .timeline-item { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metrics-row.cols-3, .metrics-row.cols-4 { grid-template-columns: repeat(2, 1fr); }

  .card { padding: 1rem; margin-bottom: 1rem; }

  /* Precio canal filters grid */
  .pc-filters { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; }
}

@media (max-width: 640px) {
  .main-content { padding: 1rem; padding-top: calc(56px + 1rem); }
  .filter-bar { flex-direction: column; gap: .5rem; padding: .75rem; }
  .filter-group { min-width: 100%; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metrics-row.cols-2, .metrics-row.cols-3, .metrics-row.cols-4 { grid-template-columns: 1fr; }
  .page-header h2 { font-size: 1.35rem; }

  .card { padding: .75rem; border-radius: 8px; }
  .card-header { margin-bottom: .5rem; padding-bottom: .5rem; }

  /* Tables: allow horizontal scroll, reduce padding */
  .data-table { font-size: .78rem; }
  .data-table thead th { padding: .5rem; font-size: .7rem; }
  .data-table tbody td { padding: .45rem .5rem; }

  /* Precio canal: stack filters in single column */
  .pc-filters { grid-template-columns: 1fr !important; }
  .pc-filters > div[style*="grid-column: 1 / -1"] {
    grid-template-columns: 1fr !important;
  }

  /* Multi-select dropdowns */
  .ms-dropdown { min-width: 100%; }
  .ms-options { max-height: 200px; }

  /* Product grid on mobile */
  .product-grid { grid-template-columns: 1fr; padding: .5rem; }

  /* Buttons stack on mobile */
  .card div[style*="display:flex"][style*="gap"] { flex-wrap: wrap; }
  .btn { font-size: .8rem; padding: .5rem .75rem; }

  /* Saved queries panel */
  .sq-panel { font-size: .8rem; }
  .sq-item { font-size: .78rem; }
}

/* ---------- Color indicators ---------- */
.indicator {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: .75rem;
  font-size: .78rem;
  font-weight: 600;
}
.indicator-green { background: #dcfce7; color: #15803d; }
.indicator-yellow { background: #fef9c3; color: #a16207; }
.indicator-red { background: #fee2e2; color: #dc2626; }
.indicator-gray { background: #f1f5f9; color: var(--text-tertiary); }

/* ---------- Chat ---------- */
.chat-message { display: flex; }
.chat-user { justify-content: flex-end; }
.chat-bot { justify-content: flex-start; }
.chat-bubble {
  max-width: 70%;
  padding: .75rem 1rem;
  border-radius: 1rem;
  font-size: .9rem;
  line-height: 1.5;
}
.chat-user .chat-bubble {
  background: var(--orange);
  color: var(--white);
  border-bottom-right-radius: .25rem;
}
.chat-bot .chat-bubble {
  background: var(--black-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: .25rem;
}

/* ---------- Product Grid ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1rem;
}
.image-before, .image-after {
  flex: 1;
  text-align: center;
}
.image-before img, .image-after img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
}
.image-label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .25rem;
}
.no-image {
  width: 100%;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black-elevated);
  color: var(--text-tertiary);
  border-radius: 6px;
  font-size: .8rem;
  border: 1px solid var(--border);
}

/* ---------- Export Buttons ---------- */
.export-buttons {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---------- Page Loader ---------- */
.page-loader {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.loader-backdrop {
  position: absolute; inset: 0;
  background: rgba(241, 245, 249, 0.7);
  backdrop-filter: blur(2px);
}
.loader-content {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: .75rem;
}
.loader-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text {
  font-size: .85rem; font-weight: 500;
  color: var(--text-secondary);
}

/* ──────────────────────────────────────────────────────────────────────────
   SOV Narrative Card (Agent S-B7)
   Used by partials/share_of_voice_content.html and partials/sov_narrative_findings.html
   ────────────────────────────────────────────────────────────────────────── */
.narrative-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.narrative-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}
.narrative-header .ai-badge {
  font-size: .68rem;
  font-weight: 700;
  padding: .15rem .5rem;
  border-radius: 4px;
  background: var(--orange-subtle);
  color: var(--orange);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.narrative-header h3 {
  font-size: .95rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}
.narrative-loading {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-tertiary);
  font-size: .85rem;
  padding: .75rem 0;
}
.narrative-loading .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.narrative-body {
  font-size: .875rem;
  line-height: 1.75;
  color: var(--text-secondary);
}
.narrative-body strong { color: var(--text-primary); }
.narrative-body .finding {
  display: flex;
  gap: .75rem;
  padding: .65rem .85rem;
  border-radius: 8px;
  margin-bottom: .6rem;
  border-left: 3px solid transparent;
}
.narrative-body .finding.positive {
  background: rgba(22, 163, 74, .06);
  border-color: var(--green);
}
.narrative-body .finding.negative {
  background: rgba(220, 38, 38, .05);
  border-color: var(--red);
}
.narrative-body .finding.neutral {
  background: rgba(37, 99, 235, .05);
  border-color: var(--blue);
}
.narrative-body .finding.warning {
  background: rgba(245, 158, 11, .07);
  border-color: var(--ev-stockout-comp);
}
.narrative-body .finding-icon {
  font-size: .9rem;
  flex-shrink: 0;
  margin-top: .05rem;
}
.narrative-body .finding-text {
  font-size: .82rem;
  line-height: 1.6;
}
.narrative-footer {
  font-size: .72rem;
  color: var(--text-tertiary);
  margin-top: .85rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.narrative-regen {
  font-size: .75rem;
  color: var(--orange);
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .2rem .6rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
}
.narrative-regen:hover {
  background: var(--orange-subtle);
  border-color: var(--orange);
}

/* ──────────────────────────────────────────────────────────────────────────
   SOV Annotated Chart — event annotations + custom tooltip + custom legend
   ────────────────────────────────────────────────────────────────────────── */
.chart-outer { position: relative; }
.chart-wrap  { position: relative; height: 300px; }

.chart-tooltip {
  position: absolute;
  background: var(--text-primary);
  color: #fff;
  font-size: .75rem;
  padding: .6rem .8rem;
  border-radius: 8px;
  pointer-events: none;
  z-index: 20;
  display: none;
  min-width: 190px;
  line-height: 1.6;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.chart-tooltip .tt-month {
  font-weight: 700;
  font-size: .8rem;
  margin-bottom: .35rem;
  border-bottom: 1px solid rgba(255, 255, 255, .15);
  padding-bottom: .3rem;
}
.chart-tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: .15rem 0;
}
.chart-tooltip .tt-val { font-weight: 600; }
.chart-tooltip .tt-events {
  margin-top: .4rem;
  padding-top: .4rem;
  border-top: 1px solid rgba(255, 255, 255, .15);
}
.chart-tooltip .tt-ev {
  display: flex;
  align-items: flex-start;
  gap: .35rem;
  margin: .15rem 0;
  font-size: .7rem;
  opacity: .9;
}
.chart-tooltip .tt-ev-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: .18rem;
}

.ev-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-secondary);
}
.ev-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.ev-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Brand visibility toggle buttons (above annotated chart) */
.btn-brand-toggle {
  padding: .3rem .65rem;
  font-size: .75rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--white);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-brand-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-secondary);
}
.btn-brand-toggle.active {
  background: var(--orange-subtle);
  border-color: var(--orange);
  color: var(--orange);
}
.btn-brand-toggle.active:hover {
  background: var(--orange-glow);
}

/* "Lectura del periodo" story paragraph below the annotated chart */
.sov-chart-story {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg, #f8fafc);
  border-radius: 8px;
  font-size: .82rem;
  line-height: 1.75;
  color: var(--text-secondary);
  border-left: 3px solid var(--orange);
}
.sov-chart-story strong { color: var(--text-primary); }
.sov-chart-story-label {
  display: block;
  margin-bottom: .35rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--orange);
}

