:root {
  --bg: #0A0E13;
  --card: #131922;
  --card-2: rgba(255,255,255,0.03);
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --text: #E8EEF5;
  --text-muted: #8B9BAE;
  --text-faint: #5B6B82;
  --teal: #0D9488;
  --teal-bright: #14B8A6;
  --teal-glow: rgba(13,148,136,0.18);
  --green: #22C55E;
  --red: #F87171;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 720px; margin: 0 auto;
  padding: 24px clamp(12px, 4vw, 24px);
}

header { margin-bottom: 28px; text-align: center; }
header h1 {
  margin: 0; font-size: 28px; font-weight: 700;
  letter-spacing: -0.02em;
}
header .sub { color: var(--text-muted); margin-top: 6px; font-size: 14px; }

.header-nav {
  display: flex; justify-content: center; gap: 4px;
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  width: fit-content; margin-left: auto; margin-right: auto;
}
.nav-link {
  padding: 8px 18px; border: none; background: transparent;
  color: var(--text-muted); font-family: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer;
  border-radius: 999px;
  transition: background 150ms, color 150ms;
}
.nav-link:hover { color: var(--text); }
.nav-link.active {
  background: var(--teal); color: white;
}

/* ===== History list ===== */
.history-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px;
}
.history-title { margin: 0; font-size: 18px; font-weight: 700; }
.history-count {
  background: var(--card-2); border: 1px solid var(--border);
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; color: var(--text-muted);
}

.history-list {
  display: flex; flex-direction: column; gap: 8px;
}

.history-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 150ms;
}
.history-item:hover { border-color: var(--border-strong); }

.history-thumb {
  flex-shrink: 0;
  width: 64px; height: 64px;
  border-radius: 8px;
  background: var(--bg);
  object-fit: cover;
  border: 1px solid var(--border);
}
.history-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: var(--text-faint);
}

.history-meta {
  flex: 1; min-width: 0;
}
.history-meta .name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-meta .sub {
  font-size: 12px; color: var(--text-muted);
  margin-top: 2px;
}
.history-meta .price {
  color: var(--teal-bright); font-weight: 600;
}

.history-actions {
  display: flex; gap: 6px;
}
.history-actions button {
  padding: 6px 12px; min-height: 32px;
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-muted);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms;
}
.history-actions .view-btn:hover {
  background: rgba(13,148,136,0.1); color: var(--teal-bright); border-color: var(--teal);
}
.history-actions .delete-btn:hover {
  background: rgba(248,113,113,0.1); color: var(--red); border-color: var(--red);
}

.history-empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  margin-bottom: 18px;
}

.hidden { display: none !important; }

/* ===== Dropzone ===== */
.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 180px; padding: 24px;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--card-2);
  cursor: pointer; text-align: center;
  transition: border-color 150ms, background 150ms;
}
.dropzone input[type="file"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
  /* Native input handles clicks reliably across all browsers + mobile */
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--teal-bright);
  background: rgba(13,148,136,0.06);
}
.dz-icon { font-size: 36px; margin-bottom: 8px; }
.dz-title { font-weight: 600; }
.dz-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ===== Preview grid ===== */
.preview-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px; margin-top: 14px;
}
.preview-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
}

/* ===== Form ===== */
.form-group { margin-top: 18px; }
.field-label {
  display: block; font-size: 13px; color: var(--text-muted);
  margin-bottom: 6px; font-weight: 500;
}
textarea, input[type="text"], input[type="number"] {
  width: 100%; padding: 10px 12px;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 15px;
}
textarea { min-height: 70px; resize: vertical; }
textarea.tall { min-height: 220px; }
textarea:focus, input:focus {
  outline: none; border-color: var(--teal-bright);
}
input[readonly], textarea[readonly] {
  background: rgba(13,148,136,0.04);
  cursor: text;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 22px; border-radius: 10px;
  font-family: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  transition: background 150ms, transform 100ms;
  min-height: 44px;
}
.btn.primary {
  background: var(--teal); color: white;
  box-shadow: 0 4px 14px var(--teal-glow);
  margin-top: 18px;
}
.btn.primary:hover:not(:disabled) { background: var(--teal-bright); transform: translateY(-1px); }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn.ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--border);
}
.btn.ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn.full { width: 100%; margin-top: 18px; }

.btn-copy {
  padding: 4px 12px; min-height: 28px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--card-2); color: var(--text);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background 150ms;
}
.btn-copy:hover { background: rgba(13,148,136,0.1); border-color: var(--teal); }
.btn-copy.copied { background: var(--green); color: white; border-color: var(--green); }

/* ===== Loader ===== */
.loader-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--teal-bright);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { margin-top: 16px; color: var(--text-muted); font-size: 14px; }

/* ===== Summary block ===== */
.summary-block {
  margin-bottom: 20px; padding: 16px;
  background: rgba(13,148,136,0.06);
  border: 1px solid rgba(13,148,136,0.25);
  border-radius: 8px;
}
.summary-block .item-name {
  font-size: 18px; font-weight: 700; margin-bottom: 6px;
}
.summary-block .item-meta {
  color: var(--text-muted); font-size: 13px;
}
.summary-block .price-line {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.summary-block .price-line strong { color: var(--teal-bright); }
.summary-block .warn { color: #FBBF24; margin-top: 6px; font-size: 13px; }

/* ===== Value-add suggestions ===== */
.value-adds-block {
  margin-bottom: 20px;
  background: rgba(34,197,94,0.04);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 8px;
  padding: 16px;
}
.value-adds-header { margin-bottom: 12px; }
.value-adds-header h3 {
  margin: 0; font-size: 16px; font-weight: 700;
  color: var(--text);
}
.value-adds-sub {
  display: block; font-size: 12px;
  color: var(--text-muted); margin-top: 4px;
}

.value-adds-list {
  display: flex; flex-direction: column; gap: 8px;
}

.value-add-item {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.value-add-item.top-roi {
  border-color: rgba(34,197,94,0.4);
  background: rgba(34,197,94,0.06);
}

.va-line-1 {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.va-action {
  font-weight: 600; font-size: 14px; flex: 1;
}
.va-roi {
  font-size: 14px; font-weight: 700;
  color: var(--green); white-space: nowrap;
}
.va-roi.medium { color: #FBBF24; }
.va-roi.low { color: var(--text-muted); }

.va-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 6px; font-size: 12px; color: var(--text-muted);
}
.va-meta .difficulty-easy { color: var(--green); }
.va-meta .difficulty-medium { color: #FBBF24; }
.va-meta .difficulty-hard { color: var(--red); }

.va-tools {
  font-size: 12px; color: var(--text-muted);
  margin-top: 6px;
}
.va-tools strong { color: var(--text); font-weight: 600; }

.va-note {
  font-size: 12.5px; color: var(--text);
  margin-top: 6px; font-style: italic; opacity: 0.85;
}

.value-adds-total {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text);
}
.value-adds-total strong { color: var(--green); }

/* ===== Tabs ===== */
.tabs {
  display: flex; gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1; padding: 10px 8px;
  background: transparent; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color 150ms, border-color 150ms;
}
.tab-btn.active { color: var(--teal-bright); border-bottom-color: var(--teal-bright); }
.tab-btn:hover { color: var(--text); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadein 180ms; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.field-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; margin-bottom: 6px;
}
.field-row .field-label { margin: 0; }

.meta-line {
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px; color: var(--text-muted);
}

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--red); color: white;
  padding: 12px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  z-index: 1000;
  animation: slideup 200ms;
}
@keyframes slideup {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%); }
}

/* ===== Login page ===== */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo { font-size: 36px; margin-bottom: 8px; }
.login-brand h1 { margin: 0; font-size: 22px; font-weight: 700; }
.login-brand .sub { color: var(--text-muted); margin-top: 4px; font-size: 14px; }

.login-error {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.35);
  color: var(--red);
  padding: 10px 14px; border-radius: 8px;
  font-size: 13.5px; margin-bottom: 18px; text-align: center;
}

.login-form .form-group { margin-bottom: 16px; }
.login-form .btn.primary.full { margin-top: 6px; }

@media (max-width: 480px) {
  .page { padding: 16px 12px; }
  header h1 { font-size: 24px; }
  .card { padding: 16px; }
  .btn.primary { padding: 14px 20px; font-size: 16px; }
}
