/* ===========================
   TikTok Shop Profit Calculator
   Dark Theme — TikTok Style
   =========================== */

:root {
  /* TikTok Colors */
  --bg-primary: #121212;
  --bg-secondary: #1E1E1E;
  --bg-card: #1A1A2E;
  --bg-input: #2A2A2A;

  --accent: #FE2C55;
  --accent-hover: #E91E45;
  --accent-glow: rgba(254, 44, 85, 0.3);
  --cyan: #25F4EE;
  --cyan-glow: rgba(37, 244, 238, 0.2);

  --text-primary: #FFFFFF;
  --text-secondary: #A0A0A0;
  --text-muted: #666666;

  --border: #333333;
  --border-focus: #FE2C55;

  --profit: #00D26A;
  --profit-glow: rgba(0, 210, 106, 0.2);
  --loss: #FE2C55;
  --loss-glow: rgba(254, 44, 85, 0.2);

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-input: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Reset */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===========================
   Header
   =========================== */
.header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

.header__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.header__icon {
  flex-shrink: 0;
}

.header__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header__title-accent {
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header__subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ===========================
   Main / Calculator Layout
   =========================== */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

.calculator {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .calculator {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* ===========================
   Cards
   =========================== */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}

.card--results {
  background: var(--bg-card);
  border-color: rgba(254, 44, 85, 0.15);
  position: sticky;
  top: 1rem;
}

.card__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card__title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 1.1em;
  background: var(--accent);
  border-radius: 2px;
}

.card--results .card__title::before {
  background: linear-gradient(180deg, var(--accent), var(--cyan));
}

/* ===========================
   Form Grid
   =========================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group--full {
  grid-column: 1 / -1;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-label-value {
  color: var(--cyan);
  font-weight: 600;
}

.form-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  margin-left: 0.25rem;
  border: 1px solid var(--border);
}

/* Inputs */
.input-wrapper {
  position: relative;
}

.input-wrapper--dollar .form-input {
  padding-left: 1.75rem;
}

.input-prefix {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  pointer-events: none;
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* Select arrow */
.form-select {
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23A0A0A0' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
}

.form-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Number input arrows */
.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  opacity: 0.5;
}

/* ===========================
   Slider (Affiliate)
   =========================== */
.form-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-input);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  margin-top: 0.25rem;
}

.form-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-secondary);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s;
}

.form-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.form-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-secondary);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ===========================
   Profit Display
   =========================== */
.profit-display {
  text-align: center;
  padding: 1.5rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  transition: background 0.3s;
}

.profit-display--positive {
  background: var(--profit-glow);
}

.profit-display--negative {
  background: var(--loss-glow);
}

.profit-amount {
  font-size: 2.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  transition: color 0.3s;
}

.profit-amount--positive {
  color: var(--profit);
}

.profit-amount--negative {
  color: var(--loss);
}

.profit-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.profit-margin {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.5rem;
  transition: color 0.3s;
}

.profit-margin--positive {
  color: var(--profit);
}

.profit-margin--negative {
  color: var(--loss);
}

/* ===========================
   Break-even
   =========================== */
.breakeven {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(37, 244, 238, 0.06);
  border: 1px solid rgba(37, 244, 238, 0.15);
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
}

.breakeven__label {
  color: var(--text-secondary);
}

.breakeven__value {
  color: var(--cyan);
  font-weight: 700;
  font-size: 1rem;
}

/* ===========================
   Fee Breakdown Bar
   =========================== */
.breakdown {
  margin-bottom: 1.25rem;
}

.breakdown__title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}

.breakdown__bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-input);
  gap: 1px;
}

.breakdown__segment {
  height: 100%;
  transition: width 0.4s ease;
  min-width: 2px;
}

.breakdown__segment--referral { background: var(--accent); }
.breakdown__segment--shipping { background: #FF9500; }
.breakdown__segment--affiliate { background: #AF52DE; }
.breakdown__segment--cogs { background: #8E8E93; }
.breakdown__segment--profit { background: var(--profit); }
.breakdown__segment--loss { background: var(--loss); }

.breakdown__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot--referral { background: var(--accent); }
.legend-dot--shipping { background: #FF9500; }
.legend-dot--affiliate { background: #AF52DE; }
.legend-dot--cogs { background: #8E8E93; }
.legend-dot--profit { background: var(--profit); }
.legend-dot--loss { background: var(--loss); }

/* ===========================
   Detail Rows
   =========================== */
.details {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.details__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  font-size: 0.9rem;
}

.details__label {
  color: var(--text-secondary);
}

.details__rate {
  color: var(--text-muted);
  font-size: 0.8em;
}

.details__value {
  font-weight: 600;
  color: var(--text-primary);
}

.details__value--negative {
  color: var(--accent);
}

.details__divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

.details__row--total {
  padding-top: 0.5rem;
}

.details__row--total .details__label {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
}

.details__row--total .details__value {
  font-size: 1.15rem;
}

.details__row--total .details__value--positive {
  color: var(--profit);
}

.details__row--total .details__value--negative {
  color: var(--loss);
}

/* ===========================
   Footer
   =========================== */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  margin-top: 1rem;
}

.footer__text {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer__text--muted {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.footer__link {
  color: var(--cyan);
  text-decoration: none;
  font-weight: 500;
}

.footer__link:hover {
  text-decoration: underline;
}

/* ===========================
   Utilities
   =========================== */
.hidden {
  display: none !important;
}

/* ===========================
   Mobile Sticky Bar (hidden on desktop)
   =========================== */
.mobile-sticky {
  display: none;
}

/* ===========================
   Bottom Sheet Popup
   =========================== */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.25s ease;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.popup-overlay.active {
  opacity: 1;
}

.popup-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding: 0.5rem 1.25rem 2rem;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  -webkit-overflow-scrolling: touch;
}

.popup-sheet.active {
  transform: translateY(0);
}

.popup-sheet__handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-muted);
  margin: 0.5rem auto 1rem;
  opacity: 0.5;
}

.popup-sheet__close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.popup-sheet__close:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* Popup content reuses desktop styles */
.popup-sheet__content .profit-display {
  padding: 1rem 0.75rem;
  margin-bottom: 0.75rem;
}

.popup-sheet__content .profit-amount {
  font-size: 2.25rem;
}

.popup-sheet__content .breakeven {
  margin-bottom: 1rem;
}

.popup-sheet__content .breakdown {
  margin-bottom: 1rem;
}

.popup-sheet__content .details__row {
  padding: 0.35rem 0;
  font-size: 0.85rem;
}

/* ===========================
   Mobile Responsive
   =========================== */
@media (max-width: 767px) {
  .header__title {
    font-size: 1.25rem;
  }

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

  .card {
    padding: 1.25rem;
  }

  /* --- Results card becomes sticky container on mobile --- */
  .card--results {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  /* Hide desktop detail content on mobile */
  .card--results > .card__title,
  .card--results > .profit-display,
  .card--results > .breakeven,
  .card--results > .breakdown,
  .card--results > .details {
    display: none;
  }

  /* --- Mobile Sticky Bar --- */
  .mobile-sticky {
    display: block;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1rem 0.4rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.3s;
  }

  .mobile-sticky--positive {
    background: linear-gradient(135deg, rgba(0, 210, 106, 0.12), var(--bg-card) 60%);
    border-bottom-color: rgba(0, 210, 106, 0.2);
  }

  .mobile-sticky--negative {
    background: linear-gradient(135deg, rgba(254, 44, 85, 0.12), var(--bg-card) 60%);
    border-bottom-color: rgba(254, 44, 85, 0.2);
  }

  .mobile-sticky__content {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .mobile-sticky__left {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
  }

  .mobile-sticky__profit {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    transition: color 0.3s;
  }

  .mobile-sticky__profit--positive { color: var(--profit); }
  .mobile-sticky__profit--negative { color: var(--loss); }

  .mobile-sticky__margin {
    font-size: 0.8rem;
    font-weight: 600;
    transition: color 0.3s;
  }

  .mobile-sticky__margin--positive { color: var(--profit); }
  .mobile-sticky__margin--negative { color: var(--loss); }

  .mobile-sticky__right {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
  }

  .mobile-sticky__be-label {
    color: var(--text-muted);
    font-weight: 500;
  }

  .mobile-sticky__be-value {
    color: var(--cyan);
    font-weight: 700;
    font-size: 0.9rem;
  }

  .mobile-sticky__chevron {
    color: var(--text-muted);
    margin-left: 0.15rem;
    flex-shrink: 0;
    transition: transform 0.2s;
  }

  .mobile-sticky__bar {
    display: flex;
    height: 4px;
    border-radius: 2px;
    overflow: hidden;
    background: var(--bg-input);
    gap: 1px;
    margin-top: 0.4rem;
  }

  .mobile-sticky__bar .breakdown__segment {
    height: 100%;
    min-width: 2px;
    transition: width 0.4s ease;
  }

  /* Reorder: on mobile, results card comes first (order) */
  .calculator {
    display: flex;
    flex-direction: column;
  }

  .card--results {
    order: -1;
  }
}

/* ===========================
   Animations
   =========================== */
@keyframes pulse-profit {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.profit-amount.animate {
  animation: pulse-profit 0.3s ease;
}

/* Smooth transitions for conditional fields */
.form-group {
  transition: opacity 0.2s, max-height 0.2s;
}
