/* Walmart Sales Intelligence — Modern Responsive Styles */
/* CSS Grid, Flexbox, SVG, CSS Animations, 3D Flip Cards & Mobile Optimization */

/* ==========================================================================
   1. Animation Keyframes
   ========================================================================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulseBadge {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(0, 83, 226, 0.25);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(0, 83, 226, 0);
  }
}

@keyframes bounceHint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.page-view:not(.hidden) {
  animation: fadeInUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   2. Sidebar & Navigation (SVG Icons & Touch-Friendly Horizontal Scroll)
   ========================================================================== */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.page-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-nav .nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 13px;
  padding: 11px 14px;
  border-radius: 11px;
  line-height: 1.45;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  transition: transform 0.2s ease;
}

.page-nav .nav-item:hover {
  background: var(--subtle);
  color: var(--ink);
  transform: translateX(2px);
}

.page-nav .nav-item:hover .nav-icon {
  transform: scale(1.1);
}

.page-nav .nav-item.active {
  background: var(--soft);
  color: var(--blue);
  border-color: var(--line);
  font-weight: 800;
}

.page-nav .nav-item.active:before {
  content: "";
  position: absolute;
  left: -1px;
  top: 10px;
  bottom: 10px;
  width: 3.5px;
  background: var(--blue);
  border-radius: 4px;
}

.page-view[hidden] {
  display: none !important;
}

.page-title:focus {
  outline: none;
}

/* ==========================================================================
   3. 3D Flip Cards & Metric Business Insights (CSS 3D Transforms & Dynamic HTML)
   ========================================================================== */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.flip-card {
  perspective: 1200px;
  cursor: pointer;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  min-height: 156px;
  height: 156px;
  outline: none;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: left;
  transition: transform 0.65s cubic-bezier(0.34, 1.25, 0.64, 1);
  transform-style: preserve-3d;
}

.flip-card:hover .flip-card-inner,
.flip-card:focus-within .flip-card-inner,
.flip-card.is-flipped .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: var(--white);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.flip-card:hover .flip-card-front {
  border-color: var(--blue);
  box-shadow: 0 8px 26px rgba(0, 83, 226, 0.12);
}

.flip-card-front:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3.5px;
  background: var(--blue);
}

.card.yellow .flip-card-front:before {
  background: var(--yellow);
}

.card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-top-row .label {
  font-size: 11px;
  font-weight: 750;
  color: var(--muted);
}

.card-icon-svg {
  width: 20px;
  height: 20px;
  color: var(--blue);
  opacity: 0.85;
}

.card.yellow .card-icon-svg {
  color: #d79b00;
}

.flip-card-front .value {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-top: 6px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.flip-card-front .detail {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.flip-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 9.5px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-top: 4px;
  opacity: 0.75;
  transition: opacity 0.2s, color 0.2s;
}

.flip-card:hover .flip-hint {
  opacity: 1;
  color: var(--blue);
  animation: bounceHint 1.2s infinite;
}

/* 3D Flip Back (Metric Intelligence & Business Takeaway) */
.flip-card-back {
  transform: rotateY(180deg);
  background: var(--subtle);
  border-color: var(--blue);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card.yellow .flip-card-back {
  border-color: var(--yellow);
}

.flip-card-back:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3.5px;
  background: linear-gradient(90deg, var(--blue), var(--yellow));
}

.metric-back-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.metric-back-badge {
  background: var(--soft);
  color: var(--blue);
  padding: 2.5px 8px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.card.yellow .metric-back-badge {
  background: rgba(255, 194, 32, 0.18);
  color: #a06e00;
}

.metric-back-icon {
  color: var(--muted);
  display: flex;
  align-items: center;
  opacity: 0.8;
}

.metric-back-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 3px 0;
  line-height: 1.25;
}

.metric-back-desc {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.35;
  margin: 0 0 5px 0;
  flex: 1;
}

.metric-back-takeaway {
  font-size: 9.5px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  padding: 5px 8px;
  border-radius: 6px;
}

.card.yellow .metric-back-takeaway {
  border-left-color: var(--yellow);
}

.metric-back-takeaway strong {
  color: var(--blue);
  font-weight: 750;
}

.card.yellow .metric-back-takeaway strong {
  color: #a06e00;
}

/* ==========================================================================
   Power BI Interactive Cross-Filter Banner
   ========================================================================== */
.cross-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--soft);
  border: 1px solid var(--blue);
  border-left: 4px solid var(--blue);
  border-radius: 11px;
  padding: 9px 15px;
  margin-bottom: 16px;
  animation: fadeInUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 16px rgba(0, 83, 226, 0.08);
}

.cross-filter-banner.hidden {
  display: none !important;
}

.cross-filter-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink);
}

.cross-filter-icon {
  display: flex;
  align-items: center;
  color: var(--blue);
  flex-shrink: 0;
}

.cross-filter-text {
  font-weight: 700;
  color: var(--ink);
}

.cross-filter-tags {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.cross-filter-tag {
  background: var(--blue);
  color: #ffffff;
  padding: 2.5px 9px;
  border-radius: 6px;
  font-weight: 750;
  font-size: 11px;
  letter-spacing: 0.2px;
  box-shadow: 0 2px 6px rgba(0, 83, 226, 0.25);
}

.cross-filter-hint {
  font-size: 10.5px;
  color: var(--muted);
  font-style: italic;
}

.clear-filter-btn {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--blue);
  font-size: 11.5px;
  font-weight: 750;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.clear-filter-btn:hover {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 83, 226, 0.2);
}

/* ==========================================================================
   4. Donut Chart Styles (Holiday Impact)
   ========================================================================== */
.donut-plot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-center-badge {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-center-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: -0.6px;
  line-height: 1.1;
}

.donut-center-label {
  font-size: 9.5px;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 3px;
}

[data-theme="dark"] .donut-center-value {
  color: var(--yellow);
}

/* ==========================================================================
   5. Filters & Controls (CSS Grid & Flexbox)
   ========================================================================== */
.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) minmax(135px, 160px);
  gap: 12px;
  margin: 22px 0;
  align-items: stretch;
}

.filter-reset-wrap {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--white);
}

.reset-filter-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .65px;
  margin-bottom: 8px;
}

.filter-reset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 28px;
  padding: 5px 12px;
  background: var(--soft);
  color: var(--blue);
  border: 1px solid rgba(0, 83, 226, 0.2);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.filter-reset-btn:hover {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 83, 226, 0.25);
}

.filter-reset-btn svg,
.top-reset-btn svg {
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.filter-reset-btn:hover svg,
.top-reset-btn:hover svg {
  transform: rotate(-45deg);
}

/* Top bar reset button */
.top-reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 750;
  border-color: var(--line);
}

.top-reset-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

[data-theme="dark"] .filter-reset-btn {
  background: var(--soft);
  color: var(--blue);
  border-color: rgba(138, 180, 255, 0.25);
}

[data-theme="dark"] .filter-reset-btn:hover {
  background: var(--blue);
  color: #0b1930;
}

.filters.filters-three {
  grid-template-columns: repeat(3, minmax(130px, 1fr));
}

.page-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 17px;
}

.page-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 150px;
}

.control label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.control select,
.control input {
  min-height: 41px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.control select:focus,
.control input:focus {
  border-color: var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.control.search-control {
  flex: 1;
  min-width: 210px;
}

.control input {
  width: 100%;
}

.page-toolbar .sub {
  max-width: 500px;
}

.page-note {
  margin: 0 0 17px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.page-charts {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.page-charts .panel {
  min-width: 0;
}

.page-charts .plot {
  height: 300px;
}

/* ==========================================================================
   6. Compare Stores Toolbar & Store Picker
   ========================================================================== */
.compare-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.compare-actions .btn.sm {
  padding: 7px 12px;
  font-size: 11px;
  min-height: 36px;
  border-radius: 9px;
  box-shadow: none;
}

.compare-search {
  min-height: 36px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--white);
  color: var(--ink);
  font-size: 11px;
  max-width: 135px;
  outline: none;
  transition: border-color 0.2s;
}

.compare-search:focus {
  border-color: var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.compare-period-control {
  min-width: 110px;
}

.compare-period-control label {
  display: none;
}

.compare-period-control select {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
}

.store-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 165px;
  overflow: auto;
  padding: 4px 2px;
  margin-top: 12px;
  scrollbar-width: thin;
}

.store-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  background: var(--subtle);
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.store-chip:hover {
  background: var(--hover);
  color: var(--ink);
  border-color: var(--blue);
}

.store-chip.selected {
  border-color: var(--blue);
  background: var(--soft);
  color: var(--blue);
  font-weight: 750;
}

.store-chip input {
  accent-color: var(--blue);
  margin: 0;
  cursor: pointer;
}

.store-chip:focus-within {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ==========================================================================
   7. Data Tables & Pagination
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 11px;
  scrollbar-width: thin;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
  text-align: left;
}

.data-table th {
  background: var(--subtle);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: var(--subtle);
}

/* Power BI-Style Interactive Click-to-Filter Tables */
.data-table.table-interactive tbody tr.clickable-row {
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.data-table.table-interactive tbody tr.clickable-row:hover {
  background: var(--soft) !important;
}

.data-table.table-interactive tbody tr.clickable-row:hover td {
  color: var(--blue);
  font-weight: 600;
}

.data-table.table-interactive tbody tr.clickable-row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.data-table .numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .table-empty {
  text-align: center;
  padding: 36px;
  color: var(--muted);
  font-size: 13px;
}

.table-caption {
  font-size: 11px;
  line-height: 1.7;
  margin: 12px 0 0;
  color: var(--muted);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 15px;
}

.pagination-actions {
  display: flex;
  gap: 8px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.change-up {
  color: #137743 !important;
}

.change-down {
  color: #b23b39 !important;
}

[data-theme="dark"] .change-up {
  color: #7edbac !important;
}

[data-theme="dark"] .change-down {
  color: #ffa5a3 !important;
}

.page-view .card .detail {
  line-height: 1.5;
}

.page-view .card .value {
  font-variant-numeric: tabular-nums;
}

.empty-chart-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ==========================================================================
   8. Mobile & Phone Responsive Optimizations (Screens <= 1180px, 780px, 480px)
   ========================================================================== */
@media (max-width: 1180px) {
  .page-charts {
    grid-template-columns: 1fr;
  }
  .filters.filters-three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  /* Sticky Top Mobile Header with Horizontal Navigation Bar */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: auto;
    overflow: visible;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: var(--white);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  }

  .sidebar .logo {
    width: 135px;
    align-self: flex-start;
  }

  /* Touch-Friendly Horizontal Scrolling Nav Bar */
  .page-nav {
    display: flex !important;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 7px;
    padding: 2px 1px 8px;
    scrollbar-width: none;
  }

  .page-nav::-webkit-scrollbar {
    display: none;
  }

  .page-nav .nav-item {
    display: flex !important;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 9px;
  }

  .page-nav .nav-item.active:before {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 0;
    height: 3px;
    width: auto;
  }

  .sidefoot {
    display: none;
  }

  .main {
    padding: 16px 14px 45px;
  }

  /* Top Bar Actions & Buttons on Mobile */
  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .top h1 {
    font-size: 24px;
    margin: 4px 0 6px;
  }

  .actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .actions .btn,
  .actions .upload-label {
    flex: 1;
    justify-content: center;
    padding: 10px 12px;
    font-size: 11.5px;
    text-align: center;
  }

  /* Filters on Mobile */
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
    margin: 16px 0;
  }

  .filters .filter-reset-wrap {
    grid-column: span 2;
  }

  .filters.filters-three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter {
    padding: 10px 12px;
  }

  /* 3D Flip Cards on Phone */
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .flip-card {
    min-height: 154px;
    height: 154px;
  }

  .flip-card-front,
  .flip-card-back {
    padding: 13px 14px;
  }

  .flip-card-front .value {
    font-size: 20px;
  }

  .metric-back-title {
    font-size: 11px;
  }

  .metric-back-desc {
    font-size: 9px;
    line-height: 1.3;
  }

  .metric-back-takeaway {
    font-size: 8.5px;
    padding: 4px 6px;
  }

  /* Charts on Mobile */
  .chart-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .wide {
    grid-column: span 1;
  }

  .panel {
    padding: 16px 15px;
    border-radius: 13px;
  }

  .plot {
    height: 255px;
  }

  .plot.sm {
    height: 240px;
  }

  .page-charts .plot {
    height: 260px;
  }

  .insights {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Compare Stores on Mobile */
  .compare-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .compare-actions .btn.sm {
    flex: 1;
    min-width: 75px;
    text-align: center;
  }

  .compare-search {
    width: 100%;
    max-width: 100%;
  }

  .compare-period-control {
    width: 100%;
  }

  .store-picker {
    max-height: 175px;
  }

  .store-chip {
    padding: 6px 9px;
    font-size: 10.5px;
  }

  .page-controls {
    width: 100%;
  }

  .control {
    flex: 1;
    min-width: 135px;
  }
}

/* Narrow Phone Screens (iPhone SE, Small Androids <= 420px) */
@media (max-width: 420px) {
  .main {
    padding: 12px 10px 40px;
  }

  .top h1 {
    font-size: 21px;
  }

  .filters {
    grid-template-columns: 1fr !important;
  }

  .filters .filter-reset-wrap {
    grid-column: span 1;
  }

  .filters.filters-three {
    grid-template-columns: 1fr;
  }

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

  .flip-card {
    min-height: 150px;
    height: 150px;
  }

  .flip-card-front .value {
    font-size: 21px;
  }

  .plot {
    height: 240px;
  }

  .plot.sm {
    height: 230px;
  }

  .donut-center-value {
    font-size: 17px;
  }

  .donut-center-label {
    font-size: 8.5px;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn,
  .actions .upload-label {
    width: 100%;
  }
}
