* { box-sizing: border-box; }
:root {
  --navy: #003575;
  --navy-deep: #002756;
  --cream: #FFF8D6;
  --blue-soft: #BFE3F2;
  --green: #A6D77A;
  --green-deep: #7DB94C;
  --red: #DC2626;
  --red-soft: #FEF2F2;
  --ink: #0B2545;
  --ink-soft: rgba(11,37,69,.65);
  --line: rgba(11,37,69,.12);
  --bg: #F7F7F2;
}
html, body { margin:0; padding:0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }

.hidden { display: none !important; }

/* PIN screen */
.pin-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--cream), var(--blue-soft));
}
.pin-card {
  background: #fff;
  border-radius: 24px;
  padding: 40px 32px;
  box-shadow: 0 20px 60px rgba(0,53,117,.18);
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.pin-card .icon { font-size: 48px; display: block; margin-bottom: 12px; }
.pin-card h1 { color: var(--navy); margin: 0 0 6px; font-size: 26px; }
.pin-card p { color: var(--ink-soft); margin: 0 0 20px; }
.pin-card input {
  width: 100%;
  font-size: 22px;
  text-align: center;
  letter-spacing: 8px;
  padding: 14px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
  font-family: monospace;
}
.pin-card input:focus { outline: 0; border-color: var(--navy); box-shadow: 0 0 0 4px rgba(191,227,242,.5); }
.pin-error {
  color: var(--red);
  font-size: 14px;
  min-height: 20px;
  margin-bottom: 12px;
}
.pin-card button {
  width: 100%;
  padding: 14px;
  background: var(--navy);
  color: #fff;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  transition: background .15s;
}
.pin-card button:hover:not(:disabled) { background: var(--navy-deep); }
.pin-card button:disabled { opacity: .5; cursor: not-allowed; }

/* Painel */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  margin: 0;
  color: var(--navy);
}
.app-title .icon { font-size: 26px; }
.app-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn-secondary:hover { border-color: var(--navy); }
.btn-primary {
  background: var(--navy);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--navy-deep); }
.btn-logout {
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: underline;
  padding: 6px 8px;
}

/* Stats cards */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,53,117,.08); }
.stat-card.is-active {
  border-color: var(--navy);
  background: linear-gradient(0deg, rgba(191,227,242,.4), rgba(191,227,242,.4)), #fff;
}
.stat-card__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.stat-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}
.stat-card__hint {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.stat-card--accent .stat-card__value { color: var(--green-deep); }
.stat-card--danger .stat-card__value { color: var(--red); }
.stat-card--receipt .stat-card__value { color: #0E9F6E; }
.stat-card--pending .stat-card__value { color: #B45309; }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.toolbar__search {
  flex: 1;
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: #fafafa;
}
.toolbar__search input {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 14px;
  outline: 0;
  font-family: inherit;
  color: var(--ink);
}
.toolbar__filter-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-right: 4px;
}
.toolbar__chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  transition: all .15s;
}
.chip:hover { border-color: var(--navy); }
.chip.is-active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* Table */
.table-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.table-status {
  padding: 30px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}
.table-scroll {
  overflow-x: auto;
  max-height: 65vh;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead {
  position: sticky;
  top: 0;
  background: #f4f4ee;
  z-index: 1;
}
th {
  text-align: left;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafafa; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge--yes { background: rgba(166,215,122,.25); color: var(--green-deep); }
.badge--no { background: rgba(220,38,38,.12); color: var(--red); }
.badge--dup { background: #FEF3C7; color: #92400E; margin-left: 6px; }

.meta { font-size: 12px; color: var(--ink-soft); }
.unidade-line { margin-top: 3px; font-style: italic; }

.footer-info {
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--ink-soft);
}
.footer-info a { color: var(--navy); text-decoration: underline; }

.col-actions { width: 48px; text-align: right; }
.col-receipt { width: 200px; }

/* Receipt button — press-twice pattern */
.btn-receipt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  color: #0E9F6E;
  border: 1.5px solid #0E9F6E;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-receipt:hover { background: #ECFDF5; }
.btn-receipt.is-arming {
  background: #DC2626;
  color: #fff;
  border-color: #DC2626;
  animation: pulseArm 1s ease-in-out infinite;
}
.btn-receipt.is-done {
  background: #ECFDF5;
  color: #0E9F6E;
  border-color: transparent;
  cursor: default;
}
.btn-receipt.is-done:hover { background: #D1FAE5; cursor: pointer; }
.btn-receipt:disabled { opacity: .5; cursor: not-allowed; }

@keyframes pulseArm {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.receipt-meta {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.btn-delete {
  background: transparent;
  border: 1px solid transparent;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-delete:hover {
  background: rgba(220, 38, 38, .08);
  color: var(--red);
  border-color: rgba(220, 38, 38, .25);
}
.btn-delete:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
.btn-delete:disabled { opacity: .4; cursor: not-allowed; }

@media (max-width: 540px) {
  th.col-id, td.col-id { display: none; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: modalFadeIn .18s ease-out;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 37, 69, 0.55);
  backdrop-filter: blur(2px);
}
.modal__panel {
  position: relative;
  background: #fff;
  border-radius: 18px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,53,117,.3);
  animation: modalSlideUp .25s ease-out;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
}
.modal__title {
  margin: 0;
  font-size: 20px;
  color: var(--navy);
  font-weight: 700;
}
.modal__close {
  background: transparent;
  border: 0;
  font-size: 28px;
  line-height: 1;
  color: var(--ink-soft);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.modal__close:hover { background: rgba(11,37,69,.08); }
.modal__body { padding: 18px 24px 24px; }
.modal__hint {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.modal__error {
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  color: #991B1B;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin: 14px 0;
}
.modal__error.hidden { display: none; }
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.m-field { margin-bottom: 16px; }
.m-field__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.m-field__input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  background: #fafafa;
  font-family: inherit;
  color: var(--ink);
  transition: border-color .15s, background .15s;
}
.m-field__input:focus {
  outline: 0;
  border-color: var(--navy);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(191,227,242,.45);
}

.m-radio-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.m-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  background: #fafafa;
  transition: all .15s;
}
.m-radio:has(input:checked) {
  border-color: var(--navy);
  background: rgba(191,227,242,.3);
}
.m-radio input { margin: 0; }

.m-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  background: #fafafa;
  transition: all .15s;
}
.m-checkbox:has(input:checked) {
  border-color: #0E9F6E;
  background: #ECFDF5;
}
.m-checkbox input { margin: 0; width: 18px; height: 18px; accent-color: #0E9F6E; }

@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.btn-add { color: var(--green-deep); border-color: var(--green-deep); font-weight: 600; }
.btn-add:hover { background: #ECFDF5; border-color: var(--green-deep); }
