:root {
  --bg: #0f1419;
  --bg2: #1a2332;
  --bg3: #243044;
  --card: #1e2a3a;
  --border: #2d3f56;
  --text: #e8eef6;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --samsung: #60a5fa;
  --xiaomi: #f97316;
  --apple: #a78bfa;
  --tecno: #34d399;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

/* ----- Login ----- */
.screen {
  display: none;
  min-height: 100dvh;
}
.screen.active {
  display: block;
}

#login-screen {
  display: none;
  min-height: 100dvh;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  align-items: center;
  justify-content: center;
}
#login-screen.active {
  display: flex;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
#login-meta {
  display: block;
  text-align: center;
  width: 100%;
}

.logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
  margin: 0 auto 16px;
}
.logo.logo-img {
  width: auto;
  height: auto;
  min-width: 96px;
  min-height: 96px;
  background: transparent;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
}
.logo.logo-img img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  display: block;
  border-radius: 16px;
}

.login-card h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 22px;
  text-align: center;
}

.login-card .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 22px;
  text-align: center;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

select,
input[type="search"] {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  outline: none;
}
select:focus,
input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.85rem;
}
.meta-line {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.55;
}

/* ----- App shell ----- */
#app-screen.active {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(64px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar .who {
  flex: 1;
  min-width: 0;
}
.topbar .who strong {
  display: block;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .who span {
  font-size: 0.75rem;
  color: var(--muted);
}

.content {
  padding: 14px 14px 20px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fade 0.2s ease;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(26, 35, 50, 0.96);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  backdrop-filter: blur(12px);
}
.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 2px;
  font-size: 0.62rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.nav-btn .ico {
  font-size: 1.15rem;
  line-height: 1;
}
.nav-btn.active {
  color: var(--accent);
}

/* Cards & KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi .label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.kpi .value {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 4px;
  word-break: break-word;
}
.kpi .hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card h3 .muted {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.75rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.brand-row:last-child {
  border-bottom: none;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.brand-row .name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}
.brand-row .nums {
  text-align: right;
  font-size: 0.82rem;
}
.brand-row .nums .muted {
  color: var(--muted);
  font-size: 0.72rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--bg3);
  color: var(--muted);
}
.chip.ok {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}
.chip.warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}
.chip.bad {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}
.chip.b-samsung {
  background: rgba(96, 165, 250, 0.15);
  color: var(--samsung);
}
.chip.b-xiaomi {
  background: rgba(249, 115, 22, 0.15);
  color: var(--xiaomi);
}
.chip.b-apple {
  background: rgba(167, 139, 250, 0.15);
  color: var(--apple);
}
.chip.b-tecno {
  background: rgba(52, 211, 153, 0.15);
  color: var(--tecno);
}

/* Search & list */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar input,
.toolbar select {
  margin: 0;
  flex: 1;
  min-width: 120px;
}

.list-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.list-item .row1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}
.list-item .title {
  font-weight: 650;
  font-size: 0.92rem;
}
.list-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}
.list-item .money {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}
.list-item .detail,
.list-item .detail.always-open {
  display: block;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.sku-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.82rem;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.sku-line:last-child {
  border-bottom: none;
}
.sku-line .sku-name {
  flex: 1;
  min-width: 0;
  line-height: 1.35;
}
.sku-line .sku-stat {
  flex-shrink: 0;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Targets */
.target-block {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.target-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.bucket {
  display: grid;
  grid-template-columns: 1.1fr 0.7fr 0.7fr 0.7fr;
  gap: 4px;
  font-size: 0.75rem;
  padding: 4px 0;
  align-items: center;
}
.bucket.head {
  color: var(--muted);
  font-weight: 600;
}
.bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  border-radius: 99px;
}

/* Activity */
.act-item {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.act-item:last-child {
  border-bottom: none;
}
.act-date {
  color: var(--muted);
  font-size: 0.72rem;
}
.act-main strong {
  display: block;
  font-size: 0.85rem;
}
.act-main span {
  color: var(--muted);
  font-size: 0.75rem;
}
.act-day {
  margin-bottom: 14px;
}
.act-day-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  margin: 10px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.act-dealer-card {
  margin-bottom: 8px;
}
.act-right-stats {
  text-align: right;
  line-height: 1.35;
}
.act-stat-line {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 2px;
}
.hist-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 2px 0 6px;
}
.sku-line.hist-focus {
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  padding-left: 6px;
  padding-right: 6px;
  margin: 0 -4px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
  font-size: 0.9rem;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* Desktop */
@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .content {
    padding: 20px 24px 40px;
  }
  #app-screen.active {
    padding-bottom: 20px;
  }
  .bottom-nav {
    position: sticky;
    top: 57px;
    bottom: auto;
    max-width: 960px;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-top: 12px;
    width: calc(100% - 48px);
  }
  #app-screen.active {
    padding-bottom: 24px;
  }
  .bottom-nav {
    order: 0;
  }
}
