* { box-sizing: border-box; }

:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #171717;
  background: #f3f4f6;
  font-synthesis: none;
}

html, body { min-height: 100%; }
body { margin: 0; }
button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  background: #111827;
  color: white;
  font-weight: 700;
}
button:hover:not(:disabled) { opacity: .9; }
button:disabled { opacity: .52; cursor: wait; }
button.secondary { background: #e5e7eb; color: #111827; }
button.danger { background: #b91c1c; }
button.link-button {
  background: transparent;
  color: #1d4ed8;
  padding: 4px;
  font-weight: 600;
}
.hidden { display: none !important; }
.fatal-banner { background: #fee2e2; color: #991b1b; padding: 14px; font-weight: 700; }

.auth-screen {
  min-height: 100vh;
  padding: 30px 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #f8fafc, #e5e7eb);
}
.auth-card {
  width: min(430px, 100%);
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, .09);
}
.auth-brand { font-size: 31px; font-weight: 900; letter-spacing: 2px; }
.auth-card h1 { margin: 8px 0 5px; font-size: 25px; }
.auth-card > p { margin: 0 0 22px; color: #6b7280; line-height: 1.45; }
.auth-form { display: grid; gap: 15px; }
.auth-form button[type="submit"] { margin-top: 3px; }
.password-notice {
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #92400e;
  border-radius: 8px;
  padding: 11px;
  font-size: 13px;
  line-height: 1.4;
}
.build-status { margin-top: 18px; font-size: 12px; color: #6b7280; text-align: center; }
.build-status.ok { color: #166534; }
.build-status.error { color: #991b1b; font-weight: 700; }

.topbar {
  background: white;
  border-bottom: 1px solid #d1d5db;
  padding: 17px 28px 13px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-main { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.topbar h1 { margin: 0 0 4px; font-size: 25px; }
.topbar p { margin: 0; color: #6b7280; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.user-summary {
  border-left: 1px solid #d1d5db;
  padding-left: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-badge, .badge {
  border-radius: 999px;
  background: #e5e7eb;
  color: #1f2937;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}
.app-status {
  margin-top: 11px;
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 700;
}
.app-status.ok { background: #dcfce7; color: #166534; }
.app-status.loading { background: #fef3c7; color: #92400e; }
.app-status.error { background: #fee2e2; color: #991b1b; white-space: pre-wrap; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, .82fr) minmax(430px, 1fr);
  gap: 18px;
  padding: 18px;
  align-items: start;
}
.panel {
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
}
.preview-panel { grid-column: 2; grid-row: 1 / span 2; }
.panel h2 { margin: 0 0 14px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}
input, select {
  border: 1px solid #9ca3af;
  border-radius: 7px;
  min-height: 42px;
  padding: 8px 10px;
  background: white;
  color: #111827;
}
input:focus, select:focus { outline: 3px solid #dbeafe; border-color: #2563eb; }
.search-row { display: flex; gap: 8px; margin-top: 8px; }
.search-row input { flex: 1; font-size: 17px; }
.status { min-height: 22px; padding-top: 8px; color: #6b7280; }
.results { display: grid; gap: 8px; margin-top: 6px; }
.result { border: 1px solid #d1d5db; border-radius: 8px; padding: 12px; cursor: pointer; }
.result:hover { background: #f9fafb; border-color: #6b7280; }
.result.selected { border-color: #111827; box-shadow: inset 0 0 0 1px #111827; }
.result strong { display: block; font-size: 16px; margin-bottom: 3px; }
.result small { color: #6b7280; line-height: 1.4; }
.help, .print-note {
  margin-top: 14px;
  padding: 12px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #4b5563;
  font-size: 13px;
  line-height: 1.45;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.span-2 { grid-column: span 2; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.print-controls { display: flex; align-items: end; gap: 9px; }
.print-controls input { width: 75px; }

/* Role controls are hidden in the interface and separately enforced by database RLS. */
body[data-role="printer"] .editor-action,
body[data-role="printer"] .admin-action { display: none !important; }
body[data-role="editor"] .admin-action { display: none !important; }
body[data-role="printer"] .preview-panel { grid-row: 1; }

/* Exact 4 × 6 physical label. The fold remains at 2.5 inches. */
.label-sheet {
  width: 4in;
  height: 6in;
  margin: 16px auto 0;
  background: white;
  box-shadow: 0 0 0 1px #9ca3af;
  overflow: hidden;
  display: grid;
  grid-template-rows: 2.5in 0 3.5in;
  color: #000;
}
.label-top {
  width: 4in;
  height: 2.5in;
  padding: .18in .22in .12in;
  overflow: hidden;
  display: grid;
  grid-template-rows: .42in .52in .29in 1fr;
  row-gap: .05in;
}
.label-brand {
  font-size: 31pt;
  line-height: .95;
  letter-spacing: .5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
}
.label-title {
  font-size: 17pt;
  line-height: 1.08;
  font-weight: 700;
  overflow: hidden;
}
.label-style {
  font-size: 15.5pt;
  line-height: 1.05;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}
.size-barcode-row {
  min-height: 0;
  display: grid;
  grid-template-columns: 1.2in 1fr;
  align-items: start;
  gap: .1in;
}
.size-block {
  height: .66in;
  display: flex;
  align-items: center;
  gap: .08in;
  white-space: nowrap;
}
.size-block .us { font-size: 17pt; font-weight: 700; }
.size-block .size { font-size: 36pt; line-height: 1; font-weight: 400; }
.size-block .width { font-size: 12pt; font-weight: 700; }
.barcode-block {
  height: .66in;
  overflow: visible;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transform: translateY(-.03in);
}
.barcode-block svg { width: 100%; height: .62in; display: block; }
.fold-line { border-top: 2px dashed #000; position: relative; z-index: 2; }
.label-bottom {
  width: 4in;
  height: 3.5in;
  padding: .20in .23in;
  font-size: 11.5pt;
  line-height: 1.35;
  overflow: hidden;
}
.label-bottom p { margin: 0 0 .13in; }

.message {
  margin-top: 13px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}
.message.ok { background: #dcfce7; color: #166534; }
.message.error { background: #fee2e2; color: #991b1b; }
.message.loading { background: #fef3c7; color: #92400e; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(17, 24, 39, .56);
  padding: 24px;
  display: grid;
  place-items: center;
}
.modal-card {
  width: min(980px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: white;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.modal-heading h2 { margin: 0 0 4px; }
.modal-heading p { margin: 0; color: #6b7280; }
.icon-button {
  background: #e5e7eb;
  color: #111827;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 25px;
}
.invite-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr 1.25fr 1.2fr auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f9fafb;
}
.credentials-panel {
  margin-top: 14px;
  border: 1px solid #86efac;
  background: #f0fdf4;
  border-radius: 10px;
  padding: 14px;
}
.credentials-panel > p { margin: 5px 0 12px; color: #166534; font-size: 13px; }
.credential-row {
  display: grid;
  grid-template-columns: 145px 1fr;
  gap: 10px;
  align-items: center;
  margin: 7px 0;
}
.credential-row span { font-size: 12px; color: #4b5563; font-weight: 700; }
.credential-row code {
  display: block;
  overflow-wrap: anywhere;
  background: white;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 8px;
  font-size: 14px;
}
.credentials-panel button { margin-top: 7px; }
.table-wrap { overflow-x: auto; margin-top: 18px; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td {
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  padding: 11px 8px;
  vertical-align: middle;
}
.users-table th { font-size: 12px; text-transform: uppercase; color: #6b7280; }
.users-table td strong { display: block; }
.users-table td small { color: #6b7280; }
.users-table select { min-width: 190px; }
.active-toggle { flex-direction: row; align-items: center; }
.active-toggle input { min-height: auto; width: 20px; height: 20px; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.table-actions button { padding: 8px 10px; font-size: 12px; }

#printArea { display: none; }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 1fr; }
  .preview-panel { grid-column: 1; grid-row: auto; }
  .topbar { position: static; }
  .topbar-main { align-items: flex-start; }
  .invite-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .topbar-main, .panel-heading { align-items: stretch; flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
  .user-summary { border-left: 0; padding-left: 0; }
  .grid, .invite-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1; }
  .preview-panel { overflow-x: auto; }
  .credential-row { grid-template-columns: 1fr; }
}

@page { size: 4in 6in; margin: 0; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; width: 4in; }
  .print-label-page {
    width: 4in;
    height: 6in;
    page-break-after: always;
    break-after: page;
  }
  .print-label-page:last-child { page-break-after: auto; break-after: auto; }
  .print-label-page .label-sheet { margin: 0; box-shadow: none; }
}

/* One-time owner bootstrap page. */
.setup-page { background: #eef1f5; min-height: 100vh; }
.setup-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}
.setup-card {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(17, 24, 39, .12);
  padding: 28px;
}
.setup-card h1 { margin: 8px 0 8px; }
.setup-intro { margin: 0 0 18px; color: #4b5563; line-height: 1.5; }
.setup-health {
  border-radius: 8px;
  padding: 11px 12px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 700;
}
.setup-health.loading { background: #fef3c7; color: #92400e; }
.setup-health.ok { background: #dcfce7; color: #166534; }
.setup-health.error { background: #fee2e2; color: #991b1b; }
.password-rules { color: #6b7280; font-size: 12px; line-height: 1.45; }
.setup-complete {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid #86efac;
  border-radius: 10px;
  background: #f0fdf4;
}
.setup-complete h2 { margin: 0 0 8px; }
.setup-complete ol { padding-left: 22px; line-height: 1.55; }
.button-link {
  display: inline-block;
  border-radius: 8px;
  padding: 11px 16px;
  text-decoration: none;
  background: #111827;
  color: #fff;
  font-weight: 700;
}
.setup-warning {
  margin-top: 18px;
  padding: 12px;
  border-radius: 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.45;
}
