/*
 * Store sidecar UI — hand-written CSS that reproduces sub2api's ProductsView.vue
 * without a Tailwind build. Palette matches frontend/tailwind.config.js:
 *   primary = teal/emerald (500 #14b8a6, 600 #0d9488, 700 #0f766e)
 *   dark    = slate scale used for dark-mode surfaces
 * Theme is toggled by adding/removing the `dark` class on <html> (see app.js),
 * driven by the ?theme= query param.
 */

:root {
  --primary-50: #f0fdfa;
  --primary-100: #ccfbf1;
  --primary-300: #5eead4;
  --primary-400: #2dd4bf;
  --primary-500: #14b8a6;
  --primary-600: #0d9488;
  --primary-700: #0f766e;
  --accent-100: #ccfbf1;

  /* light surfaces (Tailwind default gray) */
  --page-bg: #f9fafb;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --divide: #f3f4f6;
  --surface-muted: #f9fafb;
  --cover-bg: #f3f4f6;

  --text: #111827;      /* gray-900 */
  --text-soft: #4b5563; /* gray-600 */
  --text-muted: #6b7280;/* gray-500 */
  --text-faint: #9ca3af;/* gray-400 */

  --badge-bg: rgba(255, 255, 255, 0.9);
  --badge-text: var(--primary-700);
  --btn-secondary-bg: #f3f4f6;
  --btn-secondary-text: #374151;
  --btn-secondary-hover: #e5e7eb;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

html.dark {
  --page-bg: #0f172a;      /* dark-900 */
  --card-bg: #1e293b;      /* dark-800 */
  --border: #334155;       /* dark-700 */
  --divide: #334155;
  --surface-muted: #1e293b;
  --cover-bg: #334155;

  --text: #ffffff;
  --text-soft: #cbd5e1;    /* dark-300 */
  --text-muted: #94a3b8;   /* dark-400 */
  --text-faint: #64748b;   /* dark-500 */

  --badge-bg: rgba(15, 23, 42, 0.8);
  --badge-text: var(--primary-300);
  --btn-secondary-bg: #334155;
  --btn-secondary-text: #e5e7eb;
  --btn-secondary-hover: #475569;

  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* Card container (.card p-4 sm:p-6) */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 24px; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 16px;
}
.section-head + .section-sub { margin-top: -12px; }
.section-title { font-size: 18px; font-weight: 600; margin: 0; color: var(--text); }
.section-note { margin: 0; font-size: 12px; color: var(--text-muted); }
.section-sub { margin: 0 0 20px; font-size: 14px; color: var(--text-muted); }

/* Product grid */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
/* Cards never grow past 290px: on a wide host panel the row fills with more
   columns (or leaves space on the right) instead of stretching each card. */
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(230px, 290px)); gap: 14px; }
}

.product {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  transition: box-shadow 0.2s ease;
}
.product:hover { box-shadow: var(--shadow-md); }

.cover {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--cover-bg);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--primary-50), var(--accent-100));
  color: var(--primary-400);
}
html.dark .cover-placeholder {
  background: linear-gradient(135deg, #334155, #0f172a);
  color: var(--primary-500);
}
.cover-placeholder .ph-icon { font-size: 28px; }
.cover-placeholder .ph-text { font-size: 12px; color: var(--text-faint); }

.badge {
  position: absolute;
  right: 8px;
  top: 8px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 9999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(4px);
}

.product-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 12px 14px 14px;
}
.product-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-summary {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-foot {
  /* Pin price + button to the card bottom so they line up across a row even
     when one card's summary wraps to more lines. */
  margin-top: auto;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.price { font-size: 16px; font-weight: 600; color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-sm { font-size: 12px; padding: 6px 12px; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: #ffffff;
}
.btn-primary:not(:disabled):hover { filter: brightness(1.05); }
.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}
.btn-secondary:not(:disabled):hover { background: var(--btn-secondary-hover); }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 32px; height: 32px; border-color: var(--primary-500); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; justify-content: center; padding: 64px 0; }

.empty { text-align: center; padding: 64px 0; color: var(--text-muted); font-size: 14px; }

/* Orders list */
.orders { list-style: none; margin: 0; padding: 0; }
.orders li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 0;
  border-top: 1px solid var(--divide);
}
.orders li:first-child { border-top: none; }
.order-main { min-width: 0; flex: 1; }
.order-product { margin: 0; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-time { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.order-price { font-size: 14px; font-weight: 600; color: var(--text); flex-shrink: 0; }

/* Dialogs */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.dialog {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 24px;
}
.dialog h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; color: var(--text); }
.dialog p.msg { margin: 0 0 16px; font-size: 14px; color: var(--text-soft); }

.balance-box {
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 16px;
  font-size: 14px;
}
.balance-row { display: flex; align-items: center; justify-content: space-between; }
.balance-row + .balance-row { margin-top: 8px; }
.balance-row .label { color: var(--text-muted); }
.balance-row .val { font-weight: 500; color: var(--text); }
.balance-row .val.hl { font-weight: 600; color: var(--primary-600); }
html.dark .balance-row .val.hl { color: var(--primary-400); }

.payload {
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
  margin: 0;
  max-height: 46vh;
  overflow-y: auto;
  overflow-wrap: anywhere;
}
.payload-line { min-height: 1em; }
.payload-gap { height: 8px; }
.payload-link {
  color: var(--primary-600);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--primary-600) 40%, transparent);
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.payload-link:hover { text-decoration-color: var(--primary-600); }
html.dark .payload-link { color: var(--primary-400); }
.payload-code {
  display: inline-block;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.6;
  vertical-align: baseline;
}
.payload-label { margin: 0 0 4px; font-size: 12px; font-weight: 500; color: var(--text-muted); }

.dialog-actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.hidden { display: none !important; }


/* ---- Embedded mode (ui_mode=embedded, inside sub2api's content pane) ----
   The host already wraps the iframe in a rounded card and floats a
   "open in new tab" button at the top-right, so: no second card, transparent
   ground, full pane width, and the header keeps the top-right clear. */
html.embedded, html.embedded body { background: transparent; }
.embedded .wrap { max-width: none; padding: 20px 24px 28px; } /* host iframe has no inset; match sub2api's own page gutter */
.embedded .card {
  background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 0;
}
.embedded .card + .card {
  margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border);
}
.embedded .section-head {
  flex-direction: column; align-items: flex-start; gap: 2px;
  padding-right: 160px; /* clearance for the host's floating button */
}
.embedded .section-title { font-size: 16px; }
.embedded .section-note { font-size: 12px; }
.embedded .section-sub { margin-bottom: 14px; font-size: 13px; }
@media (max-width: 560px) { .embedded .wrap { padding: 16px; } .embedded .section-head { padding-right: 0; padding-top: 40px; } }
