:root {
  --bg-1: #eef8ff;
  --bg-2: #dcefff;
  --bg-3: #cbe6fb;
  --ink: #0b2942;
  --ink-dim: #4f7089;
  --ink-dimmer: #85a3b9;
  --surface: rgba(255, 255, 255, 0.62);
  --surface-soft: rgba(255, 255, 255, 0.42);
  --border: rgba(14, 116, 213, 0.16);
  --sky: #38bdf8;
  --blue: #2563eb;
  --teal: #06b6d4;
  --indigo: #6366f1;
  --green: #16a34a;
  --red: #e11d48;
  --amber: #f59e0b;
  --grad: linear-gradient(135deg, #2563eb, #06b6d4);
  --grad-warm: linear-gradient(135deg, #f59e0b, #fb923c);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-soft: 0 8px 30px rgba(37, 99, 235, 0.12);
  --shadow-lift: 0 20px 45px rgba(37, 99, 235, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  color: var(--ink);
  font-family: 'Prompt', system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ===== Floating watercolor blobs ===== */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.55;
  mix-blend-mode: multiply;
  animation: float 20s ease-in-out infinite;
}
.blob-a {
  width: 500px; height: 500px;
  background: #7dd3fc;
  top: -140px; left: -110px;
  animation-duration: 23s;
}
.blob-b {
  width: 440px; height: 440px;
  background: #38bdf8;
  bottom: -150px; right: -90px;
  animation-duration: 27s;
  animation-delay: -6s;
}
.blob-c {
  width: 380px; height: 380px;
  background: #2dd4bf;
  top: 42%; left: 58%;
  animation-duration: 21s;
  animation-delay: -12s;
}
.blob-d {
  width: 300px; height: 300px;
  background: #60a5fa;
  top: 8%; right: 12%;
  animation-duration: 25s;
  animation-delay: -3s;
}
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.08); }
  66% { transform: translate(-30px, 25px) scale(0.94); }
}

/* ===== Glass surface ===== */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

/* ===== Buttons ===== */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease, filter 0.2s ease;
  color: var(--ink);
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.32);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-2px); box-shadow: 0 12px 30px rgba(37, 99, 235, 0.4); }

.btn-warm {
  background: var(--grad-warm);
  color: #fff;
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.32);
}
.btn-warm:hover { filter: brightness(1.06); transform: translateY(-2px); }

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 8px 24px rgba(225, 29, 72, 0.3);
}
.btn-danger:hover { filter: brightness(1.08); transform: translateY(-2px); }

.btn-ghost {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid var(--border);
  color: var(--ink);
}
.btn-ghost:hover { background: rgba(37, 99, 235, 0.14); transform: translateY(-2px); }

.btn-block { width: 100%; }
.plus { font-size: 18px; font-weight: 800; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(37, 99, 235, 0.1);
  color: var(--ink);
  font-size: 15px;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:hover { background: rgba(37, 99, 235, 0.2); transform: scale(1.08); }
.icon-btn.ghost { background: transparent; }
.icon-btn.ghost:hover { background: rgba(37, 99, 235, 0.12); }
.icon-btn.danger:hover { background: rgba(225, 29, 72, 0.18); }
.icon-btn.on-dark { background: rgba(255,255,255,0.25); color: #fff; }
.icon-btn.on-dark:hover { background: rgba(255,255,255,0.4); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ===== Login ===== */
.login-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  text-align: center;
  animation: pop-in 0.5s cubic-bezier(.34,1.56,.64,1);
}
.login-icon {
  font-size: 44px;
  margin-bottom: 8px;
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.login-title {
  font-size: 26px;
  font-weight: 800;
  margin: 0 0 6px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-sub {
  color: var(--ink-dim);
  font-size: 13.5px;
  margin: 0 0 28px;
  line-height: 1.6;
}
.eye-btn {
  position: absolute;
  right: 6px;
  top: 8px;
  background: transparent;
}
.error-text {
  color: var(--red);
  font-size: 13px;
  margin: -8px 0 16px;
  text-align: left;
}

/* ===== Floating label fields ===== */
.field {
  position: relative;
  margin-bottom: 20px;
  text-align: left;
}
.field input, .field textarea {
  width: 100%;
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 14px 8px;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  resize: vertical;
}
.field textarea { padding-top: 20px; min-height: 56px; }
.field input:focus, .field textarea:focus {
  border-color: var(--blue);
  background: rgba(37, 99, 235, 0.06);
}
.field label {
  position: absolute;
  left: 14px;
  top: 15px;
  color: var(--ink-dimmer);
  font-size: 15px;
  pointer-events: none;
  transition: all 0.18s ease;
  background: transparent;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label,
.field textarea:focus + label,
.field textarea:not(:placeholder-shown) + label {
  top: 4px;
  font-size: 11px;
  color: var(--teal);
}
.field.span-2 { grid-column: span 2; }

/* ===== App shell ===== */
.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  animation: fade-in 0.5s ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-emoji {
  font-size: 34px;
  filter: drop-shadow(0 4px 12px rgba(37,99,235,0.35));
  animation: bob 4s ease-in-out infinite;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; color: var(--ink); }
.brand p { margin: 2px 0 0; color: var(--ink-dim); font-size: 13px; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  animation: fade-in-up 0.5s ease both;
  animation-delay: calc(var(--i) * 0.08s);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon-cost { background: linear-gradient(135deg, rgba(37,99,235,0.28), rgba(37,99,235,0.08)); }
.stat-icon-revenue { background: linear-gradient(135deg, rgba(6,182,212,0.3), rgba(6,182,212,0.08)); }
.stat-icon-profit { background: linear-gradient(135deg, rgba(22,163,74,0.28), rgba(22,163,74,0.08)); }
.stat-icon-count { background: linear-gradient(135deg, rgba(99,102,241,0.28), rgba(99,102,241,0.08)); }
.stat-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { font-size: 12.5px; color: var(--ink-dim); white-space: nowrap; }
.stat-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ===== Wallet panel ===== */
.wallet-panel {
  padding: 22px 24px;
  margin-bottom: 26px;
  animation: fade-in-up 0.5s ease both;
  animation-delay: 0.2s;
}
.wallet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.wallet-head h2 { margin: 0; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.wallet-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-dim); }

.wallet-balances { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.wallet-tile {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}
.wallet-tile-icon { font-size: 24px; }
.wallet-tile-label { font-size: 12px; color: var(--ink-dim); display: block; }
.wallet-tile-value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--green); }
.wallet-tile-value.negative { color: var(--red); }
.wallet-tile-value.neutral { color: var(--ink); }

.wallet-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.wallet-history {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.wallet-history h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-dim); font-weight: 600; }
.wallet-tx-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.wallet-tx-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 13px;
  animation: fade-in-up 0.3s ease both;
}
.tx-type-badge { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.tx-type-badge.withdraw { background: rgba(245, 158, 11, 0.22); color: #7c4a03; }
.tx-type-badge.reinvest { background: rgba(6, 182, 212, 0.22); color: #075566; }
.wallet-tx-info { flex: 1; min-width: 0; }
.wallet-tx-note { color: var(--ink-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wallet-tx-meta { font-size: 11px; color: var(--ink-dimmer); white-space: nowrap; }
.wallet-empty { font-size: 13px; color: var(--ink-dimmer); text-align: center; padding: 14px 0; }

.wallet-hint {
  background: rgba(37, 99, 235, 0.07);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-bottom: 18px;
  line-height: 1.6;
}
.wallet-hint strong { color: var(--ink); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.search-box {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.search-box input {
  border: none; background: transparent; outline: none;
  color: var(--ink); font-family: inherit; font-size: 14px; width: 100%;
}
.search-icon { opacity: 0.7; }

.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  color: var(--ink-dim);
  padding: 9px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chip:hover { color: var(--ink); border-color: rgba(37,99,235,0.35); }
.chip.active {
  background: var(--grad);
  color: white;
  border-color: transparent;
}

/* ===== Product grid ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.product-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(.22,1,.36,1), box-shadow 0.3s ease;
  animation: fade-in-up 0.45s ease both;
}
.product-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lift);
}

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, rgba(37,99,235,0.18), rgba(6,182,212,0.12));
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-media img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.4s ease;
}
.product-card:hover .card-media img { transform: scale(1.06); }
.card-media .placeholder-emoji { font-size: 46px; filter: drop-shadow(0 6px 14px rgba(37,99,235,0.25)); }

.status-badge {
  position: absolute;
  top: 12px; right: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}
.status-badge.in_stock { background: rgba(245, 158, 11, 0.9); color: #402c00; }
.status-badge.sold { background: rgba(22, 163, 74, 0.9); color: #ffffff; }

.card-actions {
  position: absolute;
  top: 12px; left: 12px;
  display: flex; gap: 6px;
  opacity: 0;
  transform: translateY(-6px);
  transition: all 0.2s ease;
}
.product-card:hover .card-actions, .product-card:focus-within .card-actions { opacity: 1; transform: translateY(0); }
.card-actions .icon-btn { background: rgba(11, 41, 66, 0.5); color: #fff; backdrop-filter: blur(6px); }
.card-actions .icon-btn:hover { background: rgba(11, 41, 66, 0.7); }

.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-title { font-size: 16px; font-weight: 700; margin: 0; line-height: 1.35; color: var(--ink); }
.card-desc {
  color: var(--ink-dim); font-size: 12.5px; margin: -4px 0 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.price-rows { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.price-row { display: flex; justify-content: space-between; color: var(--ink-dim); }
.price-row span:last-child { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }

.profit-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.profit-line span:first-child { font-size: 12.5px; color: var(--ink-dim); }
.profit-value { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.profit-value.positive { color: var(--green); }
.profit-value.negative { color: var(--red); }

/* ===== Empty state & skeleton ===== */
.empty-state {
  text-align: center;
  padding: 70px 20px;
  animation: fade-in 0.5s ease;
}
.empty-emoji { font-size: 56px; margin-bottom: 12px; animation: bob 3.5s ease-in-out infinite; }
.empty-state h3 { margin: 0 0 6px; font-size: 18px; color: var(--ink); }
.empty-state p { color: var(--ink-dim); margin: 0 0 20px; font-size: 14px; }

.skel-card {
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}
.skel-card::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(37,99,235,0.12), transparent);
  animation: shimmer 1.6s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 41, 66, 0.28);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade-in 0.2s ease;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 28px 28px;
  animation: pop-in 0.3s cubic-bezier(.34,1.56,.64,1);
  background: rgba(255,255,255,0.85);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 700; color: var(--ink); }

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 160px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
  background: rgba(37,99,235,0.04);
}
.dropzone:hover, .dropzone.drag-over { border-color: var(--teal); background: rgba(6,182,212,0.08); }
.dropzone-hint { text-align: center; color: var(--ink-dim); font-size: 13.5px; padding: 20px; }
.dropzone-emoji { font-size: 30px; display: block; margin-bottom: 6px; }
.link-text { color: var(--blue); font-weight: 600; }
.image-preview { width: 100%; height: 220px; object-fit: cover; display: block; }
.remove-image-btn {
  position: absolute; top: 10px; right: 10px;
  background: rgba(11,41,66,0.55);
  color: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
}

.status-field { margin-top: 4px; }
.status-label { display: block; font-size: 12.5px; color: var(--ink-dim); margin-bottom: 8px; }
.status-toggle { display: flex; gap: 10px; }
.status-opt {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.status-opt.active {
  background: var(--grad);
  color: white;
  border-color: transparent;
}

.profit-preview {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(37,99,235,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0 22px;
  font-size: 13.5px;
  color: var(--ink-dim);
}
.profit-preview strong { font-size: 18px; color: var(--green); font-variant-numeric: tabular-nums; }
.profit-preview strong.negative { color: var(--red); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.confirm-modal { max-width: 360px; text-align: center; padding: 32px 28px; }
.confirm-emoji { font-size: 42px; margin-bottom: 10px; }
.confirm-modal h3 { margin: 0 0 6px; color: var(--ink); }
.confirm-modal p { color: var(--ink-dim); font-size: 13.5px; margin: 0 0 22px; }
.confirm-modal .modal-actions { justify-content: center; }

/* ===== Toasts ===== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 100;
}
.toast {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  font-size: 13.5px;
  color: var(--ink);
  display: flex; align-items: center; gap: 10px;
  min-width: 240px;
  animation: slide-in 0.3s cubic-bezier(.34,1.56,.64,1);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.leaving { animation: slide-out 0.25s ease forwards; }

/* ===== Keyframes ===== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slide-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ===== Responsive ===== */
@media (max-width: 780px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}
