:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #e11d48;
  --red-soft: #fff1f2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  overflow-x: hidden;
}

body {
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
}

.hidden { display: none !important; }

/* Login Screen */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #1e3a8a 100%);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  margin-bottom: 20px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
}

.field-label input {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.field-label input:focus {
  border-color: var(--primary);
  background: #fff;
}

.login-error {
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 10px;
}

.btn-login {
  margin-top: 4px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
}

.btn-login:disabled { opacity: 0.6; cursor: wait; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.18);
  flex-shrink: 0;
  animation: pulse 2.4s infinite;
}

.live-dot.syncing {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.22);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.16); opacity: 0.72; }
}

.brand-title { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.pill-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.pill-btn.kzt { background: var(--amber-soft); border-color: #fcd34d; color: #92400e; }
.pill-btn.fresh { background: var(--green-soft); border-color: #6ee7b7; color: var(--green); }

.icon-btn {
  width: 35px;
  height: 35px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Subtle top loading line (replaces flickering loading box!) */
.top-progress {
  height: 2.5px;
  background: linear-gradient(90deg, transparent 0%, var(--primary) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.sync-banner {
  background: var(--primary-soft);
  color: #1e40af;
  font-size: 12px;
  padding: 5px 12px;
  text-align: center;
  border-top: 1px solid #dbeafe;
}

/* Controls */
.controls-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.controls-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.preset-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.hot.active { background: var(--green); border-color: var(--green); }

.custom-dates { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.custom-dates input[type="date"] {
  flex: 1 1 125px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.date-sep { color: var(--muted); }

.filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.select-input, .search-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}

.select-input { flex: 1 1 160px; }
.search-input { width: 100%; }
.period-badge { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }

/* Main */
.main-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.loading-box, .empty-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

@media (min-width: 720px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.kpi-card.hero {
  grid-column: span 2;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 65%, #172554 100%);
  color: #fff;
  border-color: #0f172a;
}

.kpi-card.hero .kpi-label { color: #94a3b8; }
.kpi-card.hero .kpi-sub { color: #cbd5e1; }

.kpi-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 20px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; word-break: break-word; }
.kpi-card.hero .kpi-value { font-size: 28px; }
.kpi-sub { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.delta-up { color: #34d399; font-weight: 700; }
.delta-down { color: #fb7185; font-weight: 700; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); }
.link-btn { border: none; background: transparent; color: var(--primary); font-weight: 700; font-size: 12.5px; cursor: pointer; padding: 2px 4px; }

/* Split bar */
.split-bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; display: flex; margin-top: 8px; }
.split-cash { background: var(--green); height: 100%; }
.split-card { background: var(--primary); height: 100%; }

/* Interactive Bar Chart */
.chart-tooltip {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
  color: #334155;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-scroll { overflow-x: auto; padding-bottom: 4px; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 150px;
  min-width: 100%;
  padding-top: 22px;
}

.bar-col {
  flex: 1 0 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  cursor: pointer;
}

.bar-val { font-size: 9.5px; color: var(--muted); margin-bottom: 3px; white-space: nowrap; }

.bar-fill {
  width: 100%;
  max-width: 30px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #60a5fa 0%, #2563eb 100%);
  min-height: 3px;
}

.bar-col.selected .bar-fill { background: linear-gradient(180deg, #34d399 0%, #059669 100%); }
.bar-fill.zero { background: #e2e8f0; min-height: 2px; }
.bar-lbl { font-size: 10px; color: var(--muted); margin-top: 5px; white-space: nowrap; }
.bar-col.selected .bar-lbl { color: var(--text); font-weight: 700; }

/* List Rows */
.list-stack { display: flex; flex-direction: column; gap: 8px; }

.row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.row-card:active { background: #f8fafc; }
.row-card.no-click { cursor: default; }

.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.row-name { font-weight: 700; font-size: 14px; color: var(--text); word-break: break-word; }
.row-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-amount { font-weight: 800; font-size: 16px; white-space: nowrap; text-align: right; }

.row-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  font-size: 12px;
  color: #334155;
}

.metric-chip { display: inline-flex; align-items: center; gap: 4px; }
.metric-chip b { color: var(--text); }

.stock-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.stock-pill {
  font-size: 11px;
  background: #f1f5f9;
  color: #334155;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 600;
}

.rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: #f1f5f9;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
  margin-right: 6px;
  flex-shrink: 0;
}

.rank-num.top1 { background: #fef3c7; color: #b45309; }
.rank-num.top2 { background: #e2e8f0; color: #334155; }
.rank-num.top3 { background: #ffedd5; color: #c2410c; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: var(--primary-soft); color: var(--primary); }

/* Progress Bar */
.prog-track { height: 7px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.prog-fill { height: 100%; border-radius: 999px; background: var(--primary); }
.prog-fill.hot { background: var(--green); }
.prog-fill.mid { background: var(--amber); }
.prog-fill.low { background: #94a3b8; }

/* Buttons */
.btn-primary-sm, .btn-add, .btn-outline-sm, .btn-send {
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 12.5px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
}

.btn-primary-sm { background: var(--primary); color: #fff; }
.btn-outline-sm { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-add { background: var(--primary-soft); color: var(--primary); padding: 7px 11px; font-size: 12px; white-space: nowrap; }
.btn-add.added { background: var(--green-soft); color: var(--green); }

.btn-wa { background: #16a34a; color: #fff; }
.btn-tg { background: #0284c7; color: #fff; }
.btn-share { background: #0f172a; color: #fff; }
.btn-copy { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-xlsx { background: #047857; color: #fff; }
.btn-danger { background: var(--red-soft); color: var(--red); }

/* Segmented Control */
.seg-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: #475569;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
}

.seg-btn.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 2px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

.nav-item.active { color: var(--primary); }

/* Floating Cart Button */
.cart-fab {
  position: fixed;
  right: 14px;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  background: #0f172a;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.28);
  cursor: pointer;
}

.cart-badge { background: var(--green); color: #fff; font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; }

/* Modal Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; padding: 20px; }
}

.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 720px) {
  .sheet { border-radius: 18px; max-height: 86vh; }
}

.sheet-header {
  background: #fff;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-title { font-weight: 800; font-size: 16px; }
.sheet-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.sheet-body {
  padding: 12px 14px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Qty Stepper */
.qty-box { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.qty-btn { width: 32px; height: 32px; border: none; background: #f8fafc; font-weight: 800; font-size: 14px; cursor: pointer; }
.qty-input { width: 50px; height: 32px; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); text-align: center; font-weight: 700; font-size: 13px; }

.send-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
@media (min-width: 540px) { .send-grid { grid-template-columns: repeat(4, 1fr); } }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 92vw;
  text-align: center;
}
