/* ==========================================================================
   Online Store > Themes (#/themes) and the Theme editor (#/themes/customize) — THEME-2 layout pass.
   Compact cards, one preview ratio (16:10), teal primary actions (#0F766E), settings sidebar + live preview on desktop,
   settings drawer + full-width preview on phones. Presentation only; data, RPC and storefront rendering are unchanged.
   ========================================================================== */
#view-themes, .th-pv {
  --th-teal: #0F766E; --th-teal-dark: #0B5E58; --th-teal-soft: #E7F5F2;
  --th-line: var(--color-border-soft, #E2E8F0); --th-ink: var(--color-text, #0F172A); --th-muted: var(--color-text-muted, #64748B);
}
#view-themes .th-loading, #view-themes .th-note, .th-pv .th-note { padding: 16px 0; color: var(--th-muted); font-size: 13px; }

/* buttons: one size everywhere on this page */
#view-themes .btn, .th-pv .btn { width: auto; min-height: 36px; padding: 0 14px; gap: 6px; font-size: 13px; font-weight: 600; line-height: 20px; box-shadow: none; white-space: nowrap; text-decoration: none; }
#view-themes .btn .ai, .th-pv .btn .ai { display: inline-flex; width: 16px; height: 16px; }
#view-themes .btn .ai svg, .th-pv .btn .ai svg { width: 16px; height: 16px; }
#view-themes .btn-primary, .th-pv .btn-primary { background: var(--th-teal); border: 1px solid var(--th-teal); color: #fff; }
#view-themes .btn-primary:hover, .th-pv .btn-primary:hover { background: var(--th-teal-dark); border-color: var(--th-teal-dark); }
#view-themes .btn-ghost { background: #fff; border: 1px solid var(--color-border-strong, #CBD5E1); color: var(--th-ink); }
#view-themes .btn:focus-visible, .th-pv .btn:focus-visible, #view-themes .th-icon-btn:focus-visible, .th-pv .th-icon-btn:focus-visible { outline: 2px solid var(--th-teal); outline-offset: 2px; }
#view-themes .btn:disabled { opacity: .45; cursor: not-allowed; }
#view-themes a[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: auto; }

/* page */
#view-themes .th-section { margin: 0 0 20px; }
#view-themes .th-section h2 { margin: 0 0 10px; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--th-ink); }
#view-themes .th-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#view-themes .th-card { display: flex; gap: 14px; align-items: stretch; min-width: 0; padding: 12px; background: #fff; border: 1px solid var(--th-line); border-radius: 12px; }
#view-themes .th-thumb { flex: none; width: 176px; aspect-ratio: 16 / 10; align-self: flex-start; overflow: hidden; border-radius: 8px; border: 1px solid var(--th-line); background: #F1F5F9; display: flex; }
#view-themes .th-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
#view-themes .th-card-text { min-width: 0; }
#view-themes .th-card-text b { display: block; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--th-ink); }
#view-themes .th-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#view-themes .th-title b { display: inline; }
#view-themes .th-card-text p, #view-themes .th-hint { margin: 2px 0 0; font-size: 13px; line-height: 18px; color: var(--th-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#view-themes .th-hint { margin: 0; -webkit-line-clamp: 3; flex: 1 1 100%; }
#view-themes .th-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#view-themes .th-current { max-width: 640px; }
#view-themes .th-live { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--th-teal-soft); color: var(--th-teal-dark); font-size: 12px; font-weight: 600; line-height: 20px; }
#view-themes .th-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--th-teal); }

/* mock storefront thumbnails (decorative; fill the 16:10 box) */
.th-mock { flex: 1; min-width: 0; min-height: 0; background: #fff; padding: 7px; display: flex; flex-direction: column; gap: 5px; }
.th-mock i { display: block; height: 5px; border-radius: 3px; background: #D1D5DB; flex: none; }
.th-mock b { display: block; flex: 1; min-height: 0; border-radius: 4px; background: #9CA3AF; position: relative; overflow: hidden; }
.th-mock-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; flex: none; }
.th-mock-grid u { display: block; height: 24px; border-radius: 3px; background: #E5E7EB; position: relative; overflow: hidden; }
.th-mock-g i, .th-mock-g b { background: #0B3D2E; }
.th-mock-g .th-mock-grid u { background: #F1F1F1; }
.th-mock b img, .th-mock-grid u img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

/* shared editor / preview chrome */
.th-icon-btn { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--th-ink); cursor: pointer; text-decoration: none; }
.th-icon-btn:hover { background: #F1F5F9; }
.th-icon-btn .ai, .th-icon-btn svg { width: 20px; height: 20px; }
.th-bar-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.th-bar-id b { font-size: 14px; line-height: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--th-ink); }
.th-unsaved, .th-pv-tag { font-size: 12px; line-height: 18px; font-weight: 500; color: #92400E; background: #FEF3C7; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.th-pv-tag { color: #475569; background: #F1F5F9; }
.th-devices { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--th-line); border-radius: 8px; background: #F8FAFC; }
.th-devices button { height: 30px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; font-size: 13px; font-weight: 500; color: var(--th-muted); cursor: pointer; }
.th-devices button.on { background: #fff; color: var(--th-ink); box-shadow: 0 1px 2px rgba(15, 23, 42, .12); }
.th-stage { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; justify-content: center; background: #EEF1F4; padding: 12px; overflow: auto; }
.th-frame-wrap { width: 100%; height: 100%; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(15, 23, 42, .14); }
.th-frame-wrap.is-mobile { width: 390px; max-width: 100%; }
.th-frame-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }

/* editor */
#view-themes .th-editor { display: flex; flex-direction: column; height: calc(100vh - var(--header-h, 56px) - 48px); height: calc(100dvh - var(--header-h, 56px) - 48px); min-height: 480px; background: #fff; border: 1px solid var(--th-line); border-radius: 12px; overflow: hidden; }
#view-themes .th-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--th-line); }
#view-themes .th-bar .th-bar-id { flex: 1; }
#view-themes .th-bar-actions { display: flex; gap: 8px; }
#view-themes .th-body { position: relative; display: flex; flex: 1; min-height: 0; }
#view-themes .th-panel { width: 320px; flex: none; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--th-line); background: #fff; }
#view-themes .th-panel-head, #view-themes .th-panel-foot, #view-themes .th-scrim, #view-themes .th-fab { display: none; }
#view-themes .th-panel-scroll { flex: 1; min-height: 0; overflow: auto; padding: 0 14px 16px; overscroll-behavior: contain; }
#view-themes .th-group { border-bottom: 1px solid var(--th-line); padding: 6px 0 10px; }
#view-themes .th-group summary { padding: 8px 0; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--th-ink); cursor: pointer; }
#view-themes .th-field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
#view-themes .th-field > label, #view-themes .th-label { font-size: 12.5px; line-height: 18px; color: var(--th-muted); }
#view-themes .th-field input[type=text], #view-themes .th-field textarea { width: 100%; box-sizing: border-box; min-height: 36px; padding: 7px 10px; border: 1px solid var(--color-border-strong, #CBD5E1); border-radius: 8px; background: #fff; font: inherit; font-size: 13px; color: var(--th-ink); }
#view-themes .th-field textarea { resize: vertical; }
#view-themes .th-field input:focus-visible, #view-themes .th-field textarea:focus-visible { outline: 2px solid var(--th-teal); outline-offset: 0; border-color: var(--th-teal); }
#view-themes .th-field input[aria-invalid="true"] { border-color: #DC2626; }
#view-themes .th-color { display: flex; gap: 8px; align-items: center; }
#view-themes .th-color input[type=color] { flex: none; width: 40px; height: 36px; padding: 2px; border: 1px solid var(--color-border-strong, #CBD5E1); border-radius: 8px; background: #fff; }
#view-themes .th-color input[type=text] { flex: 1; min-width: 0; font-family: var(--font-mono, ui-monospace, monospace); }
#view-themes .th-check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; color: var(--th-ink); min-height: 28px; }
#view-themes .th-check input { width: 16px; height: 16px; accent-color: var(--th-teal); }
#view-themes .th-img { display: flex; align-items: center; justify-content: center; min-height: 64px; overflow: hidden; border: 1px dashed var(--color-border-strong, #CBD5E1); border-radius: 8px; background: #F8FAFC; }
#view-themes .th-img img { max-width: 100%; max-height: 96px; object-fit: contain; }
#view-themes .th-img em { font-size: 12px; color: var(--th-muted); font-style: normal; }
#view-themes .th-img-actions { display: flex; gap: 8px; }
#view-themes .th-upload { cursor: pointer; }
#view-themes .th-upload.is-busy { opacity: .6; pointer-events: none; }

/* desktop: device toggle centred; the Customize pill and drawer chrome are phone-only */
@media (min-width: 861px) {
  #view-themes .th-devices { margin: 0 auto; }
}

/* tablet/phone */
@media (max-width: 860px) {
  #view-themes .th-grid { grid-template-columns: minmax(0, 1fr); }
  #view-themes .th-current { max-width: none; }
}
@media (max-width: 560px) {
  #view-themes .th-card { gap: 12px; padding: 10px; }
  #view-themes .th-thumb { width: 112px; }
  #view-themes .th-card-body { gap: 8px; }
  #view-themes .th-actions .btn { flex: 1 1 0; min-width: 0; }
  #view-themes .th-card-text p { -webkit-line-clamp: 2; font-size: 12.5px; }
  /* thumb + title on one row; the buttons span the full card width underneath */
  #view-themes .th-card { flex-wrap: wrap; }
  #view-themes .th-card-body { display: contents; }
  #view-themes .th-card-text { flex: 1; min-width: 0; align-self: center; }
  #view-themes .th-actions { flex: 1 1 100%; }
}
@media (max-width: 860px) {
  /* editor: full-bleed preview, settings in a bottom drawer */
  #view-themes .th-editor { height: calc(100vh - 56px - 64px - env(safe-area-inset-bottom, 0px) - 16px); height: calc(100dvh - 56px - 64px - env(safe-area-inset-bottom, 0px) - 16px); min-height: 420px; margin: 0 calc(-1 * var(--m-gutter, 16px)); border-left: 0; border-right: 0; border-radius: 0; }
  #view-themes .th-bar { gap: 6px; padding: 6px 8px; }
  #view-themes .th-devices, #view-themes .th-bar-actions #thDiscard { display: none; }
  #view-themes .th-stage { padding: 0; background: #fff; }
  #view-themes .th-frame-wrap, #view-themes .th-frame-wrap.is-mobile { width: 100%; max-width: 100%; border-radius: 0; box-shadow: none; }
  #view-themes .th-fab { display: inline-flex; position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3; min-height: 40px; padding: 0 18px; border-radius: 999px; box-shadow: 0 4px 14px rgba(15, 23, 42, .28); }
  #view-themes .th-fab.has-changes::after { content: ""; width: 8px; height: 8px; margin-left: 2px; border-radius: 50%; background: #FCD34D; }
  #view-themes .th-scrim { display: block; position: fixed; inset: 0; z-index: 1049; background: rgba(15, 23, 42, .4); opacity: 0; pointer-events: none; transition: opacity .18s; }
  #view-themes .th-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1050; width: auto; max-height: min(78dvh, 640px); border: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 28px rgba(15, 23, 42, .22);
    transform: translateY(105%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #view-themes .th-editor.is-open .th-panel { transform: none; visibility: visible; transition: transform .22s ease; }
  #view-themes .th-editor.is-open .th-scrim { opacity: 1; pointer-events: auto; }
  #view-themes .th-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--th-line); }
  #view-themes .th-panel-head b { font-size: 14px; font-weight: 600; }
  #view-themes .th-panel-foot { display: block; padding: 10px 14px; border-top: 1px solid var(--th-line); background: #fff; }
  #view-themes .th-panel-foot .btn { width: 100%; }
  /* 16px inputs: no iOS zoom on focus */
  #view-themes .th-field input[type=text], #view-themes .th-field textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { #view-themes .th-panel, #view-themes .th-scrim { transition: none; } }

/* preview overlay (library "Preview") */
body.th-pv-open { overflow: hidden; }
.th-pv { position: fixed; inset: 0; z-index: 1100; display: flex; flex-direction: column; background: #fff; }
.th-pv .th-pv-bar { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px 8px; border-bottom: 1px solid var(--th-line); }
.th-pv .th-bar-id { flex: 1; }
.th-pv .th-stage { padding: 12px; }
@media (max-width: 860px) {
  .th-pv .th-devices { display: none; }
  .th-pv .th-stage { padding: 0; background: #fff; }
  .th-pv .th-frame-wrap, .th-pv .th-frame-wrap.is-mobile { width: 100%; border-radius: 0; box-shadow: none; }
}
