:root {
  --color-red: #E2231A;
  --color-blue: #1B3A8C;
  --color-dark: #20242c;
  --color-bg: #f4f6fb;
  --color-card: #ffffff;
  --color-border: #e0e4ec;
  --color-text: #2b2f38;
  --color-muted: #6b7280;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(20, 30, 60, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

.topbar {
  background: var(--color-card);
  border-bottom: 4px solid var(--color-blue);
  border-image: linear-gradient(90deg, var(--color-blue), var(--color-red)) 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  box-shadow: var(--shadow);
}

.topbar img.logo {
  height: 42px;
  width: 42px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  color: var(--color-dark);
}

.topbar .brand-sub {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 2px;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 26px;
  margin-bottom: 22px;
  border: 1px solid var(--color-border);
}

.card h2 {
  margin-top: 0;
  font-size: 1.05rem;
  color: var(--color-blue);
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 10px;
  margin-bottom: 18px;
}

.intro {
  text-align: center;
}

.intro h2 {
  border: none;
  color: var(--color-dark);
}

.intro p {
  color: var(--color-muted);
  line-height: 1.5;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

@media (max-width: 620px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-dark);
}

label .opt {
  font-weight: 400;
  color: var(--color-muted);
  font-size: 0.78rem;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(27, 58, 140, 0.12);
}

input.invalid, select.invalid, textarea.invalid {
  border-color: var(--color-red);
  box-shadow: 0 0 0 3px rgba(226, 35, 26, 0.10);
}

.field-error {
  color: var(--color-red);
  font-size: 0.78rem;
  margin-top: 4px;
  min-height: 1em;
}

.field-hint {
  color: var(--color-muted);
  font-size: 0.78rem;
  margin-top: 4px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}

.btn:active {
  transform: scale(0.99);
}

.btn-primary {
  background: linear-gradient(90deg, var(--color-blue), var(--color-red));
  color: #fff;
  width: 100%;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: #fff;
  color: var(--color-blue);
  border: 1px solid var(--color-blue);
}

.btn-danger {
  background: #fff;
  color: var(--color-red);
  border: 1px solid var(--color-red);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
}

#feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

#feedback.success {
  display: block;
  background: #e7f7ec;
  color: #1d7a3c;
  border: 1px solid #b9e6c6;
}

#feedback.error {
  display: block;
  background: #fdecea;
  color: var(--color-red);
  border: 1px solid #f7c4bf;
}

footer {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.78rem;
  padding: 10px 0 30px;
}

/* Admin */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 70px);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data-table th, table.data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

table.data-table th {
  color: var(--color-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-pendente {
  background: #fff4e5;
  color: #b56a00;
}

.badge-emitida {
  background: #e7f7ec;
  color: #1d7a3c;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  gap: 8px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 60, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h3 {
  margin-top: 0;
  color: var(--color-blue);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 18px;
  font-size: 0.9rem;
  margin-bottom: 18px;
}

.detail-grid .full {
  grid-column: 1 / -1;
}

.detail-grid dt {
  color: var(--color-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}

.detail-grid dd {
  margin: 0;
  font-weight: 500;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
}

.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: 30px 0;
}

.success-check {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: #e7f7ec;
  color: #1d7a3c;
  font-size: 34px;
  line-height: 64px;
  text-align: center;
  font-weight: 700;
}

.success-modal-note {
  font-size: 0.85rem;
}

/* Nav — estilo tab segmentado */
.admin-nav {
  display: inline-flex;
  background: #fff;
  border-radius: 12px;
  padding: 5px;
  gap: 4px;
  margin-bottom: 24px;
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}

.admin-nav a {
  padding: 9px 20px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-muted);
  background: transparent;
  border: none;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color .15s, background .15s;
  white-space: nowrap;
}

.admin-nav a:hover {
  color: var(--color-blue);
  background: var(--color-bg);
  border-color: transparent;
  box-shadow: none;
  transform: none;
}

.admin-nav a.active {
  background: linear-gradient(135deg, var(--color-blue), var(--color-red));
  color: #fff !important;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(27,58,140,0.3);
}

.link-text {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--color-muted);
  word-break: break-all;
}

.spinner {
  border: 3px solid var(--color-border);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Badges extras ── */
.badge-cancelada {
  background: #fdecea;
  color: var(--color-red);
}

/* Código do cliente (ex: C001) */
.client-code {
  display: inline-block;
  background: var(--color-blue);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  margin-top: 3px;
}

/* ── Tabela zebrada (todas as tabelas do sistema) ── */
table.data-table tbody tr:nth-child(odd) {
  background: #ffffff;
}
table.data-table tbody tr:nth-child(even) {
  background: #f4f7fb;
}
table.data-table tbody tr:hover {
  background: #e8eef8 !important;
}

/* ── Barra de filtro de período (Relatórios) ── */
.period-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 14px 20px;
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.period-bar label {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0;
  color: var(--color-muted);
}

.period-bar input[type="date"],
.period-bar select {
  width: auto;
  padding: 7px 10px;
  font-size: 0.85rem;
}

/* ── BPO: Report Hero ── */
.report-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}

.report-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--color-dark);
  margin: 0 0 4px;
}

.report-subtitle {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin: 0;
}

.report-date-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.82rem;
  color: var(--color-blue);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  white-space: nowrap;
}

/* ── BPO: KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 920px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 580px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px 16px;
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  position: relative;
  overflow: hidden;
  text-align: center;
  transition: box-shadow .2s, transform .2s;
}

.kpi-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.09);
  transform: translateY(-2px);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  border-radius: 12px 12px 0 0;
}

.kpi-total::before    { background: var(--color-blue); }
.kpi-emitidas::before { background: #1d7a3c; }
.kpi-pendentes::before { background: #b56a00; }
.kpi-canceladas::before { background: var(--color-red); }
.kpi-valor::before { background: linear-gradient(90deg, var(--color-blue), var(--color-red)); }

.kpi-icon-wrap {
  font-size: 1.7rem;
  margin-bottom: 10px;
  display: block;
  line-height: 1;
}

.kpi-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--color-dark);
  line-height: 1;
  margin-bottom: 8px;
  display: block;
}

.kpi-label {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  font-weight: 700;
  display: block;
  margin-bottom: 3px;
}

.kpi-sub {
  font-size: 0.68rem;
  color: var(--color-muted);
  display: block;
}

.card-sub {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin: 4px 0 0;
  font-weight: 400;
}

/* Progress bar de taxa de emissão */
.kpi-bar-wrap {
  margin-top: 10px;
  height: 4px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
}
.kpi-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: #1d7a3c;
  transition: width .6s ease;
}
