:root {
  --bg: #0f1115;
  --panel: #14161c;
  --card: #181b22;
  --border: #262b36;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --green: #3ddc84;
  --red: #ff5c5c;
  --yellow: #ffc24b;
  --accent: #5b8cff;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}
input {
  font-family: inherit;
}

.app {
  display: flex;
  min-height: 100vh;
}
.app[hidden],
#authScreen[hidden] {
  display: none;
}
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(400px, 100%);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.auth-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
}
.auth-card > p {
  color: var(--muted);
  font-size: 13px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}
.auth-form label {
  margin-top: 6px;
  font-size: 13px;
}
.auth-form input,
.admin-panel input {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
}
.auth-form button {
  margin-top: 8px;
  padding: 10px;
  color: white;
  background: var(--accent);
  border-radius: 8px;
}
.auth-error,
.account-message.error {
  color: var(--red) !important;
}
.auth-help {
  margin-bottom: 0;
}
.account-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.admin-panel {
  margin-top: 12px;
  font-size: 13px;
}
.admin-panel summary {
  cursor: pointer;
  color: var(--accent);
}
.admin-panel .new-list-form {
  margin-top: 8px;
}
.account-message {
  margin: 0;
  color: var(--green);
  font-size: 11px;
}

/* ---- sidebar ---- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-header h1 {
  font-size: 16px;
  margin: 0 0 16px;
}
.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.drawer-toggle,
.drawer-close,
.drawer-backdrop {
  display: none;
}
.list-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  width: 100%;
  text-align: left;
}
.list-nav-item:hover {
  background: #1c2027;
  color: var(--text);
}
.list-nav-item.active {
  background: rgba(91, 140, 255, 0.15);
  color: var(--accent);
  font-weight: 600;
}
.list-nav-item .count {
  font-size: 11px;
  opacity: 0.7;
}

.new-list-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.new-list-form input {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.new-list-form button {
  background: var(--accent);
  color: white;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
}

.sidebar-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.conn {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.next-check {
  font-size: 11px;
  color: var(--muted);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.dot.live {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
}
.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.ghost-btn.danger:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ---- main content ---- */
.content {
  flex: 1;
  padding: 24px 28px;
  max-width: 1200px;
}
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.content-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.content-header h2 {
  margin: 0;
  font-size: 20px;
}

.add-product-form {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.add-product-form input,
.add-product-form select {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
.add-product-form select {
  flex: 0 1 220px;
}
.add-product-form button {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  white-space: nowrap;
}
.form-error {
  color: var(--red);
  font-size: 12px;
  min-height: 18px;
  margin: 6px 0 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition:
    border-color 0.3s,
    background 0.3s;
  cursor: pointer;
  position: relative;
}
.card.flash {
  border-color: var(--accent);
  background: #1c2130;
}
.card-image {
  height: 140px;
  background: #0d0f13;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-image img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}
.card-image .placeholder {
  color: var(--muted);
  font-size: 28px;
}
.card-body {
  padding: 12px 14px;
}
.card-site {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.card-site img {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}
.card-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.price {
  font-size: 19px;
  font-weight: 700;
  color: var(--green);
}
.price.na {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge.in {
  background: rgba(61, 220, 132, 0.15);
  color: var(--green);
}
.badge.low {
  background: rgba(255, 194, 75, 0.15);
  color: var(--yellow);
}
.badge.out {
  background: rgba(255, 92, 92, 0.15);
  color: var(--red);
}
.ts {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
}
.err {
  font-size: 11px;
  color: var(--red);
  margin-top: 6px;
}
.remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .remove-btn {
  opacity: 1;
}
.remove-btn:hover {
  background: var(--red);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  margin-top: 30px;
  text-align: center;
}

/* ---- modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: min(640px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 12px;
}
.modal-header h3 {
  margin: 0 0 4px;
  font-size: 16px;
}
.modal-header a {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.product-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 11px;
}
.product-links:empty {
  display: none;
}
.product-links strong {
  color: var(--muted);
  font-weight: 500;
}
.product-links a {
  color: var(--accent);
  text-decoration: none;
}
.price-analysis {
  margin: 4px 0 16px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.analysis-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.analysis-heading h4 {
  margin: 0;
  font-size: 13px;
}
.recommendation {
  font-size: 12px;
  font-weight: 700;
}
.recommendation.buy {
  color: var(--green);
}
.recommendation.not_buy,
.recommendation.unavailable {
  color: var(--yellow);
}
.analysis-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.analysis-details > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}
.analysis-details strong {
  color: var(--text);
  font-size: 13px;
}
@media (max-width: 420px) {
  .analysis-details {
    grid-template-columns: 1fr;
  }
}

/* ---- toasts ---- */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
}
.toast {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  max-width: 320px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  animation: in 0.25s ease-out;
}
.toast.low_stock,
.toast.out_of_stock {
  border-color: var(--red);
}
.toast.back_in_stock {
  border-color: var(--green);
}
@keyframes in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .app {
    display: block;
    min-height: 100dvh;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 61;
    width: min(300px, 85vw);
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 30px rgba(0, 0, 0, 0.35);
  }
  .app.drawer-open .sidebar {
    transform: translateX(0);
  }
  body.drawer-visible {
    overflow: hidden;
  }
  .drawer-toggle,
  .drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .drawer-close {
    padding: 5px 8px;
  }
  .drawer-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.55);
  }
  .content {
    padding: 18px;
  }
  .add-product-form {
    flex-wrap: wrap;
  }
  .add-product-form select {
    flex: 1 1 100%;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
