@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9eaec;
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --text: #0f0f0f;
  --text-secondary: #374151;
  --text-muted: #9ca3af;
  --red: #cc0000;
  --red-hover: #a80000;
  --red-dim: rgba(204, 0, 0, 0.07);
  --red-border: rgba(204, 0, 0, 0.2);
  --green: #16a34a;
  --green-dim: rgba(22, 163, 74, 0.08);
  --green-border: rgba(22, 163, 74, 0.22);
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LOGIN PAGE ─────────────────────────────────────────── */

.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* Subtle top accent line on login */
.login-wrapper::before {
  content: '';
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  height: 3px;
  background: var(--red);
  border-radius: 0 0 4px 4px;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 48px 44px;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}

.login-logo-img {
  width: 136px;
  height: auto;
  display: block;
  margin: 0 auto 20px;
}

.login-logo h1 {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.form-group input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--red);
  background: rgba(204, 0, 0, 0.03);
}

.form-group input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.2s, transform 0.12s;
  margin-top: 4px;
}

.btn-primary:hover { background: var(--red-hover); }
.btn-primary:active { transform: scale(0.98); }

.error-msg {
  color: #dc2626;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

/* ── HEADER ─────────────────────────────────────────────── */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 32px;
  width: auto;
}

.brand {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-family: 'Times New Roman', Times, serif;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.btn-logout:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}

/* ── HEADER NAV TABS ────────────────────────────────────── */

.header-nav {
  display: flex;
  gap: 4px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.nav-tab {
  padding: 5px 16px;
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.nav-tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-tab.active {
  color: var(--red);
  background: var(--red-dim);
  border-color: var(--red-border);
}

/* ── OFFERS PAGE ────────────────────────────────────────── */

.offers-container {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 32px auto;
  padding: 0 24px;
}

.offers-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 18px;
  padding-left: 2px;
}

.model-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.model-group-header {
  padding: 12px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.offer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.offer-row:last-child { border-bottom: none; }
.offer-row:hover { background: var(--surface-2); }

.offer-spec {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.offer-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  margin-left: 24px;
}

@media (max-width: 640px) {
  .header-nav { gap: 2px; }
  .nav-tab { padding: 5px 10px; font-size: 11px; }
  .offers-container { padding: 0 12px; margin: 18px auto; }
  .offer-row { padding: 10px 14px; }
  .model-group-header { padding: 10px 14px; }
  .offer-spec { font-size: 13px; }
  .offer-price { font-size: 14px; margin-left: 12px; }
}

/* ── WATERMARK ──────────────────────────────────────────── */

.search-watermark {
  position: fixed;
  top: 56px;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.search-watermark img {
  width: 90%;
  max-width: 1000px;
  opacity: 0.12;
  user-select: none;
}

/* ── SEARCH CONTAINER ───────────────────────────────────── */

.search-container {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 32px auto;
  padding: 0 24px;
}

.search-box-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 18px;
}

.search-box-wrapper h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}

.search-row {
  display: flex;
  gap: 10px;
}

.search-row input {
  flex: 1;
  padding: 11px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
  outline: none;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.search-row input:focus {
  border-color: var(--red);
  background: rgba(204, 0, 0, 0.025);
}

.search-row input::placeholder {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  font-weight: 400;
}

.btn-search {
  padding: 11px 30px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, transform 0.12s;
}

.btn-search:hover { background: var(--red-hover); }
.btn-search:active { transform: scale(0.98); }
.btn-search:disabled {
  background: rgba(204, 0, 0, 0.3);
  cursor: not-allowed;
  transform: none;
}

/* ── STATE BOXES ────────────────────────────────────────── */

.state-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 56px 28px;
  text-align: center;
}

.state-box .state-icon {
  font-size: 34px;
  display: block;
  margin-bottom: 14px;
}

.state-box h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.state-box p {
  font-size: 14px;
  color: var(--text-muted);
}

.state-error h3 { color: #f87171; }

/* ── RESULTS HEADER ─────────────────────────────────────── */

.results-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-left: 2px;
}

.results-header h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.badge {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid var(--red-border);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

/* ── RESULT CARDS ───────────────────────────────────────── */

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

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: border-color 0.15s, background 0.15s;
}

.result-card:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

.result-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.result-code {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}

.sell-target {
  flex-shrink: 0;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 90px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

.meta-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.meta-value.price { color: var(--green); }
.meta-value.cost  { color: var(--text-muted); }

/* ── LOADING SPINNER ────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255, 255, 255, 0.07);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── SELL FORM ──────────────────────────────────────────── */

.btn-sell {
  padding: 5px 14px;
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.12s;
  white-space: nowrap;
}

.btn-sell:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  transform: translateY(-1px);
}

.btn-sell:active { transform: scale(0.97); }

.sell-form {
  display: flex;
  align-items: center;
  gap: 5px;
}

.sell-qty {
  width: 46px;
  padding: 4px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.sell-qty:focus { border-color: var(--red); }
.sell-qty-error { border-color: #dc2626 !important; }

.sell-avail {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-sell-confirm {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid var(--green-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  padding: 0;
  flex-shrink: 0;
}

.btn-sell-confirm:hover {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-sell-confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sell-cancel {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  padding: 0;
  flex-shrink: 0;
}

.btn-sell-cancel:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.sell-error {
  color: #dc2626;
  font-size: 12px;
  font-weight: 600;
}

/* ── SALE SUCCESS TOAST ─────────────────────────────────── */

.sale-toast {
  position: relative;
  z-index: 2;
  background: var(--green-dim);
  border: 1px solid var(--green-border);
  color: var(--green);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  animation: fadeInOut 3.5s ease forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(-6px); }
  10%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── RESPONSIVE ─────────────────────────────────────────── */

@media (max-width: 640px) {
  header { padding: 0 16px; }
  .header-logo { display: none; }
  .brand { font-size: 11px; max-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .search-container { padding: 0 12px; margin: 18px auto; }
  .search-row { flex-direction: column; }
  .search-box-wrapper { padding: 18px 16px; }
  .login-card { padding: 36px 24px; }

  /* Result cards — tighter on mobile */
  .result-card { padding: 14px 14px; }

  .result-card-top { margin-bottom: 12px; }

  .result-code { font-size: 15px; }

  /* Pills in a 2-column grid so everything fits neatly */
  .result-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .meta-pill {
    min-width: 0;
    padding: 7px 10px;
  }

  .meta-label { font-size: 10px; }
  .meta-value { font-size: 13px; }

  /* Sell form compact on mobile */
  .sell-form { gap: 4px; }
  .sell-qty { width: 42px; }
}

/* ── THEME TOGGLE BUTTON ────────────────────────────────── */

.btn-theme {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.btn-theme:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}

/* In light mode show moon; in dark mode show sun */
.btn-theme .icon-sun  { display: none; }
.btn-theme .icon-moon { display: block; }

html.dark .btn-theme .icon-sun  { display: block; }
html.dark .btn-theme .icon-moon { display: none; }

/* Login page floating toggle */
.login-theme-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
}

/* ── DARK THEME OVERRIDES ───────────────────────────────── */

html.dark {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface-2: #1f1f1f;
  --surface-3: #282828;
  --border: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.13);
  --text: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #646464;
  --red-hover: #e00000;
  --red-dim: rgba(204, 0, 0, 0.1);
  --red-border: rgba(204, 0, 0, 0.22);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.08);
  --green-border: rgba(34, 197, 94, 0.22);
}

/* Watermark needs brightness boost on dark bg */
html.dark .search-watermark img {
  filter: brightness(10);
  opacity: 0.12;
}

/* Login accent swaps to glow on dark */
html.dark .login-wrapper::before {
  width: 700px;
  height: 500px;
  top: -180px;
  background: radial-gradient(ellipse, rgba(204, 0, 0, 0.07) 0%, transparent 68%);
  border-radius: 0;
  opacity: 1;
}

/* Sell/state error colors are readable on both, but soften in dark */
html.dark .sell-error,
html.dark .state-error h3,
html.dark .error-msg { color: #f87171; }
