:root {
  --bg-color: var(--tg-theme-bg-color, #1a1a2e);
  --text-color: var(--tg-theme-text-color, #ffffff);
  --hint-color: var(--tg-theme-hint-color, #8b8b9e);
  --link-color: var(--tg-theme-link-color, #6c5ce7);
  --button-color: var(--tg-theme-button-color, #6c5ce7);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #252542);
  
  --card-sales: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-orders: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --card-stocks: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --card-avg: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  --card-buyout: linear-gradient(135deg, #ff9500 0%, #ff5e3a 100%);
  --card-warehouses: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);
  
  --success: #00d26a;
  --warning: #ffc107;
  --danger: #ff4757;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  padding: 0;
  overflow-x: hidden;
}

#app {
  max-width: 100%;
  padding: 16px;
  padding-bottom: 80px;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 8px 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 28px;
}

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.period-selector {
  display: flex;
  gap: 4px;
  background: var(--secondary-bg);
  padding: 4px;
  border-radius: 12px;
}

.period-btn {
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--hint-color);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.period-btn.active {
  background: var(--button-color);
  color: var(--button-text-color);
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 16px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--button-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading p {
  color: var(--hint-color);
  font-size: 14px;
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.card-sales::before { background: var(--card-sales); }
.card-orders::before { background: var(--card-orders); }
.card-stocks::before { background: var(--card-stocks); }
.card-avg::before { background: var(--card-avg); }
.card-buyout::before { background: var(--card-buyout); }
.card-warehouses::before { background: var(--card-warehouses); }

.card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.card-icon {
  font-size: 16px;
}

.card-title {
  font-size: 11px;
  color: var(--hint-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 11px;
  color: var(--hint-color);
}

.revenue-value {
  color: var(--success);
  font-weight: 600;
}

.card-meta {
  margin-top: 8px;
  font-size: 11px;
}

.cancelled {
  color: var(--danger);
}

/* Chart Sections */
.chart-section {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.section-header {
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.chart-container {
  position: relative;
  height: 200px;
}

.chart-container.small {
  height: 160px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chart-container.small canvas {
  max-width: 100%;
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.chart-section.half {
  margin-bottom: 0;
}

/* Products Section */
.products-section {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.products-count {
  font-size: 12px;
  color: var(--hint-color);
}

.products-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-item {
  display: flex;
  align-items: flex-start;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}

.product-item:hover {
  background: rgba(255,255,255,0.1);
}

.product-rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--button-color);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.product-info {
  flex: 1;
  min-width: 0;
}

.product-name {
  font-size: 13px;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.product-article {
  font-size: 10px;
  color: var(--hint-color);
  margin-top: 2px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.product-meta-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--hint-color);
}

.product-stats {
  text-align: right;
  flex-shrink: 0;
}

.product-revenue {
  font-size: 13px;
  font-weight: 600;
  color: var(--success);
}

.product-share {
  font-size: 10px;
  color: var(--button-color);
}

.product-count {
  font-size: 10px;
  color: var(--hint-color);
}

.product-stock {
  font-size: 10px;
  color: var(--hint-color);
  margin-top: 2px;
}

/* All Products Section */
.all-products-section {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.products-search {
  margin-bottom: 12px;
}

.products-search input {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: var(--text-color);
  font-size: 14px;
}

.products-search input::placeholder {
  color: var(--hint-color);
}

.products-sort {
  margin-bottom: 12px;
}

.products-sort select {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: var(--text-color);
  font-size: 14px;
  cursor: pointer;
}

.all-products-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.product-item-full {
  display: block;
  padding: 16px;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}

.product-item-full:hover {
  background: rgba(255,255,255,0.1);
}

.product-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.product-index {
  font-size: 12px;
  color: var(--hint-color);
  font-weight: 600;
}

.product-name-full {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.product-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}

.product-detail-row {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 10px;
  color: var(--hint-color);
}

.detail-value {
  font-size: 12px;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.product-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  text-align: center;
  padding: 10px 6px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
}

.stat-box.orders { border-top: 2px solid #f093fb; }
.stat-box.sales { border-top: 2px solid #667eea; }
.stat-box.buyout { border-top: 2px solid #ff9500; }
.stat-box.stock { border-top: 2px solid #4facfe; }

.stat-value {
  font-size: 14px;
  font-weight: 700;
}

.stat-label {
  font-size: 10px;
  color: var(--hint-color);
  margin-top: 2px;
}

.product-revenue-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.revenue-big {
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
}

.revenue-share {
  font-size: 12px;
  color: var(--button-color);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: var(--text-color);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.page-btn:hover {
  background: rgba(255,255,255,0.2);
}

.page-btn.active {
  background: var(--button-color);
  color: var(--button-text-color);
}

.page-dots {
  color: var(--hint-color);
  padding: 0 4px;
}

/* Warning Section */
.warning-section {
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid rgba(255, 193, 7, 0.3);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.warning-section .section-header h2 {
  color: var(--warning);
}

.warning-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warning-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}

.warning-item:hover {
  background: rgba(255,255,255,0.1);
}

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

.warning-item-name {
  font-size: 13px;
  font-weight: 500;
  word-wrap: break-word;
}

.warning-item-details {
  font-size: 10px;
  color: var(--hint-color);
  margin-top: 2px;
}

.warning-item-warehouse {
  font-size: 10px;
  color: var(--hint-color);
  margin-top: 2px;
}

.warning-item-qty {
  font-size: 13px;
  font-weight: 600;
  color: var(--warning);
}

/* Error */
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  text-align: center;
}

.error-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.error p {
  color: var(--hint-color);
  margin-bottom: 20px;
}

.retry-btn {
  padding: 12px 32px;
  background: var(--button-color);
  color: var(--button-text-color);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px;
  background: var(--bg-color);
  text-align: center;
  border-top: 1px solid var(--secondary-bg);
}

.footer a {
  color: var(--hint-color);
  text-decoration: none;
  font-size: 12px;
}

/* Responsive */
@media (max-width: 600px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
  
  .chart-section.half {
    margin-bottom: 12px;
  }
  
  .product-details {
    grid-template-columns: 1fr 1fr;
  }
  
  .product-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 360px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  
  .card-value {
    font-size: 20px;
  }
  
  .product-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
