/* ============================================================
   QCOW — Sale & Lot Management
   Design tokens
   ============================================================ */
:root{
  --ink:        #23201b;
  --ink-soft:   #5b5347;
  --paper:      #f6f3ec;
  --paper-dim:  #ece7db;
  --surface:    #ffffff;
  --line:       #ddd6c4;
  --pasture:    #2f4b3c;
  --pasture-dk: #203a2d;
  --tag-gold:   #c08f2c;
  --tag-gold-lt:#f1e2b8;
  --danger:     #a4342a;

  --font-display: 'Zilla Slab', Georgia, serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'IBM Plex Mono', 'Courier New', monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(35,32,27,0.06), 0 8px 24px -12px rgba(35,32,27,0.18);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3{
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 .5em;
  letter-spacing: -0.01em;
}

a{ color: var(--pasture); }

button{ font-family: inherit; }

/* ---------- Layout shells ---------- */
.top-strip{
  padding: 22px 24px 10px;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.top-strip .actions{ display:flex; gap:14px; align-items:center; text-transform:none; letter-spacing:0; font-family: var(--font-body); }
.top-strip .actions a, .top-strip .actions button.link-btn{
  background:none; border:none; cursor:pointer; color: var(--ink-soft); font-size: 13px; text-decoration: underline;
  padding: 0;
}

.center-shell{
  min-height: calc(100vh - 60px);
  display:flex;
  align-items:flex-start;
  justify-content:center;
  padding: 24px;
}

.card{
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
}
.card.wide{ max-width: 620px; }
.card.xwide{ max-width: 880px; }

.card h2.form-title{
  text-align:center;
  font-size: 26px;
  margin-bottom: 28px;
}

/* ---------- Forms ---------- */
label{
  display:block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--ink);
}
.field{ margin-bottom: 20px; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="url"],
select,
textarea{
  width:100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus{
  outline: none;
  border-color: var(--pasture);
  box-shadow: 0 0 0 3px rgba(47,75,60,0.15);
}
.row-3{ display:grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, opacity .12s;
}
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity:.55; cursor:not-allowed; }
.btn-primary{ background: var(--pasture); color:#fff; }
.btn-primary:hover:not(:disabled){ filter: brightness(1.08); }
.btn-block{ width:100%; }
.btn-ghost{ background: transparent; border:1px solid var(--line); color: var(--ink); }
.btn-ghost:hover{ background: var(--paper-dim); }
.btn-sm{ padding: 8px 16px; font-size: 13px; }
.btn-outline-gold{ background: #fff; border: 1.5px solid var(--tag-gold); color:#8a6a20; }
.btn-outline-gold:hover{ background: var(--tag-gold-lt); }

.helper-text{ font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }
.error-text{ font-size: 13px; color: var(--danger); margin-top: 10px; min-height: 1em; }
.success-text{ font-size: 13px; color: var(--pasture); margin-top: 10px; min-height: 1em; }

.form-footer{ text-align:center; margin-top: 20px; font-size: 13.5px; color: var(--ink-soft); }
.form-footer a{ font-weight:600; }

/* ---------- Ear-tag badge (signature element) ---------- */
.tag-badge{
  display:inline-flex;
  align-items:center;
  gap: 6px;
  background: var(--pasture);
  color:#fff;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .03em;
  padding: 4px 10px 4px 12px;
  border-radius: 3px 12px 12px 3px;
  position: relative;
}
.tag-badge::before{
  content:"";
  position:absolute;
  left: 4px; top: 50%;
  width: 4px; height: 4px;
  background: rgba(255,255,255,.85);
  border-radius: 50%;
  transform: translateY(-50%);
}
.tag-badge.gold{ background: var(--tag-gold); }

/* ---------- Sale header / list page ---------- */
.sale-header{
  background: var(--paper-dim);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 26px 28px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.sale-header h1{ font-size: 24px; margin:0; }
.sale-header .sale-meta{ font-size: 13px; color: var(--ink-soft); margin-top: 4px; font-family: var(--font-body); font-weight:400;}

.lot-list{ list-style:none; margin:0; padding:0; }
.lot-row{
  display:flex;
  align-items:center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.lot-row:last-child{ border-bottom:none; }
.lot-main{ flex: 1 1 220px; min-width: 200px; }
.lot-main .lot-name{ font-weight: 700; font-size: 15.5px; }
.lot-main .lot-reg{ font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

.icon-btn{
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 38px; height: 38px;
  display:inline-flex; align-items:center; justify-content:center;
  cursor:pointer;
  color: var(--ink);
  transition: background .12s, border-color .12s;
}
.icon-btn:hover{ background: var(--paper-dim); border-color: var(--pasture); }
.icon-group{ display:flex; gap:8px; }

.media-row{ display:flex; gap:8px; align-items:center; }
.media-row input{ flex:1; }
.media-row .row-remove{
  background: var(--paper); border:1px solid var(--line); border-radius: 50%;
  width: 34px; height: 34px; flex: 0 0 auto; cursor:pointer; color: var(--danger);
  display:flex; align-items:center; justify-content:center; font-size:16px;
}
.media-row .row-remove:hover{ background: var(--paper-dim); }
.media-rows .media-row + .media-row{ margin-top: 10px; }
.link-btn-inline{
  background:none; border:none; color: var(--pasture); font-weight:600; font-size: 13.5px;
  cursor:pointer; padding: 10px 0 0; text-decoration: underline;
}

/* ---------- Media management (inside Edit Lot modal) ---------- */
.media-manage{ margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.media-manage-title{
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-soft);
  margin: 0 0 12px;
}
.media-manage-list{
  display:flex;
  flex-direction:column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}
.media-manage-row{ display:flex; align-items:center; gap:10px; }
.media-thumb{
  width: 48px; height: 48px; flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-dim);
  border: 1px solid var(--line);
  display:flex; align-items:center; justify-content:center;
}
.media-thumb-img, .media-thumb-video{
  width:100%; height:100%;
  object-fit: cover;
  display:block;
}
.media-thumb-fallback{
  width:100%; height:100%;
  display:flex; align-items:center; justify-content:center;
  color: var(--ink-soft);
}
.media-info{ flex:1; min-width:0; display:flex; flex-direction:column; gap:4px; }
.media-label{ font-size: 12px; font-weight:700; color: var(--ink); }
.media-manage-row input{
  flex:1;
  padding: 7px 10px;
  font-size: 12.5px;
}
.media-manage-row .row-remove{ width:30px; height:30px; font-size:15px; flex:0 0 auto; }
.media-manage-row.is-saving input{ opacity:.6; }

.empty-state{
  text-align:center;
  padding: 60px 28px;
  color: var(--ink-soft);
}

/* ---------- Modal ---------- */
.modal-overlay{
  position:fixed; inset:0;
  background: rgba(35,32,27,0.45);
  display:flex; align-items:center; justify-content:center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay[hidden]{ display:none; }
.modal-box{
  background:#fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
  padding: 30px 28px;
  position: relative;
}
.modal-box.wide{ max-width: 480px; }
.modal-close{
  position:absolute; top:14px; right:16px;
  background:none; border:none; cursor:pointer;
  font-size: 20px; color: var(--ink-soft); line-height:1;
}
.modal-box h3{ font-size: 19px; margin-bottom: 18px; }

/* ---------- CSV mapping table ---------- */
.mapping-table{ width:100%; border-collapse: collapse; margin-top: 18px; }
.mapping-table thead th{
  text-align:left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
  background: var(--paper-dim);
  padding: 10px 14px;
}
.mapping-table tbody td{
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.mapping-table tbody td:first-child{ font-weight:600; }

.dropzone{
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 50px 20px;
  text-align:center;
  color: var(--ink-soft);
  cursor:pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag-over, .dropzone:hover{ border-color: var(--pasture); background: var(--paper-dim); }
.dropzone input[type=file]{ display:none; }
.file-chip{
  display:inline-flex; align-items:center; gap:8px;
  background: var(--paper-dim); border:1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; margin-top: 14px;
}

/* ---------- QR page ---------- */
.qr-wrap{ text-align:center; padding: 30px 10px 10px; }
.qr-wrap img{ width: 240px; height: 240px; border-radius: 8px; border:1px solid var(--line); }
.qr-status{ font-weight:600; margin-bottom: 18px; font-family: var(--font-display); font-size:18px;}
.qr-actions{ display:flex; gap: 12px; justify-content:center; margin-top: 20px; }
.qr-url{ font-family: var(--font-mono); font-size:12.5px; color: var(--ink-soft); margin-top:14px; word-break: break-all;}

/* spinner */
.spinner{
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid var(--paper-dim);
  border-top-color: var(--pasture);
  animation: spin .8s linear infinite;
  display:inline-block;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

/* utility */
.mt-24{ margin-top:24px; }
.flex-between{ display:flex; align-items:center; justify-content:space-between; }
.text-center{ text-align:center; }
.stack-gap-16 > * + *{ margin-top:16px; }

@media (max-width: 560px){
  .row-3{ grid-template-columns: 1fr; }
  .card{ padding: 30px 22px; }
  .lot-row{ padding: 16px; }
}