/* ============================================================
   TELESCOPY — components.css
   Reusable primitives: buttons, chips, cards, tables, inputs, modals.
   ============================================================ */

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 10px 16px;
  font: var(--fw-semi) var(--fs-14)/1 var(--font-sans);
  letter-spacing: -0.01em;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer; user-select: none;
  transition: background var(--dur-2) var(--ease-out),
              border-color var(--dur-2) var(--ease-out),
              color var(--dur-2) var(--ease-out),
              transform var(--dur-1) var(--ease-out),
              box-shadow var(--dur-2) var(--ease-out);
  white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:active { transform: translateY(1px); }
.btn .bi, .btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--brand-500); color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, var(--shadow-xs);
}
.btn-primary:hover { background: var(--brand-600); }

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

.btn-ghost {
  background: transparent; color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-sm { padding: 6px 10px; font-size: var(--fs-13); }
.btn-lg { padding: 14px 22px; font-size: var(--fs-16); }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }
.btn-icon.btn-sm { width: 28px; height: 28px; padding: 4px; }

/* ---------- Chip / Badge ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  font: var(--fw-semi) var(--fs-12)/1.4 var(--font-sans);
  letter-spacing: 0.01em;
  border-radius: var(--r-full);
  white-space: nowrap;
}
.chip-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.9;
}

.chip-rising   { background: var(--rising-bg);   color: var(--rising-fg); }
.chip-stable   { background: var(--stable-bg);   color: var(--stable-fg); }
.chip-seasonal { background: var(--seasonal-bg); color: var(--seasonal-fg); }
.chip-fad      { background: var(--fad-bg);      color: var(--fad-fg); }
.chip-decline  { background: var(--decline-bg);  color: var(--decline-fg); }
.chip-neutral  { background: var(--neutral-bg);  color: var(--neutral-fg); }

.chip-viable      { background: var(--viable-bg);    color: var(--viable-fg); }
.chip-marginal    { background: var(--marginal-bg);  color: var(--marginal-fg); }
.chip-notviable   { background: var(--notviable-bg); color: var(--notviable-fg); }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: var(--s-6); }
.card-pad-sm { padding: var(--s-4); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-6);
  border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font: var(--fw-semi) var(--fs-15)/1.3 var(--font-sans); letter-spacing: -0.01em; }
.card-head .muted { color: var(--text-muted); font-size: var(--fs-13); }
.card-body { padding: var(--s-6); }
.card-body-flush { padding: 0; }

/* ---------- Table ---------- */
.t-wrap { overflow: auto; }
.t {
  width: 100%; border-collapse: collapse;
  font-size: var(--fs-14);
}
.t thead th {
  text-align: left; font: var(--fw-semi) var(--fs-11)/1 var(--font-sans);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0;
}
.t tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.t tbody tr:hover td { background: var(--surface-2); }
.t tbody tr:last-child td { border-bottom: 0; }

.t .num { font-variant-numeric: tabular-nums; }
.t .right { text-align: right; }
.t .center { text-align: center; }

/* Product image cell (square placeholder) */
.img-cell {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  background: var(--surface-3); display: grid; place-items: center;
  color: var(--text-subtle); font-size: 18px;
  overflow: hidden; flex-shrink: 0;
}
.img-cell img { width: 100%; height: 100%; object-fit: cover; }

/* Product name cell */
.prod {
  display: flex; align-items: center; gap: var(--s-3);
  min-width: 0;
}
.prod-meta { display: flex; flex-direction: column; min-width: 0; }
.prod-name {
  font-weight: var(--fw-semi); font-size: var(--fs-14);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 320px;
}
.prod-brand { color: var(--text-muted); font-size: var(--fs-12); }

.asin {
  font: var(--fw-medium) var(--fs-12)/1 var(--font-mono);
  color: var(--brand-600); letter-spacing: 0.02em;
}

/* ---------- Input ---------- */
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  font: var(--fw-regular) var(--fs-14)/1.3 var(--font-sans);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: var(--shadow-focus);
}
.input::placeholder { color: var(--text-subtle); }

.input-icon {
  position: relative;
}
.input-icon .bi, .input-icon svg {
  position: absolute; top: 50%; left: 12px; transform: translateY(-50%);
  color: var(--text-subtle); width: 16px; height: 16px;
  pointer-events: none;
}
.input-icon .input { padding-left: 36px; }

/* Segmented control */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0; background: transparent;
  padding: 6px 12px; font: var(--fw-medium) var(--fs-13)/1 var(--font-sans);
  color: var(--text-muted); border-radius: calc(var(--r-md) - 3px);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ---------- Progress bar ---------- */
.progress {
  width: 100%; height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress > span {
  display: block; height: 100%;
  background: var(--brand-500);
  border-radius: inherit;
  transition: width var(--dur-4) var(--ease-out);
}
.progress.thin { height: 4px; }
.progress.thick { height: 10px; }

/* ---------- Gallery ---------- */
.gallery { display: flex; flex-direction: column; gap: var(--s-3); }
.gallery-main {
  aspect-ratio: 1/1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: grid; place-items: center;
  position: relative;
}
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.gallery-thumbs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2);
}
.gallery-thumbs button {
  aspect-ratio: 1/1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0; cursor: pointer; overflow: hidden;
  transition: border-color var(--dur-2) var(--ease-out);
}
.gallery-thumbs button:hover { border-color: var(--text-muted); }
.gallery-thumbs button[aria-pressed="true"] {
  border-color: var(--brand-500);
  box-shadow: var(--shadow-focus);
}
.gallery-thumbs img { width: 100%; height: 100%; object-fit: cover; }

/* Empty gallery — intentional, not a broken image */
.gallery-empty {
  aspect-ratio: 1/1;
  background: repeating-linear-gradient(
    45deg,
    var(--surface-2) 0 12px,
    var(--surface-3) 12px 24px
  );
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-3);
  padding: var(--s-6);
  text-align: center;
  color: var(--text-muted);
}
.gallery-empty svg { width: 40px; height: 40px; opacity: 0.6; }
.gallery-empty .title {
  font: var(--fw-semi) var(--fs-14)/1.3 var(--font-sans);
  color: var(--text);
}
.gallery-empty .sub {
  font-size: var(--fs-12); line-height: 1.4;
  max-width: 220px;
}
.gallery-empty .btn { margin-top: var(--s-2); }

/* ---------- Modal / Dialog ---------- */
[hidden] { display: none !important; }

.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(7, 17, 26, 0.55);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 100;
  animation: fade-in var(--dur-2) var(--ease-out);
}
[data-theme="dark"] .dialog-backdrop { background: rgba(0,0,0,0.7); }

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  animation: rise var(--dur-3) var(--ease-out);
}
.dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-6);
  border-bottom: 1px solid var(--border);
}
.dialog-body { padding: var(--s-6); }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise    { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Utility ---------- */
.stack { display: flex; flex-direction: column; }
.row   { display: flex; align-items: center; }
.gap-1 { gap: var(--s-1); }  .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }  .gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); }
.between { justify-content: space-between; }
.mt-auto { margin-top: auto; }
.flex-1 { flex: 1; min-width: 0; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.mono { font-family: var(--font-mono); }

/* Kbd */
kbd {
  display: inline-block;
  padding: 2px 6px; min-width: 18px; text-align: center;
  font: var(--fw-medium) var(--fs-12)/1.4 var(--font-mono);
  color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
}

/* Divider */
.divider { height: 1px; background: var(--border); border: 0; margin: var(--s-4) 0; }
.divider-v { width: 1px; background: var(--border); align-self: stretch; }

/* Pulse (for live updates — matches Best Niches) */
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(0, 171, 179, 0.45); }
  70%  { box-shadow: 0 0 0 10px rgba(0, 171, 179, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 171, 179, 0); }
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand-500);
  animation: pulse-ring 1.8s infinite;
}

/* Scrollbars — subtle */
.nice-scroll { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.nice-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.nice-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
.nice-scroll::-webkit-scrollbar-track { background: transparent; }
