:host { display: block; }

.stock-card-page {
  max-width: 1400px;
  margin: 0 auto;

  .text-end { text-align: end; }
  .text-center { text-align: center; }
  .mono { font-family: monospace; }
  .text-success { color: #10b981 !important; font-weight: 700; }
  .text-danger { color: #ef4444 !important; font-weight: 700; }
}

.page-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.product-info {
  h2 { margin: 0; font-size: 1.4rem; font-weight: 800; color: #1e293b; }
  .product-code { font-size: .82rem; color: #94a3b8; font-weight: 600; }
  .variant-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 700;
    padding: .2rem .6rem;
    border-radius: 999px;
    background: rgba(99,102,241,0.12);
    color: #6366f1;
    margin-inline-start: .5rem;
    vertical-align: middle;
  }
}

// Collapsible section
.collapsible-section {
  margin-bottom: 1rem;

  .collapse-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 1rem;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-surface-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-brand, #1a237e);
    transition: all 0.2s;

    &:hover { background: var(--color-surface-muted, #f8fafc); }

    i { font-size: 0.8rem; }

    .collapse-summary {
      font-weight: 400;
      font-size: 0.8125rem;
      color: var(--color-text-secondary, #64748b);
      margin-inline-start: auto;

      strong { color: var(--color-text-primary, #1e293b); }
    }
  }

  &:not(.collapsed) .collapse-toggle {
    border-radius: 8px 8px 0 0;
    border-bottom: none;
    margin-bottom: 0;
  }

  &:not(.collapsed) .stats-grid {
    margin-top: 0;
  }
}

// Stats grid
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  position: relative;
  overflow: hidden;
  background: white;
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 1px solid rgba(0,0,0,0.05);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all .3s;
  &:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(0,0,0,0.08); }
}

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  i { font-size: 1.25rem; color: white; }
}

.stat-info {
  display: flex;
  flex-direction: column;
  .stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; color: #1e293b; }
  .stat-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; margin-top: .2rem; }
}

.stat-decoration {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  top: -40px;
  right: -40px;
  opacity: .06;
}

@each $n, $c1, $c2 in (blue, #3b82f6, #2563eb), (green, #10b981, #059669), (amber, #f59e0b, #d97706), (rose, #f43f5e, #e11d48), (purple, #8b5cf6, #7c3aed) {
  .stat-#{$n} {
    border-top: 3px solid $c1;
    .stat-icon-wrap { background: linear-gradient(135deg, $c1, $c2); box-shadow: 0 4px 12px rgba($c1, .3); }
    .stat-decoration { background: $c1; }
  }
}

// Charts
.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: white;
  border-radius: 1rem;
  border: 1px solid rgba(0,0,0,0.05);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
}

.chart-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}

.chart-title-wrap {
  display: flex;
  align-items: center;
  gap: .75rem;
  h3 { margin: 0; font-size: .95rem; font-weight: 700; color: #1e293b; }
}

.chart-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  i { font-size: 1.1rem; }
}

.chart-body {
  padding: 1rem 1.5rem 1.5rem;
  &.doughnut-chart {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.no-chart-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #94a3b8;
  font-size: .9rem;
}

// Section card
.section-card {
  background: white;
  border-radius: 1rem;
  border: 1px solid rgba(0,0,0,0.05);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  flex-wrap: wrap;
  gap: .75rem;
  h3 {
    margin: 0;
    font-size: .95rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: .5rem;
    i { color: #6366f1; }
  }
}

.filter-controls {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.date-presets {
  display: flex;
  gap: .25rem;
}

.date-range-inputs {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 1rem;
  padding: 5rem 2rem;
  border: 1px solid rgba(0,0,0,0.05);
  p { color: #94a3b8; margin-top: 1rem; }
}

// Costing section
.costing-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0;

  .cost-stat {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 1.25rem 1rem;
    border-inline-end: 1px solid rgba(0,0,0,0.04);

    &:last-child { border-inline-end: none; }

    .cost-stat-label {
      font-size: 0.7rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: #94a3b8;
    }
    .cost-stat-value {
      font-size: 1.25rem;
      font-weight: 800;
      color: #1e293b;
    }
  }
}

.fw-bold { font-weight: 700; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
}

.exhausted-row {
  opacity: 0.5;
  td { text-decoration: line-through; }
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .page-header-bar { flex-direction: column; align-items: flex-start; }
}

// ─── Dark Mode ───
body.dark-mode {
  .product-info {
    h2 { color: var(--color-text-primary); }
    .product-code { color: #64748b; }
  }

  .stat-card {
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(12px);
    border-color: rgba(255, 255, 255, 0.06);
  }
  .stat-info {
    .stat-value { color: var(--color-text-primary); }
    .stat-label { color: #94a3b8; }
  }

  .chart-card, .section-card {
    background: rgba(17, 24, 39, 0.7);
    backdrop-filter: blur(12px);
    border-color: rgba(255, 255, 255, 0.06);
  }
  .chart-header { border-bottom-color: rgba(255, 255, 255, 0.06); }
  .chart-title-wrap h3 { color: var(--color-text-primary); }
  .no-chart-data { color: #64748b; }

  .section-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
    h3 { color: var(--color-text-primary); }
  }

  .loading-state {
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(12px);
    border-color: rgba(255, 255, 255, 0.06);
    p { color: #94a3b8; }
  }

  .costing-summary .cost-stat {
    border-inline-end-color: rgba(255, 255, 255, 0.06);
    .cost-stat-label { color: #94a3b8; }
    .cost-stat-value { color: var(--color-text-primary); }
  }

  .toggle-label { color: #94a3b8; }
}
