/* =====================================================================
   Label Studio — app styles
   A quiet, warm "print shop" workspace so the colorful labels are the
   loudest thing on screen.
   ===================================================================== */
:root {
  --bg: #F5F1EB;
  --surface: #FFFFFF;
  --surface-2: #FAF7F3;
  --border: #E4DBCF;
  --border-strong: #CFC3B4;
  --text: #22182C;
  --text-2: #5B5065;
  --primary: #4A2877;
  --primary-hover: #3B1F61;
  --primary-soft: #EFE6F9;
  --on-primary: #FFFFFF;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --success: #1E7148;
  --focus: #7B4BE0;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-1: 0 1px 2px rgba(34, 24, 44, .06), 0 1px 1px rgba(34, 24, 44, .04);
  --shadow-2: 0 10px 30px rgba(34, 24, 44, .14), 0 2px 6px rgba(34, 24, 44, .08);

  --font-ui: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-brand: 'Shrikhand', 'Outfit', cursive;

  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;

  --printbar-h: 68px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--primary); color: var(--on-primary);
  padding: 8px 14px; border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: 12px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ---------- icons ---------- */
.icon { width: 18px; height: 18px; flex: none; }
[data-icon] { display: inline-flex; }

/* ---------- brand ---------- */
.brand {
  font-family: var(--font-brand);
  font-size: 22px;
  color: var(--primary);
  letter-spacing: .2px;
  line-height: 1;
}
.brand-lg { font-size: 34px; text-align: center; margin-bottom: 20px; }

/* ---------- boot ---------- */
.boot {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--text-2);
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease,
              color var(--dur-fast) ease, transform var(--dur-fast) ease;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: rgba(74, 40, 119, .07); }
.btn-sm { min-height: 36px; padding: 0 10px; font-size: 14px; gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8F1C13; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover:not(:disabled) { background: var(--danger-soft); }
.btn-link {
  background: none; border: 0; padding: 8px 4px; color: var(--primary);
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px; align-self: center;
}
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-color: rgba(255,255,255,.5); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
.btn-secondary.is-loading::after { border-color: var(--border-strong); border-top-color: var(--primary); }
.icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; border-radius: var(--radius); color: var(--text-2);
}
.icon-btn:hover { background: rgba(74, 40, 119, .07); color: var(--text); }

/* ---------- form controls ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > label, legend, .label-row label { font-weight: 600; font-size: 14px; }
legend { padding: 0; margin-bottom: 8px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.counter { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.req { color: var(--danger); }
.help { font-size: 13px; color: var(--text-2); }
.field-error, .form-error { font-size: 13px; color: var(--danger); font-weight: 500; }
.form-error { background: var(--danger-soft); padding: 10px 12px; border-radius: var(--radius-sm); }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search],
input:not([type]), select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
input:hover, select:hover, textarea:hover { border-color: var(--text-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(123, 75, 224, .25);
}
[aria-invalid="true"] { border-color: var(--danger) !important; }
select { appearance: none; padding-right: 34px; cursor: pointer;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235B5065' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
}
select:disabled { opacity: .5; cursor: not-allowed; }

.input-prefix { position: relative; }
.input-prefix > span {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-2); font-weight: 600;
}
.input-prefix input { padding-left: 26px; font-variant-numeric: tabular-nums; }

.input-suffix { position: relative; }
.input-suffix > span {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-2); font-weight: 600; pointer-events: none;
}
.input-suffix input { padding-right: 34px; font-variant-numeric: tabular-nums; }

.input-affix { position: relative; }
.input-affix input { padding-right: 68px; }
.affix-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-height: 34px; padding: 0 10px; border: 0; background: transparent; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; color: var(--primary);
}
.affix-btn:hover { background: var(--primary-soft); }

.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 36px; font-size: 14px; font-weight: 500; }
.check input, .row-check { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; flex: none; margin: 0; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 28px; box-shadow: var(--shadow-1);
}
.auth-title { font-size: 22px; }

/* ---------- app layout ---------- */
.app { min-height: 100dvh; padding-bottom: calc(var(--printbar-h) + 16px); }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 24px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-email { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.demo-badge {
  font-size: 12.5px; font-weight: 600; color: #6A4A00; background: #FFF3C4;
  border: 1px solid #F0D978; padding: 4px 10px; border-radius: 999px;
}

.workspace {
  display: grid; grid-template-columns: minmax(340px, 1fr) minmax(460px, 1.15fr);
  gap: 20px; padding: 20px 24px; max-width: 1440px; margin: 0 auto; align-items: start;
}
.workspace:focus { outline: none; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); min-width: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 18px; }

/* ---------- products ---------- */
.products { position: sticky; top: 16px; display: flex; flex-direction: column; max-height: calc(100dvh - var(--printbar-h) - 100px); }
.toolbar { display: flex; gap: 8px; padding: 14px 20px 8px; }
.toolbar select { width: auto; flex: none; }
.search { position: relative; flex: 1; min-width: 0; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search input { padding-left: 36px; }

.selectbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 4px 20px 10px; border-bottom: 1px solid var(--border);
}
.selectbar select { width: auto; min-height: 36px; font-size: 14px; }

.product-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.product-row {
  display: flex; align-items: center; gap: 12px; padding: 6px 8px 6px 12px;
  border-radius: var(--radius); border: 1px solid transparent;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.product-row:hover { background: var(--surface-2); }
.product-row.is-active { background: var(--primary-soft); border-color: #D8C6F0; }
.row-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: left;
  background: none; border: 0; padding: 6px 4px; border-radius: var(--radius-sm);
}
.row-thumb { width: 168px; flex: none; line-height: 0; }
.row-thumb svg { width: 100%; height: auto; }
.row-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.row-meta { font-size: 13px; color: var(--text-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2);
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.chip-archived { background: #F1EEE9; }

.empty { padding: 40px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-2); }
.empty-icon .icon { width: 32px; height: 32px; color: var(--border-strong); }

/* ---------- editor ---------- */
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; }
.tabs [role=tab] {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; font-weight: 600; font-size: 14px;
  color: var(--text-2); min-height: 32px;
}
.tabs [role=tab][aria-selected=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.tabs [role=tab]:disabled { opacity: .45; }

.preview-stage {
  padding: 28px 20px 14px; background:
    radial-gradient(circle at 1px 1px, rgba(34,24,44,.09) 1px, transparent 0) 0 0 / 14px 14px,
    var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.preview { width: 4.5in; max-width: 100%; line-height: 0; filter: drop-shadow(0 6px 14px rgba(34,24,44,.12)); }
.preview svg { width: 100%; height: auto; }
.preview-caption { font-size: 12.5px; color: var(--text-2); }
.link-btn {
  background: none; border: 0; padding: 4px 2px; margin: -4px 0; font: inherit; font-weight: 600;
  color: var(--primary); text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.link-btn:hover { text-decoration-thickness: 2px; }
.link-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 3px; }

#details-pane, #history-pane { padding: 20px; }
.editor-form { display: flex; flex-direction: column; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-2 { grid-column: 1 / -1; }

.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.theme-option { position: relative; }
.theme-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.theme-option > input + span {
  display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 6px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: 14px; font-weight: 500;
  background: var(--surface); transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.theme-option:hover > input + span { border-color: var(--text-2); }
.theme-option input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); font-weight: 600; }
.theme-option input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.theme-swatch { width: 22px; height: 14px; border-radius: 4px; flex: none; border: 1.5px solid; position: relative; }
.theme-swatch::after { content: ''; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.colors { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.color-field { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; min-height: 40px; }
.color-field input[type=color] {
  width: 36px; height: 36px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.color-field input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type=color]::-webkit-color-swatch { border: 0; border-radius: 5px; }

.toggles { display: flex; gap: 8px 24px; flex-wrap: wrap; }

.form-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.spacer { flex: 1; }
.secondary-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* history */
.history-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: grid; grid-template-columns: 160px 1fr auto; gap: 14px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
}
.history-item svg { width: 100%; height: auto; display: block; }
.history-meta { font-size: 13px; color: var(--text-2); }
.history-action { font-weight: 600; color: var(--text); font-size: 14px; text-transform: capitalize; }

/* ---------- print bar ---------- */
.printbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; min-height: var(--printbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: rgba(255,255,255,.96); border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(34,24,44,.06);
  backdrop-filter: saturate(1.2) blur(6px);
}
.printbar-info { display: flex; align-items: center; gap: 16px; min-width: 0; flex-wrap: wrap; }
.size-picker { display: flex; align-items: center; gap: 8px; }
.size-picker label { font-weight: 600; font-size: 14px; white-space: nowrap; }
.size-picker select { width: auto; min-width: 11.5rem; min-height: 40px; font-size: 14px; }
.size-fit { min-height: 1.4em; margin-top: 12px; }
.size-fields { margin-top: 16px; }
.print-summary { font-weight: 600; font-variant-numeric: tabular-nums; }
.print-summary .muted { font-weight: 400; }
.printbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- dialogs ---------- */
.dialog {
  border: 0; border-radius: var(--radius-lg); padding: 24px; width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-2); color: var(--text); background: var(--surface);
}
.dialog::backdrop { background: rgba(22, 14, 30, .5); }
.dialog[open] { animation: dialog-in var(--dur) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dialog h2 { font-size: 19px; margin-bottom: 8px; }
.dialog-wide { width: min(980px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); display: none; flex-direction: column; }
.dialog-wide[open] { display: flex; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.sheets {
  margin-top: 14px; overflow-y: auto; background: #E9E4DD; border-radius: var(--radius); padding: 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; flex: 1;
}
.sheet { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.sheet svg { width: 100%; height: auto; background: #fff; box-shadow: var(--shadow-2); }
.sheet p { font-size: 13px; color: var(--text-2); }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; left: 50%; bottom: calc(var(--printbar-h) + 16px); transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-2); font-size: 14px; font-weight: 500; pointer-events: auto;
  animation: toast-in var(--dur) var(--ease-out);
}
.toast-error { background: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity 140ms ease, transform 140ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .products { position: static; max-height: none; }
  .product-list { max-height: 420px; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .user-email { display: none; }
  .demo-badge { order: 3; width: 100%; text-align: center; }
  .workspace { padding: 12px; gap: 12px; }
  .panel-head, #details-pane, #history-pane { padding-left: 16px; padding-right: 16px; }
  .toolbar, .selectbar { padding-left: 16px; padding-right: 16px; }
  .row-thumb { width: 120px; }
  .grid-2 { grid-template-columns: 1fr; }
  .theme-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-item { grid-template-columns: 1fr; }
  .printbar { padding: 10px 12px; flex-direction: column; align-items: stretch; gap: 8px; }
  .printbar-actions { justify-content: stretch; }
  .printbar-info { gap: 6px 12px; }
  .size-picker { width: 100%; }
  .size-picker select { flex: 1; }
  .printbar-actions .btn { flex: 1; padding: 0 10px; }
  #preview-sheets-btn { display: none; }
  .app { padding-bottom: 190px; }
  .toasts { bottom: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- printing ---------- */
.print-root { display: none; }
@page { size: letter portrait; margin: 0; }
@media print {
  html, body { background: #fff !important; margin: 0; padding: 0; }
  body.has-print > *:not(#print-root) { display: none !important; }
  body.has-print .print-root { display: block; }
  .print-page {
    overflow: hidden; /* width/height are set inline: 8.5×11 or 11×8.5 */
    break-after: page; page-break-after: always;
  }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page svg { display: block; width: 100%; height: 100%; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* Hide the "Powered by Netlify" badge Netlify adds on the free plan. */
#nl-badge-frame,
#nl-badge,
#netlify-badge,
.netlify-badge { display: none !important; }
