:root {
  color-scheme: light;
  --primary: #c2540e;
  --primary-dark: #9a4108;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --text: #1f2430;
  --text-secondary: #6b7280;
  --text-table: #64748b;
  --placeholder: #94a3b8;
  --input-border: #e4e1da;
  --focus-ring: 0 0 0 3px rgba(194, 84, 14, 0.12);
  --tint: #f7e8de;
  --tint-neutral: #f1efea;
  --info-text: #1d4ed8;
  --info-bg: #eff6ff;
  --warning-text: #b45309;
  --warning-bg: #fffbeb;
  --danger-text: #b91c1c;
  --danger-bg: #fef2f2;
  --row-hover: #faf9f7;
  font-family: "Ubuntu", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Ubuntu", system-ui, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

::placeholder {
  color: var(--placeholder);
}

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar,
.panel-heading,
.item-main,
.card-actions,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  align-items: flex-end;
}

.topbar h1 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.button {
  border: 1px solid transparent;
  border-radius: 0;
  padding: 9px 16px;
  min-height: 36px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.button.ghost {
  background: #fff;
  color: #475569;
  border-color: var(--input-border);
}

.button.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--primary);
}

.button.danger {
  background: var(--danger-text);
  color: #fff;
}

.button.danger:hover:not(:disabled) {
  background: #991b1b;
}

.button.small {
  min-height: 32px;
  padding: 7px 12px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  padding: 0;
}

.dashboard {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

/* ----------------------------------------------------------------------
   Autenticacao (login / primeiro acesso) -- tema claro, card unico
   ---------------------------------------------------------------------- */

.auth-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-root {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.login-card-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 32px 28px;
}

.login-card-body h2 {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.login-card-body .subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 6px;
}

.login-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-form .form-label {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

.login-form .form-input {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 0;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-form .form-input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.login-error {
  margin: 0;
  border: 1px solid #fecaca;
  border-radius: 0;
  padding: 8px 10px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 12px;
  text-align: center;
}

.btn-submit {
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-submit:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card-footer {
  margin: 4px 0 0;
  color: var(--placeholder);
  font-size: 12px;
  text-align: center;
}

.session-user {
  align-self: center;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

/* ----------------------------------------------------------------------
   Paineis / cards
   ---------------------------------------------------------------------- */

.panel,
.public-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.list-panel {
  min-width: 0;
}

.history-panel {
  margin-top: 22px;
}

.history-table {
  min-width: 900px;
}

.form-panel {
  position: sticky;
  top: 18px;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 0;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea {
  resize: vertical;
}

.form-actions {
  margin-top: 18px;
}

.search {
  min-width: 260px;
  max-width: 360px;
}

.list-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.sector-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.sector-filter {
  min-height: 30px;
  border: 1px solid var(--input-border);
  border-radius: 0;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.sector-filter:hover,
.sector-filter.active {
  border-color: var(--primary);
  background: var(--tint);
  color: var(--primary-dark);
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.detail-grid {
  grid-template-columns: minmax(320px, 560px);
  justify-content: center;
}

.table-section {
  margin-top: 20px;
}

.table-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.table-heading h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
}

.control-table {
  width: 100%;
  min-width: 1160px;
  border-collapse: collapse;
  font-size: 13px;
}

.control-table th,
.control-table td {
  padding: 12px 13px;
  text-align: left;
  vertical-align: middle;
}

.control-table th {
  border-bottom: 1px solid var(--input-border);
  color: var(--text-table);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.control-table td {
  border-bottom: 1px solid #f1f5f9;
}

.control-table tr:last-child td {
  border-bottom: 0;
}

.product-row {
  cursor: pointer;
}

.product-row:hover td {
  background: var(--row-hover);
}

.recipient-cell {
  color: var(--primary-dark);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Badges de status: unica excecao ao radius zero do app */
.table-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.table-status.expired {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.table-status.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.item-card {
  display: grid;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.item-main {
  align-items: flex-start;
}

.item-main > div {
  min-width: 0;
}

.item-card h3 {
  display: block;
  margin: 8px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  margin: 0;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-pill.expired {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.status-pill.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.qr-code {
  flex: 0 0 auto;
  width: 132px;
  height: 132px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  image-rendering: pixelated;
}

.print-label {
  display: none;
}

dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.item-card dl div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--tint-neutral);
}

dt {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.card-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 2px;
}

.empty-state {
  margin-top: 18px;
  padding: 28px;
  border: 1px dashed var(--input-border);
  border-radius: 0;
  color: var(--text-secondary);
  text-align: center;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* ----------------------------------------------------------------------
   Consulta publica (standalone, sem chrome do app)
   ---------------------------------------------------------------------- */

.public-view {
  max-width: 780px;
  margin: 0 auto;
}

.view-only-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.public-card {
  width: 100%;
  max-width: 420px;
  padding: 28px;
}

.public-card .eyebrow {
  text-align: center;
}

.public-card h2 {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

.details-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.details-grid dt {
  font-size: 11px;
}

.details-grid dd {
  font-size: 13px;
}

.notes {
  margin: 20px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 0;
  background: transparent;
  padding: 0;
}

.back-link:hover {
  color: var(--primary);
}

@media (max-width: 820px) {
  .topbar,
  .dashboard,
  .panel-heading,
  .item-main {
    display: grid;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .search {
    min-width: 0;
    max-width: none;
  }

  .list-tools,
  .topbar-actions {
    justify-content: stretch;
  }

  .list-tools > *,
  .topbar-actions > * {
    width: 100%;
  }

  dl {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .item-main {
    justify-items: start;
  }

  .qr-code {
    width: 148px;
    height: 148px;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .topbar,
  .form-panel,
  .panel-heading,
  .search,
  .table-section,
  .empty-state,
  .status-pill,
  .item-card h3,
  .item-card dl,
  .card-actions,
  .back-link {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .dashboard {
    display: block;
  }

  .list-panel {
    border: 0;
    padding: 0;
  }

  .items-grid {
    display: grid;
    grid-template-columns: repeat(4, 38mm);
    gap: 8mm;
    margin: 0;
  }

  .item-card,
  .item-main {
    display: block;
  }

  .item-card {
    width: 38mm;
    min-height: 38mm;
    padding: 0;
    border: 0;
    background: #fff;
  }

  .panel,
  .public-card,
  .item-card {
    box-shadow: none;
    break-inside: avoid;
  }

  .print-selected .item-card {
    display: none;
  }

  .print-selected .item-card.print-target {
    display: block;
  }

  .qr-code {
    display: block;
    width: 38mm;
    height: 38mm;
    border: 0;
    border-radius: 0;
  }

  .print-all .item-card {
    min-height: 47mm;
  }

  .print-all .print-label {
    display: block;
    width: 38mm;
    margin: 2mm 0 0;
    color: #000;
    font-size: 8pt;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .print-selected .print-label {
    display: none;
  }
}
