/* =============================================================
   WB Profit Calculator — Master Stylesheet
   ============================================================= */

:root {
  --bg-base: #0d0f14;
  --bg-surface: #0a0b0e;
  --bg-card: #16181d;
  --bg-elevated: #21242c;
  --bg-input: #1a1d23;
  --bg-hover: #2d313a;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(203, 17, 171, 0.4);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #cb11ab;
  --accent-light: #e82cd5;
  --accent-gradient: linear-gradient(135deg, #cb11ab 0%, #4834d4 100%);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.1);
  --red: #f87171;
  --red-dim: rgba(239, 68, 68, 0.1);
  --yellow: #fbbf24;
  --yellow-dim: rgba(245, 158, 11, 0.1);
  --blue: #3b82f6;
  --sidebar-w: 260px;
  --radius: 14px;
  --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  margin: 0; overflow-x: hidden;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; bottom: 0; top: 0; left: 0; z-index: 1000;
  transition: transform 0.3s ease;
}
.sidebar-logo { padding: 24px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.sidebar-logo-icon { width: 32px; height: 32px; background: var(--accent-gradient); border-radius: 6px; flex-shrink:0; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; }
.sidebar-logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-logo-title { font-weight: 700; font-size: 14px; color: #fff; }
.sidebar-logo-sub { font-size: 10px; color: var(--text-muted); }

.sidebar-nav { padding: 15px 10px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 15px; margin-bottom: 2px;
  color: var(--text-secondary); text-decoration: none; font-size: 14px; font-weight: 500; border-radius: 8px;
}
.nav-item:hover { background: var(--bg-hover); color: #fff; }
.nav-item.active { background: rgba(108, 99, 255, 0.1); color: var(--accent); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ===================== MAIN & PAGES ===================== */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.page { display: none; padding: 32px; animation: fadeIn 0.15s ease; }
.page.active { display: block; }
.mobile-header { display: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 15px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 800; }

/* ===================== SUMMARY GRID ===================== */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.summary-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.sc-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 8px; }
.sc-value { font-size: 20px; font-weight: 800; color: #fff; }
.summary-card-profit { background: var(--green-dim); border-color: rgba(16, 185, 129, 0.2); }
.summary-card-profit .sc-value { color: var(--green); }

/* ===================== BREAKDOWN ===================== */
.calc-breakdown {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
}
.calc-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 15px;
}
.calc-row.sub {
  font-size: 13px;
  color: var(--text-secondary);
  padding-left: 20px;
  padding-top: 4px;
  padding-bottom: 4px;
}
.calc-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}
.calc-total {
  font-size: 20px;
  font-weight: 700;
  color: var(--blue);
}
.calc-value { font-weight: 700; color: #fff; min-width: 80px; text-align: right; }
.calc-value.neg { color: #f87171; }
.calc-value.pos { color: #4ade80; }

/* Table Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--border);
}
.badge-success { background: rgba(74, 222, 128, 0.1); color: #4ade80; }
.badge-danger { background: rgba(248, 113, 113, 0.1); color: #f87171; }
.badge-warn { background: rgba(251, 191, 36, 0.1); color: #fbbf24; }

.row-warn { background: rgba(248, 113, 113, 0.05); }

/* Compact table for details */
.data-table th.text-right, .data-table td.text-right {
  padding-left: 8px;
  padding-right: 8px;
}

/* ===================== SKU GRID ===================== */
.sku-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-top: 10px; }
.sku-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: 0.2s; position: relative; }
.sku-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.sku-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.sku-card-title { font-size: 16px; font-weight: 700; color: #a89fff; }
.sku-card-name { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.sku-card-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 15px; }
.sku-metric { background: var(--bg-elevated); padding: 10px; border-radius: 8px; }
.sku-metric-label { font-size: 9px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 3px; }
.sku-metric-value { font-size: 14px; font-weight: 600; color: #fff; }
.sku-card-wb { font-size: 11px; color: var(--text-muted); margin-top: 10px; }
.sku-card-comment { font-size: 11px; font-style: italic; color: var(--text-secondary); margin-top: 8px; opacity: 0.8; }
.sku-card-actions { display: flex; gap: 6px; }

/* ===================== IMPORTS (UPLOAD CARDS) ===================== */
.import-upload-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }
.upload-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.upload-title { font-size: 16px; font-weight: 700; margin-bottom: 15px; color: #fff; }
.upload-drop-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 30px; text-align: center; color: var(--text-secondary); cursor: pointer; transition: 0.2s; }
.upload-drop-zone:hover { border-color: var(--accent); background: rgba(203, 17, 171, 0.05); }
.upload-progress { margin-top: 15px; }
.progress-bar { height: 6px; background: var(--bg-elevated); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent-gradient); width: 0; transition: width 0.3s; }

/* Custom report card */
.upload-card-custom {
  border: 1px solid rgba(203, 17, 171, 0.35);
  background: linear-gradient(135deg, rgba(203,17,171,0.05) 0%, rgba(72,52,212,0.05) 100%);
  grid-column: span 2;
}
.upload-card-custom .upload-drop-zone:hover {
  border-color: #cb11ab;
  background: rgba(203,17,171,0.08);
}

/* File-type badges */
.file-type-badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.file-type-main { background: rgba(59,130,246,0.15); color: #60a5fa; }
.file-type-buyout { background: rgba(16,185,129,0.15); color: #34d399; }
.file-type-storage { background: rgba(245,158,11,0.15); color: #fbbf24; }
.file-type-advertising { background: rgba(248,113,113,0.15); color: #f87171; }
.file-type-custom { background: linear-gradient(135deg, rgba(203,17,171,0.2), rgba(72,52,212,0.2)); color: #e82cd5; }

/* Utility */
.mt-2 { margin-top: 16px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.hidden { display: none !important; }

/* ===================== TABLES ===================== */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.card-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.table-container { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 12px 16px; text-align: left; background: var(--bg-elevated); color: var(--text-muted); font-size: 11px; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tr:hover td { background: var(--bg-hover); }
.text-right { text-align: right; }

/* ===================== MODALS ===================== */
.modal-overlay { 
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); 
  backdrop-filter: blur(5px); z-index: 5000; align-items: center; justify-content: center; 
}
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; width: 600px; max-width: 95vw; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; }

/* ===================== BUTTONS & INPUTS ===================== */
.btn { 
  display: inline-flex; 
  align-items: center; 
  gap: 8px; 
  padding: 10px 20px; 
  border-radius: 10px; 
  font-weight: 600; 
  font-size: 13px; 
  border: none; 
  cursor: pointer; 
  font-family: inherit; 
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary { 
  background: var(--accent-gradient); 
  color: #fff; 
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4);
}

.btn-ghost { 
  background: var(--bg-elevated); 
  color: var(--text-secondary); 
  border: 1px solid var(--border); 
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: var(--text-muted);
}

.btn-danger { 
  background: rgba(248, 113, 113, 0.1); 
  color: #f87171; 
  border: 1px solid rgba(248, 113, 113, 0.2); 
}
.btn-danger:hover {
  background: #f87171;
  color: #fff;
}

.btn-icon { padding: 10px; border-radius: 8px; }

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-light);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  font-size: 13px;
  transition: 0.2s;
  display: inline-block;
}
.btn-link:hover {
  color: #fff;
  text-decoration: underline;
  transform: translateX(2px);
}

.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }

.form-input { 
  width: 100%; 
  background: var(--bg-input); 
  border: 1px solid var(--border); 
  padding: 12px 16px; 
  border-radius: 10px; 
  color: #fff; 
  outline: none; 
  font-family: inherit; 
  font-size: 14px;
  transition: all 0.2s;
}
.form-input:focus { 
  border-color: var(--accent); 
  background: rgba(255,255,255,0.05);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.1);
}
.form-input::placeholder { color: var(--text-muted); }

/* ===================== TABS IN MODAL ===================== */
.details-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.details-tab {
  flex: 1 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  white-space: nowrap;
}
.details-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}
.details-tab.active {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.details-tab-content { display: none; }
.details-tab-content.active { display: block; }

/* ===================== RESPONSIVE & UTILS ===================== */
@media (max-width: 1400px) { .summary-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1100px) { .summary-grid { grid-template-columns: repeat(2, 1fr); } .import-upload-grid { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .page { padding: 20px 14px; }
  .sidebar {
    transform: translateX(-100%);
    top: 0;
    height: 100dvh;
    padding-top: 64px;
    z-index: 1400;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: 20px 0 60px #000; }
  .sidebar-nav { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .nav-item { touch-action: manipulation; }
  .main-content { margin-left: 0; }
  .mobile-header { display: flex; align-items: center; justify-content: space-between; padding: 15px; background: var(--bg-surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1500; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; background: var(--bg-elevated); color: #fff; border: 1px solid var(--border); border-radius: 10px; width: 40px; height: 40px; }
  .page-header-actions { width: 100%; }
  .page-header-actions .form-input { min-width: 0; }
  .modal {
    width: 100vw !important;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  .modal-header, .modal-footer { padding-left: 14px; padding-right: 14px; }
  .modal-body { padding: 14px; }
  .details-tab { flex: 0 0 auto; }
  .details-tabs { margin: 0 14px 12px; }
}
@media (max-width: 600px) {
  .summary-grid { grid-template-columns: 1fr; gap: 10px; }
  .page-title { font-size: 20px; }
  .btn { padding: 9px 12px; font-size: 12px; }
  .calc-row { font-size: 13px; align-items: flex-start; gap: 8px; }
  .calc-row.sub { font-size: 12px; padding-left: 10px; }
  .calc-value, .calc-total { font-size: 16px; }
  .upload-card { padding: 14px; }
  .upload-drop-zone { padding: 18px 12px; }
  .sku-grid { grid-template-columns: 1fr; }
  .table-container { -webkit-overflow-scrolling: touch; }
  .data-table th, .data-table td { padding: 10px 12px; }
}
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1300; }
.sidebar-overlay.active { display: block; }
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--bg-elevated); color: #fff; padding: 12px 20px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); border-left: 4px solid var(--accent); }

.mobile-bottom-nav { display: none; }
@media (max-width: 900px) {
  .main-content { padding-bottom: 74px; }
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1700;
    background: rgba(10, 11, 14, 0.95);
    border-top: 1px solid var(--border);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }
  .mobile-bottom-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    touch-action: manipulation;
  }
  .mobile-bottom-link.active {
    color: #fff;
    border-color: rgba(203, 17, 171, 0.5);
    background: rgba(203, 17, 171, 0.18);
  }
}
