@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;1,9..144,500&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #171614;
  --ink-soft: #211f1c;
  --paper: #f3eee4;
  --safelight: #e2a33b;
  --darkroom-red: #c1442d;
  --success-green: #3f8f5f;
  --fog: #8a8778;
  --line: #3a3733;
  --radius: 2px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}

h1, h2, h3 { font-family: 'Fraunces', serif; font-weight: 600; margin: 0 0 .4em; }
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .72rem;
  color: var(--safelight);
}

a { color: var(--safelight); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: 'Fraunces', serif; font-size: 1.15rem; }
.topbar .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--darkroom-red); }
.topbar nav a, .topbar nav button {
  color: var(--paper); text-decoration: none; margin-left: 18px; font-size: .9rem;
  background: none; border: none; font-family: inherit; cursor: pointer;
}
.topbar nav a:hover, .topbar nav button:hover { color: var(--safelight); }

/* Auth card */
.auth-shell { min-height: calc(100vh - 73px); display: flex; align-items: center; justify-content: center; padding: 40px 20px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--ink-soft);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 36px;
  position: relative;
}
.bracket-frame { position: relative; }
.bracket-frame::before, .bracket-frame::after,
.bracket-frame .b-tr, .bracket-frame .b-bl {
  content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid var(--safelight);
}
.bracket-frame::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.bracket-frame::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }
.bracket-frame .b-tr { top: -1px; right: -1px; border-left: none; border-bottom: none; }
.bracket-frame .b-bl { bottom: -1px; left: -1px; border-right: none; border-top: none; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: .8rem; color: var(--fog); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 11px 12px; background: var(--ink); border: 1px solid var(--line);
  color: var(--paper); border-radius: var(--radius); font-family: inherit; font-size: .95rem;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--safelight); outline-offset: 1px; border-color: var(--safelight); }

.selfie-picker {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px;
  text-align: center; cursor: pointer; background: var(--ink);
}
.selfie-picker img { max-width: 100%; max-height: 180px; border-radius: var(--radius); }
.selfie-picker .hint { color: var(--fog); font-size: .82rem; margin-top: 6px; }

.btn {
  display: inline-block; padding: 12px 20px; border-radius: var(--radius); border: none;
  font-family: 'IBM Plex Mono', monospace; font-size: .82rem; letter-spacing: .04em;
  text-transform: uppercase; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--safelight); color: var(--ink); width: 100%; }
.btn-primary:hover { background: #f0b357; }
.btn-secondary { background: transparent; color: var(--paper); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--safelight); color: var(--safelight); }
.btn-buy { background: var(--darkroom-red); color: var(--paper); }
.btn-buy:hover { background: #d75136; }
.btn-download { background: var(--success-green); color: var(--paper); }
.btn-download:hover { background: #4ba873; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.form-foot { margin-top: 16px; font-size: .85rem; color: var(--fog); text-align: center; }
.error-banner {
  background: rgba(193,68,45,.15); border: 1px solid var(--darkroom-red); color: #f2b6a8;
  padding: 10px 12px; border-radius: var(--radius); font-size: .85rem; margin-bottom: 16px; display: none;
}
.success-banner {
  background: rgba(226,163,59,.12); border: 1px solid var(--safelight); color: var(--safelight);
  padding: 10px 12px; border-radius: var(--radius); font-size: .85rem; margin-bottom: 16px; display: none;
}

/* Dashboard */
.hero-row { display: flex; align-items: baseline; justify-content: space-between; margin: 40px 0 24px; flex-wrap: wrap; gap: 12px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 22px; padding-bottom: 60px; }

.photo-card { position: relative; }
.photo-card .frame { position: relative; }
.photo-card img {
  width: 100%; aspect-ratio: 4/5; object-fit: cover; display: block; background: var(--ink-soft); border-radius: var(--radius);
  -webkit-user-select: none; user-select: none;
  -webkit-user-drag: none; user-drag: none;
  -webkit-touch-callout: none; /* blocks the iOS long-press "Save Image" menu */
  pointer-events: auto;
}
.photo-card .readout {
  position: absolute; top: 8px; left: 8px; background: rgba(23,22,20,.75);
  font-family: 'IBM Plex Mono', monospace; font-size: .68rem; color: var(--safelight);
  padding: 3px 7px; border-radius: 2px; letter-spacing: .04em;
}
.photo-card .owned-tag {
  position: absolute; top: 8px; right: 8px; background: var(--safelight); color: var(--ink);
  font-family: 'IBM Plex Mono', monospace; font-size: .68rem; padding: 3px 7px; border-radius: 2px; font-weight: 500;
}
.photo-card .meta { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.photo-card .price { font-family: 'IBM Plex Mono', monospace; color: var(--fog); font-size: .85rem; }
.photo-card input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--safelight); }
.photo-card .select-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .8rem; color: var(--fog); }
.download-note { color: var(--fog); font-size: .74rem; text-align: center; line-height: 1.4; }

.empty-state { text-align: center; padding: 80px 20px; color: var(--fog); }
.empty-state .eyebrow { display: block; margin-bottom: 10px; }

.footer-cta {
  text-align: center; padding: 48px 24px 64px; border-top: 1px solid var(--line); margin-top: 40px;
}
.footer-cta p { color: var(--fog); font-size: .92rem; margin: 0 0 16px; }
.btn-whatsapp {
  display: inline-flex; align-items: center; gap: 8px; background: var(--success-green); color: var(--paper);
  padding: 12px 24px; border-radius: var(--radius); text-decoration: none;
  font-family: 'IBM Plex Mono', monospace; font-size: .82rem; letter-spacing: .04em; text-transform: uppercase;
}
.btn-whatsapp:hover { background: #4ba873; }

.code-search-row { display: flex; gap: 10px; margin: 16px 0 28px; max-width: 480px; }
.code-search-row input {
  flex: 1; padding: 11px 12px; background: var(--ink-soft); border: 1px solid var(--line);
  color: var(--paper); border-radius: var(--radius); font-family: inherit; font-size: .95rem;
}
.code-search-row input:focus { outline: 2px solid var(--safelight); outline-offset: 1px; border-color: var(--safelight); }

.code-card {
  background: var(--ink-soft); border: 1px dashed var(--safelight); border-radius: var(--radius);
  padding: 20px 24px; margin: 24px 0; text-align: center;
}
.code-card-label { font-size: .8rem; color: var(--fog); margin-bottom: 12px; }
.code-card-row { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
.code-card-value {
  font-family: 'IBM Plex Mono', monospace; font-size: 2.4rem; font-weight: 500; color: var(--safelight);
  letter-spacing: .25em; padding-left: .25em; /* compensates for letter-spacing on last char */
}

.order-card { background: var(--ink-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.order-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.order-number { font-family: 'IBM Plex Mono', monospace; font-size: 1.3rem; color: var(--paper); letter-spacing: .04em; }
.order-card-body { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: start; }
.order-item-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: .85rem; color: var(--paper); border-bottom: 1px solid var(--line); }
.order-item-row-full { align-items: flex-start; padding: 12px 0; }
.order-item-desc { margin-bottom: 8px; }
.order-item-btns { display: flex; gap: 8px; }
.order-item-btns .btn { width: auto; padding: 7px 14px; font-size: .72rem; }

.photo-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center;
  padding: 30px 20px; z-index: 60;
}
.photo-modal.hidden { display: none; }
.photo-modal-inner { position: relative; max-width: 92vw; display: flex; flex-direction: column; align-items: center; }
.photo-modal-image {
  max-width: 92vw; max-height: 78vh; display: block; border-radius: var(--radius);
  -webkit-user-select: none; user-select: none;
  -webkit-user-drag: none; user-drag: none;
  -webkit-touch-callout: none;
}
.photo-modal-filename {
  color: var(--paper); font-family: 'IBM Plex Mono', monospace; font-size: .8rem;
  margin-top: 14px; text-align: center; word-break: break-all;
}
.photo-modal-close {
  position: absolute; top: -14px; right: -14px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--safelight); color: var(--ink); border: none; cursor: pointer; font-size: 1.3rem;
  line-height: 1; display: flex; align-items: center; justify-content: center;
}
.photo-modal-close:hover { background: #f0b357; }
.order-total-row { font-weight: 600; border-bottom: none; padding-top: 10px; color: var(--safelight); }
.order-qr { background: var(--paper); padding: 8px; border-radius: var(--radius); line-height: 0; }
.order-qr-note {
  width: 140px; padding: 8px; color: var(--fog); font-size: .72rem; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
}

.badge {
  font-family: 'IBM Plex Mono', monospace; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  padding: 5px 10px; border-radius: 2px; white-space: nowrap;
}
.badge-pending { background: rgba(193,68,45,.15); color: #f2b6a8; border: 1px solid var(--darkroom-red); }
.badge-ready { background: rgba(226,163,59,.12); color: var(--safelight); border: 1px solid var(--safelight); }
.badge-shipped { background: rgba(230,126,34,.14); color: #e67e22; border: 1px solid #e67e22; }
.badge-pickup-ready { background: rgba(63,143,95,.12); color: var(--success-green); border: 1px solid var(--success-green); }
.badge-done { background: rgba(138,135,120,.15); color: var(--fog); border: 1px solid var(--line); }

.buy-bar {
  position: sticky; bottom: 0; background: var(--ink-soft); border-top: 1px solid var(--line);
  padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.buy-bar.hidden { display: none; }

/* Format picker on each photo card */
.format-picker { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.format-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 6px 0; font-size: .85rem; }
.format-label { color: var(--paper); }
.format-price { color: var(--fog); font-family: 'IBM Plex Mono', monospace; font-size: .8rem; }
.qty-stepper { display: flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); background: var(--ink);
  color: var(--paper); cursor: pointer; font-size: .9rem; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.qty-btn:hover { border-color: var(--safelight); color: var(--safelight); }
.qty-value { min-width: 16px; text-align: center; font-family: 'IBM Plex Mono', monospace; }

/* Cart modal */
.cart-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.cart-modal.hidden { display: none; }
.cart-modal-inner {
  background: var(--ink-soft); border: 1px solid var(--line); border-radius: var(--radius);
  max-width: 480px; width: 100%; max-height: 80vh; display: flex; flex-direction: column; padding: 24px;
  overflow: hidden;
}
.cart-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-shrink: 0; }
.cart-modal-scroll { overflow-y: auto; flex: 1; min-height: 0; }
#cart-items { margin-bottom: 16px; }
.cart-line { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.remove-line-btn { background: none; border: none; color: var(--darkroom-red); cursor: pointer; font-size: 1rem; margin-left: 8px; }
.cart-modal-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; flex-shrink: 0; }

.payment-option {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: .88rem; color: var(--paper); cursor: pointer;
}
.payment-option input[type="radio"] { width: 17px; height: 17px; accent-color: var(--safelight); }

.photo-modal-inner { max-width: 720px; }
#photo-modal-img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: var(--radius); }

/* Admin */
.pricing-row {
  display: flex; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.pricing-toggle { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; }
.pricing-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--safelight); }
.pricing-status { font-size: .78rem; color: var(--fog); font-family: 'IBM Plex Mono', monospace; min-width: 140px; text-align: right; }

.upload-zone {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 30px; text-align: center;
  margin: 24px 0; background: var(--ink-soft);
}

.progress-bar-track {
  width: 100%; height: 8px; background: var(--ink); border-radius: 4px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; width: 0%; background: var(--safelight); border-radius: 4px;
  transition: width .2s ease;
}
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 24px 0; }
.stat-box { background: var(--ink-soft); border: 1px solid var(--line); padding: 16px; border-radius: var(--radius); }
.stat-box .num { font-family: 'Fraunces', serif; font-size: 1.8rem; color: var(--safelight); }
.stat-box .label { font-size: .78rem; color: var(--fog); font-family: 'IBM Plex Mono', monospace; }

table.admin-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .88rem; }
table.admin-table th, table.admin-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.admin-table th { color: var(--fog); font-weight: 500; font-family: 'IBM Plex Mono', monospace; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
table.admin-table .thumb-img { width: 44px; height: 44px; object-fit: cover; border-radius: 2px; background: var(--ink); display: block; }
table.admin-table input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--safelight); }

.order-thumb-list { display: flex; flex-direction: column; gap: 8px; }
.order-thumb-chip { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.order-thumb-img { width: 36px; height: 36px; object-fit: cover; border-radius: 2px; background: var(--ink); flex-shrink: 0; }

.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; padding-bottom: 60px; }
.user-card { background: var(--ink-soft); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.user-card-photo { aspect-ratio: 1/1; background: var(--ink); display: flex; align-items: center; justify-content: center; }
.user-card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-card-noselfie { color: var(--fog); font-size: .78rem; font-family: 'IBM Plex Mono', monospace; }
.user-card-body { padding: 14px; }
.user-card-name { font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-card-meta { color: var(--fog); font-size: .8rem; margin-bottom: 6px; word-break: break-word; }
.user-card-code { font-family: 'IBM Plex Mono', monospace; color: var(--safelight); font-size: .78rem; margin-bottom: 4px; }
.user-card-date { color: var(--fog); font-size: .72rem; font-family: 'IBM Plex Mono', monospace; }

@media (max-width: 640px) {
  .auth-card { padding: 24px; }
  .hero-row { margin-top: 24px; }

  .topbar {
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 14px 16px;
  }
  .topbar nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .topbar nav a, .topbar nav button { margin-left: 0; }
  #welcome { font-size: .78rem; }

  .wrap { padding: 0 16px; }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding-bottom: 90px;
  }
  .photo-card .readout, .photo-card .owned-tag { font-size: .6rem; padding: 2px 5px; }

  .format-picker { padding-top: 8px; }
  .format-row {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: 6px; padding: 12px 0; font-size: 1rem;
  }
  .format-row .format-label { font-size: 1.05rem; font-weight: 600; }
  .format-row .format-price { font-size: 1.05rem; font-weight: 600; color: var(--paper); }
  .format-row .qty-stepper { justify-content: center; }
  .qty-value { font-size: 1.2rem; min-width: 26px; }
  .qty-btn { width: 34px; height: 34px; font-size: 1.2rem; }
  .format-row:not(:last-of-type) { border-bottom: 1px solid var(--line); }

  .buy-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px;
  }
  .buy-bar > div:last-child { display: flex; gap: 8px; }
  .buy-bar > div:last-child .btn { flex: 1; }

  .cart-modal { padding: 0; align-items: flex-end; }
  .cart-modal-inner { max-width: 100%; max-height: 85vh; border-radius: var(--radius) var(--radius) 0 0; }

  .stat-row { grid-template-columns: repeat(2, 1fr); }

  table.admin-table { font-size: .78rem; }
  table.admin-table th, table.admin-table td { padding: 8px 4px; }

  .pricing-row { flex-wrap: wrap; gap: 8px; }
  .pricing-toggle { flex: 1 1 100%; }
  .pricing-status { text-align: left; min-width: 0; }

  .code-search-row { flex-direction: column; }
  .code-search-row .btn { width: 100%; }

  .order-card-body { grid-template-columns: 1fr; }
  .order-qr { justify-self: center; }
}

@media (max-width: 380px) {
  .gallery-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-row { grid-template-columns: 1fr 1fr; }
}

#print-label { display: none; }

@media print {
  body > *:not(#print-label) { display: none !important; }
  #print-label {
    display: flex !important; flex-direction: row; align-items: center; justify-content: space-between;
    position: static;
    width: 50mm; height: 30mm; padding: 2mm; box-sizing: border-box; margin: 0;
    background: #fff; color: #000; font-family: Arial, Helvetica, sans-serif;
  }
  #pl-left { flex: 1; min-width: 0; padding-right: 2mm; }
  #pl-order { font-size: 9pt; font-weight: 700; margin-bottom: 1mm; word-break: break-word; }
  #pl-name { font-size: 7.5pt; font-weight: 700; word-break: break-word; }
  #pl-phone { font-size: 7.5pt; }
  #pl-address { font-size: 6.5pt; line-height: 1.2; margin-top: 1mm; word-break: break-word; }
  #pl-right { flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
  #pl-qr { width: 13mm; height: 13mm; }
  #pl-qr img, #pl-qr canvas { width: 100%; height: 100%; }
  @page { size: 50mm 30mm; margin: 0; }
}
