/* Qply QR Codes — mobile-first styles. Brand: blue #3326E8, orange #FF7A1A (logo only). */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #14161f;
  --text-muted: #5d6475;
  --border: #e1e4ee;
  --accent: #3326e8;        /* Qply blue: buttons and fills */
  --accent-strong: #2618c9; /* pressed */
  --accent-text: #3326e8;   /* links, text buttons, icons */
  --accent-soft: #ecebfe;
  --on-accent: #ffffff;
  --danger: #c02637;
  --shadow: 0 1px 2px rgb(20 22 31 / 0.06), 0 6px 20px rgb(20 22 31 / 0.08);
  --shadow-strong: 0 10px 40px rgb(20 22 31 / 0.22);
  --radius: 16px;
  --radius-small: 10px;
  --backdrop: rgb(10 12 20 / 0.45);
  --toast-bg: #1c1f2a;
  --toast-text: #ffffff;
  --toast-action: #a8a2ff;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --gutter: 16px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #191c25;
    --surface-2: #232733;
    --text: #eef0f6;
    --text-muted: #a2a9ba;
    --border: #2c3140;
    --accent: #3326e8;
    --accent-strong: #4a3ff0;
    --accent-text: #a8a2ff;   /* Qply blue is too dark to read as text on black */
    --accent-soft: #242053;
    --on-accent: #ffffff;
    --danger: #ff6b7a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.3);
    --shadow-strong: 0 10px 40px rgb(0 0 0 / 0.55);
    --backdrop: rgb(0 0 0 / 0.6);
    --toast-bg: #eef0f6;
    --toast-text: #14161f;
    --toast-action: #3326e8;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body.modal-open { overflow: hidden; }

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

svg { fill: currentColor; }

:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + var(--gutter)) 10px calc(var(--safe-left) + var(--gutter));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

/* Brand lockup: Qply logo | QR Codes */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 0 2px;
}

.brand img { display: block; width: auto; height: 31px; }

.brand-product {
  padding-left: 10px;
  border-left: 2px solid var(--border);
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 24px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 0 12px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.search svg { width: 20px; height: 20px; flex: none; }

.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* 16px stops iOS from zooming on focus */
  outline: none;
}

/* ---------- Buttons ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}

.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn-small { width: 36px; height: 36px; }
.icon-btn-small svg { width: 20px; height: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font-weight: 650;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-strong); }
.btn-tonal { background: var(--accent-soft); color: var(--accent-text); }
.btn-quiet { background: transparent; color: var(--accent-text); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 0.9375rem; }
.btn-block { width: 100%; }

.text-btn {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font-size: 1rem;
}

.text-btn-strong { font-weight: 700; }
.text-btn-danger { color: var(--danger); }
.text-btn:disabled { color: var(--text-muted); opacity: 0.55; cursor: default; }

/* ---------- Main list ---------- */

main {
  padding: 4px calc(var(--safe-right) + var(--gutter)) calc(var(--safe-bottom) + 110px) calc(var(--safe-left) + var(--gutter));
  max-width: 1100px;
  margin: 0 auto;
}

.link-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* minmax(0, …) lets long links shrink instead of widening the page */
  gap: 10px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 640px) {
  .link-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 980px) {
  .link-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 120ms ease;
}

.link-card:active { transform: scale(0.985); }

.link-thumb {
  flex: none;
  width: 64px;
  height: 64px;
  padding: 4px;
  border-radius: var(--radius-small);
  background: #fff; /* QR codes always sit on white so phones can scan them */
}

.link-thumb svg { display: block; width: 100%; height: 100%; }

/* A link with a picture shows the picture, with a small QR badge in the corner. */
.link-thumb.has-picture { position: relative; padding: 0; overflow: hidden; }
.link-thumb.has-picture > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.link-thumb.is-icon > img { padding: 10px; object-fit: contain; }

.qr-badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 22px;
  height: 22px;
  padding: 3px;
  border-radius: 6px;
  background: #fff;
  color: #14161f;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
}

.link-thumb .qr-badge svg { width: 100%; height: 100%; }

.link-text { flex: 1; min-width: 0; }

.link-title,
.link-url {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.link-title { font-weight: 650; font-size: 1.0625rem; }
.link-url { color: var(--text-muted); font-size: 0.875rem; margin-top: 2px; }

.link-chevron { flex: none; width: 20px; height: 20px; color: var(--text-muted); }

/* ---------- Empty state ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 12px 24px;
}

.empty-art img { border-radius: 22px; box-shadow: var(--shadow); }
.empty h2 { margin: 22px 0 6px; font-size: 1.375rem; letter-spacing: -0.01em; }
.empty p { margin: 0 0 22px; max-width: 30ch; color: var(--text-muted); }

.no-results { margin: 28px 0; text-align: center; color: var(--text-muted); }

/* ---------- Install banner ---------- */

.install-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 4px;
  padding: 12px 8px 12px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.install-banner > div:first-child { flex: 1; min-width: 0; }
.install-banner p { margin: 2px 0 0; color: var(--text-muted); font-size: 0.875rem; }
.install-banner-actions { display: flex; align-items: center; gap: 2px; }

/* ---------- Floating add button ---------- */

.fab {
  position: fixed;
  right: calc(var(--safe-right) + var(--gutter));
  bottom: calc(var(--safe-bottom) + 20px);
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 1.0625rem;
  box-shadow: var(--shadow-strong);
}

.fab svg { width: 24px; height: 24px; }
.fab:active { background: var(--accent-strong); }

/* ---------- Sheets (full screen on phones, centered card on bigger screens) ---------- */

dialog {
  padding: 0;
  border: 0;
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop { background: var(--backdrop); }

.sheet {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg);
}

.sheet[open] { animation: sheet-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1); }

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
  .sheet {
    width: min(520px, calc(100% - 48px));
    height: auto;
    max-height: calc(100% - 48px);
    margin: auto;
    border-radius: 20px;
    box-shadow: var(--shadow-strong);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .picture-thumb[data-state="loading"]::after { animation-duration: 2.4s; }
  .link-card { transition: none; }
}

.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(64px, auto) 1fr minmax(64px, auto);
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 8px) 6px calc(var(--safe-left) + 8px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

@media (min-width: 640px) {
  .sheet-bar { padding-top: 6px; }
}

.sheet-bar > :first-child { justify-self: start; }
.sheet-bar > :last-child { justify-self: end; }

.sheet-bar h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  text-align: center;
}

.sheet-title-ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sheet-body {
  padding: 12px calc(var(--safe-right) + var(--gutter)) calc(var(--safe-bottom) + 28px) calc(var(--safe-left) + var(--gutter));
}

/* ---------- Editor form ---------- */

.field { margin-bottom: 18px; }

.field label,
.field-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 650;
  font-size: 0.9375rem;
}

.optional { color: var(--text-muted); font-weight: 400; }

.field input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 16px stops iOS from zooming on focus */
}

.field input:focus { border-color: var(--accent-text); outline: 2px solid color-mix(in srgb, var(--accent-text) 30%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }

.input-row { display: flex; gap: 8px; align-items: center; }
.input-row input { flex: 1; min-width: 0; }
.input-row .btn { flex: none; min-height: 50px; border-radius: 12px; }

.field-msg {
  min-height: 1.2em;
  margin: 6px 2px 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.field-msg.is-error { color: var(--danger); }

/* Picture field in the editor */
.picture-row { display: flex; align-items: center; gap: 14px; }

.picture-thumb {
  flex: none;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.picture-thumb > img { width: 100%; height: 100%; object-fit: cover; }
.picture-thumb[data-kind="icon"] { background: #fff; }
.picture-thumb[data-kind="icon"] > img { padding: 12px; object-fit: contain; }
.picture-thumb > svg { width: 30px; height: 30px; }

.picture-thumb[data-state="loading"]::after {
  content: "";
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

.picture-side { flex: 1; min-width: 0; }
.picture-status { margin: 0 0 8px; color: var(--text-muted); font-size: 0.875rem; }
.picture-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: -2px; }
.picture-actions .btn-quiet { padding: 0 10px; }

.preview { display: grid; place-items: center; padding-top: 4px; }

/* ---------- QR frames ---------- */

.qr-frame {
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: #fff;
  color: #14161f;
  box-shadow: var(--shadow);
}

.qr-frame svg { display: block; width: 100%; height: 100%; }

.qr-frame-small { width: 200px; height: 200px; padding: 10px; }
.qr-frame-large { width: min(100%, 420px); aspect-ratio: 1; padding: 14px; margin: 8px auto 0; }

.preview-placeholder {
  padding: 24px;
  color: #6b7280;
  font-size: 0.875rem;
  text-align: center;
}

/* ---------- Viewer ---------- */

.viewer-body { display: flex; flex-direction: column; align-items: center; }

.viewer-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: min(100%, 460px);
  margin: 18px 0 4px;
}

.viewer-picture {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: #fff;
  box-shadow: var(--shadow);
}

.viewer-picture.is-icon { padding: 6px; object-fit: contain; }

.viewer-url {
  display: block;
  min-width: 0;
  margin: 0;
  color: var(--accent-text);
  font-size: 0.9375rem;
  text-align: center;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 460px);
  margin: 18px 0 22px;
}

.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 76px;
  padding: 12px 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.action svg { width: 26px; height: 26px; color: var(--accent-text); }
.action:active { background: var(--surface-2); }

/* ---------- Menu & small dialogs ---------- */

.menu {
  width: min(420px, calc(100% - 2 * var(--gutter)));
  margin: auto auto calc(var(--safe-bottom) + 16px);
  border-radius: 18px;
  box-shadow: var(--shadow-strong);
}

@media (min-width: 640px) {
  .menu { margin: auto; }
}

.menu-list { display: flex; flex-direction: column; padding: 6px; }

.menu-item {
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  font-size: 1rem;
}

.menu-item:active { background: var(--surface-2); }
.menu-item-muted { color: var(--text-muted); }

.menu-content { padding: 20px; }
.menu-content h2 { margin: 0 0 12px; font-size: 1.1875rem; }
.menu-content p { margin: 0 0 12px; }
.menu-content .btn { margin-top: 8px; }
.muted { color: var(--text-muted); font-size: 0.875rem; }

.steps { margin: 0 0 16px; padding-left: 1.3em; }
.steps li { margin-bottom: 8px; }
.inline-icon { display: inline-block; padding: 0 4px; border-radius: 6px; background: var(--surface-2); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 88px);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 6px 8px 6px 18px;
  min-height: 48px;
  border-radius: 14px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-strong);
  transform: translateX(-50%);
  animation: toast-in 180ms ease-out;
}

.toast .text-btn { color: var(--toast-action); }

/* Inside a full-screen view there's no Add button to clear, so sit lower. */
.sheet .toast { bottom: calc(var(--safe-bottom) + 16px); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.noscript { padding: 24px; text-align: center; }

.viewer-picture:not([hidden]) + .viewer-url { text-align: left; }
