/* Photo v2 — login + upload + tabs (S3.2) — mobile-stable polish */
:root {
  --bg: #0f1419;
  --fg: #e8eef4;
  --muted: #8b9aab;
  --accent: #2f6fed;
  --ok: #3d9a6a;
  --warn: #c48a2a;
  --err: #d64545;
  --card: #1a222c;
  --border: #2a3542;
  --input-bg: #121820;
  --font: "Segoe UI", system-ui, sans-serif;
  --touch: 2.75rem; /* ≥44px */
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 20% -10%, #1c2a3d, var(--bg));
  color: var(--fg);
  overflow-x: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: max(1rem, var(--safe-top)) 1rem max(1.25rem, calc(0.75rem + var(--safe-bottom)));
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.muted { color: var(--muted); margin: 0 0 1.25rem; }

.card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.15rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.home-card {
  gap: 0;
  padding: 0;
  overflow: visible;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 0;
}

select,
input,
textarea,
button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  background: var(--input-bg);
  color: var(--fg);
  min-height: var(--touch);
  max-width: 100%;
  touch-action: manipulation;
}

/* iOS Safari zooms focused controls if font-size < 16px (labels are 0.9rem). */
input,
select,
textarea {
  width: 100%;
  font-size: 16px;
}

button {
  cursor: pointer;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

button:disabled { opacity: 0.6; cursor: wait; }
button.is-blocked { opacity: 0.65; }

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--fg);
  font-weight: 500;
}

.err {
  margin: 0;
  color: var(--err);
  font-size: 0.9rem;
}

/* Sticky shop header + tabs — solid bg avoids Safari keyboard flicker */
.home-chrome {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 1.15rem 0.7rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

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

.home-shop {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.home-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

#logout {
  flex-shrink: 0;
  padding: 0.55rem 0.85rem;
  white-space: nowrap;
}

.kind-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.kind-btn {
  background: var(--input-bg);
  border-color: var(--border);
  font-weight: 500;
}

.kind-btn.active {
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.hint {
  margin: -0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.hint.ok { color: var(--ok); }
.hint.warn { color: var(--warn); }

.article-row,
.check-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
  min-width: 0;
}

.article-label {
  margin: 0;
  min-width: 0;
}

.pick-btn {
  white-space: nowrap;
  padding: 0.65rem 0.85rem;
}

.article-picker {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: -0.1rem;
  min-width: 0;
}

.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 14rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.article-list li {
  border-bottom: 1px solid var(--border);
}

.article-list li:last-child {
  border-bottom: none;
}

.article-row-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.75rem 0.85rem;
  min-height: var(--touch);
  font-weight: 500;
}

.article-row-btn:hover,
.article-row-btn:focus-visible {
  background: #1a2838;
}

.article-row-btn strong {
  color: var(--fg);
  font-size: 0.95rem;
}

.article-row-btn span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#article-more {
  width: 100%;
}

.file-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.file-label {
  position: relative;
  display: block;
  cursor: pointer;
  min-width: 0;
}

.file-label span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.75rem 0.85rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--fg);
  background: var(--input-bg);
}

.file-label.secondary-file span {
  border-style: solid;
  color: var(--muted);
  background: transparent;
  font-size: 0.9rem;
}

.file-label input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
  min-height: 0;
  padding: 0;
  border: none;
}

.pending {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.pending-item {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  min-width: 0;
}

.pending-item img {
  width: 3rem;
  height: 3rem;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.pending-meta {
  min-width: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.pending-meta strong {
  color: var(--fg);
}

.pending-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-rm {
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0.35rem 0.55rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.saved {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.saved-item {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: 0.6rem;
  align-items: center;
  color: var(--fg);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem;
  background: var(--input-bg);
  min-width: 0;
}

.saved-item img {
  width: 3.5rem;
  height: 3.5rem;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.saved-item span {
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.35rem;
  margin: 0;
}

.tab {
  background: var(--input-bg);
  border-color: var(--border);
  font-weight: 500;
  padding: 0.55rem 0.35rem;
  font-size: 0.9rem;
  min-height: var(--touch);
}

.tab.active {
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.95rem 1.15rem 1.15rem;
  min-height: 20rem;
  min-width: 0;
}

.data-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 22rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.data-list > li {
  border-bottom: 1px solid var(--border);
}

.data-list > li:last-child {
  border-bottom: none;
}

.listing-pick {
  width: 100%;
}

.check-card {
  margin-top: 0.15rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.check-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.check-card-head strong {
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.check-badge {
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.check-badge.ok {
  color: var(--ok, #8fd19e);
  border-color: #2f5a3a;
}

.check-badge.warn {
  color: var(--warn);
  border-color: #5a4030;
}

.check-title {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.check-price {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  color: var(--text, #e8e8e8);
}

.check-price.missing {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--warn);
}

.check-calc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.manual-price {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.1rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.manual-price-field span {
  font-size: 0.9rem;
}

.manual-price-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

#manual-price-save,
#manual-price-clear {
  width: 100%;
  min-height: var(--touch);
}

.check-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.check-thumbs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.check-thumbs a {
  display: block;
  min-width: 0;
}

.check-thumbs img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #0c1016;
  display: block;
}

#listings-check {
  white-space: nowrap;
  min-height: var(--touch);
}

#listings-to-upload {
  width: 100%;
  margin-top: 0.15rem;
  min-height: var(--touch);
}

.manual-prices-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

#manual-prices-toggle,
#manual-prices-more,
#manual-prices-clear-missing {
  width: 100%;
  min-height: var(--touch);
}

.manual-prices-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: min(40dvh, 18rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.manual-prices-list > li {
  margin: 0;
  padding: 0;
  border: none;
}

.manual-prices-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.55rem;
  align-items: baseline;
  text-align: left;
  min-height: var(--touch);
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.manual-prices-art {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.manual-prices-price {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.manual-prices-date {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.manual-prices-row.is-missing {
  border-color: #d6b07a;
}

.manual-prices-missing {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  color: #b45309;
}

.photos-filters {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: end;
  min-width: 0;
}

.photos-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  max-height: min(60dvh, 26rem);
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.photos-grid > li {
  border: none;
  min-width: 0;
}

.photo-card {
  min-width: 0;
}

.photo-card a {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: var(--fg);
  min-width: 0;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #0c1016;
  display: block;
}

.photo-card span {
  font-size: 0.72rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.photo-card .photo-del {
  width: 100%;
  margin-top: 0.35rem;
  min-height: var(--touch);
  font-size: 0.9rem;
  border-color: #5a3030;
  color: #f0c0c0;
}

.photo-card.photo-deleting {
  opacity: 0.55;
  pointer-events: none;
}

#photos-more,
#upload {
  width: 100%;
  min-height: var(--touch);
}

/* Narrow phones: stack cramped rows, keep touch targets */
@media (max-width: 480px) {
  .shell {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .home-chrome {
    padding-left: 0.95rem;
    padding-right: 0.95rem;
  }

  .tab-panel {
    padding-left: 0.95rem;
    padding-right: 0.95rem;
    min-height: 18rem;
  }

  .article-row,
  .check-row,
  .photos-filters {
    grid-template-columns: 1fr;
  }

  .pick-btn,
  #listings-check,
  #photos-apply,
  #manual-prices-toggle,
  #manual-prices-more,
  #manual-prices-clear-missing {
    width: 100%;
  }

  .photos-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: min(55dvh, 24rem);
  }

  .check-thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab {
    font-size: 0.85rem;
    padding: 0.5rem 0.25rem;
  }
}

@media (max-width: 360px) {
  .photos-grid {
    grid-template-columns: 1fr;
  }
}

/* Desktop: a bit more air, keep sticky chrome */
@media (min-width: 640px) {
  .shell {
    padding: 2rem 1.25rem 2.5rem;
  }

  .tab-panel {
    min-height: 22rem;
  }

  .photos-grid {
    max-height: 28rem;
  }
}
