@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-semibold.woff2") format("woff2");
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --primary: #0f1527;
  --primary-hover: #1e293b;
  --canvas: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e5e7eb;
  --border-soft: #eef2f7;
  --text: #334155;
  --heading: #0f172a;
  --muted: #64748b;
  --subtle: #94a3b8;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 8px 24px rgb(15 23 42 / 0.04);
  --green-bg: #d1fae5;
  --green: #067647;
  --yellow-bg: #fef3c7;
  --yellow: #92400e;
  --red-bg: #fee2e2;
  --red: #b42318;
  --blue-bg: #e0e7ff;
  --blue: #3730a3;
}

html.dark {
  color-scheme: dark;
  --canvas: #0f172a;
  --surface: #1e293b;
  --surface-soft: #243247;
  --surface-hover: #334155;
  --border: #475569;
  --border-soft: #334155;
  --text: #cbd5e1;
  --heading: #f8fafc;
  --muted: #94a3b8;
  --subtle: #64748b;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.18), 0 10px 28px rgb(0 0 0 / 0.14);
  --green-bg: rgb(6 95 70 / 0.34);
  --green: #6ee7b7;
  --yellow-bg: rgb(146 64 14 / 0.35);
  --yellow: #fcd34d;
  --red-bg: rgb(153 27 27 / 0.34);
  --red: #fca5a5;
  --blue-bg: rgb(55 48 163 / 0.38);
  --blue: #c7d2fe;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgb(99 102 241 / 0.32);
  outline-offset: 2px;
}

.app-shell { display: flex; min-height: 100%; }
.sidebar {
  width: 288px;
  height: 100vh;
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 40;
  transition: transform .25s ease, background .2s ease;
}
.brand {
  height: 80px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--heading);
  white-space: nowrap;
}
.brand-word { font-size: 24px; font-weight: 800; letter-spacing: -.045em; }
.brand-section { font-size: 22px; font-weight: 750; letter-spacing: -.035em; }
.nav-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px 24px; }
.nav-group + .nav-group { margin-top: 26px; }
.nav-label {
  margin: 0 12px 10px;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.nav-link {
  min-height: 48px;
  margin: 3px 0;
  padding: 0 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-weight: 550;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-link:hover { background: var(--surface-hover); color: var(--heading); }
.nav-link.active { background: #f3f4f6; color: var(--heading); font-weight: 650; box-shadow: none; }
.dark .nav-link.active { background: var(--surface-hover); color: var(--heading); }
.nav-link svg { width: 19px; height: 19px; flex: 0 0 auto; }
.sidebar-footer { border-top: 1px solid var(--border-soft); padding: 16px; background: color-mix(in srgb, var(--surface-soft) 55%, transparent); }
.user-row { display: flex; align-items: center; gap: 12px; padding: 0 0 16px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-hover); color: var(--heading); display: grid; place-items: center; font-weight: 700; }
.user-name { color: var(--heading); font-size: 13px; font-weight: 650; }
.footer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.footer-actions .btn { min-height: 40px; padding: 0 12px; border-radius: 8px; font-weight: 550; }

.app-main { min-width: 0; flex: 1; height: 100vh; display: flex; flex-direction: column; position: relative; }
.mobile-header { display: none; }
.content { flex: 1; min-height: 0; overflow-y: auto; padding: 40px; display: flex; flex-direction: column; }
.page { width: 100%; min-height: 100%; margin: 0 auto; display: flex; flex: 1; flex-direction: column; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.page h1 { color: var(--heading); margin: 0; font-size: 30px; line-height: 1.2; font-weight: 750; letter-spacing: -.035em; }
.subtitle { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.context-badge { display: inline-flex; padding: 5px 11px; border-radius: 999px; background: rgb(15 21 39 / .08); color: var(--primary); font-size: 10px; font-weight: 750; letter-spacing: 0; }
.dark .context-badge { background: var(--surface-hover); color: var(--heading); }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.btn {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0 24px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 8px 20px rgb(15 21 39 / .15); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-excel { background: #206c3c; border-color: #206c3c; color: #fff; box-shadow: 0 8px 18px rgb(32 108 60 / .18); }
.btn-excel:hover:not(:disabled) { background: #19552d; }
.btn-danger { background: var(--red-bg); border-color: transparent; color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.tabs { display: flex; gap: 32px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 24px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 16px 2px; margin-bottom: -1px; color: var(--muted); cursor: pointer; font-weight: 550; }
.tab:hover { color: var(--heading); }
.tab.active { border-bottom-color: var(--heading); color: var(--heading); }
.counter { min-width: 25px; padding: 3px 7px; border-radius: 999px; margin-left: 7px; background: var(--surface-hover); color: var(--muted); font-size: 11px; font-weight: 700; }
.counter.pending { background: var(--yellow-bg); color: var(--yellow); }
.counter.error, .counter.cancelled { background: var(--red-bg); color: var(--red); }
.counter.sent, .counter.issued { background: var(--green-bg); color: var(--green); }

.toolbar {
  min-height: 56px;
  margin-bottom: 24px;
  padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.search-wrap { position: relative; width: min(448px, 100%); margin-left: 8px; }
.search-wrap label { display: block; }
.search-wrap svg { position: absolute; top: 50%; left: 12px; width: 16px; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.search {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 40px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--heading);
}
.search:hover, .search:focus { border-color: var(--border); background: var(--surface-soft); }
.reference { display: flex; align-items: center; gap: 12px; padding-left: 16px; margin-right: 4px; border-left: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.reference strong { font-size: 14px; font-weight: 550; }
.select { height: 38px; border: 1px solid var(--border); border-radius: 9px; padding: 0 31px 0 11px; background: var(--surface-soft); color: var(--text); }

.table-card { border: 1px solid var(--border-soft); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; display: flex; flex: 1; min-height: 400px; flex-direction: column; }
.table-scroll { width: 100%; flex: 1; min-height: 0; overflow: auto; }
table { width: 100%; min-width: 960px; border-collapse: collapse; }
.orders-table { min-width: 1120px; }
th { padding: 12px 24px; background: var(--surface-soft); color: var(--muted); border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 750; letter-spacing: .055em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { height: 58px; padding: 10px 24px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: var(--surface-soft); }
tbody tr.selected { background: var(--blue-bg); }
.sort-btn { border: 0; padding: 0; background: transparent; color: inherit; display: inline-flex; align-items: center; gap: 6px; text-transform: inherit; letter-spacing: inherit; font-weight: inherit; cursor: pointer; }
.text-right { text-align: right; }
.text-center { text-align: center; }
th.text-right .sort-btn { width: 100%; justify-content: flex-end; }
.header-unit { text-transform: none; letter-spacing: 0; }
.sort-btn svg { width: 13px; height: 13px; color: var(--subtle); }
.cell-primary { color: var(--heading); font-weight: 650; }
.cell-secondary { margin-top: 3px; color: var(--muted); font-size: 11px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.status { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-pendente { background: var(--yellow-bg); color: var(--yellow); }
.status-enviada, .status-emitida, .status-ativo, .status-ativa { background: var(--green-bg); color: var(--green); }
.status-erro, .status-cancelada { background: var(--red-bg); color: var(--red); }
.status-inativo, .status-inativa { background: var(--surface-hover); color: var(--muted); }
.check { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.table-action { border: 0; border-radius: 8px; width: 34px; height: 34px; background: transparent; color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; }
.table-action:hover { background: var(--surface-hover); color: var(--heading); }
.table-action.danger:hover { background: var(--red-bg); color: var(--red); }
.table-action svg { width: 16px; height: 16px; }

.empty-row td { height: 264px; text-align: center; }
.empty { max-width: 380px; margin: auto; display: flex; flex-direction: column; align-items: center; }
.empty-icon { width: 58px; height: 58px; border-radius: 50%; background: var(--surface-hover); color: var(--subtle); display: grid; place-items: center; margin-bottom: 14px; }
.empty-icon svg { width: 26px; height: 26px; }
.empty h2 { margin: 0 0 5px; color: var(--heading); font-size: 16px; }
.empty p { margin: 0; color: var(--muted); font-size: 13px; }
.table-footer { min-height: 58px; padding: 12px 24px; border-top: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 13px; }
.selection-summary { display: flex; align-items: center; gap: 9px; }
.pagination { display: flex; align-items: center; gap: 4px; }
.page-btn { min-width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; }
.page-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--heading); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn svg { width: 15px; height: 15px; }

.selection-bar { position: absolute; left: 50%; bottom: 24px; z-index: 28; transform: translateX(-50%); display: flex; align-items: center; gap: 16px; padding: 8px 16px 8px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); box-shadow: 0 18px 48px rgb(15 23 42 / .22); }
.selection-bar[hidden] { display: none; }
.selection-icon { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; }
.selection-icon svg { width: 20px; height: 20px; }
.selection-copy { min-width: 165px; padding-right: 16px; border-right: 1px solid var(--border); display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 5px; }
.selection-copy > span { grid-column: 1 / -1; color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.selection-copy strong { color: var(--heading); font-size: 15px; }
.selection-copy small { color: var(--muted); font-size: 12px; }
.selection-send { min-height: 42px; padding: 0 20px; border-radius: 999px; border-color: #067647; background: #067647; color: #fff; }
.selection-send:hover:not(:disabled) { background: #065f46; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 30; background: rgb(15 23 42 / .55); backdrop-filter: blur(2px); }
.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 18px; background: rgb(15 23 42 / .58); backdrop-filter: blur(5px); display: grid; place-items: center; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(384px, 100%); border: 1px solid var(--border); border-radius: 24px; background: var(--surface); box-shadow: 0 24px 60px rgb(2 6 23 / .28); padding: 32px 32px 0; text-align: center; overflow: hidden; animation: modal-in .2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 24px; background: var(--blue-bg); color: var(--blue); display: grid; place-items: center; }
.modal-icon svg { width: 30px; height: 30px; }
.modal h2 { margin: 0; color: var(--heading); font-size: 20px; font-weight: 700; letter-spacing: -.025em; }
.modal p { margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin: 28px -32px 0; padding: 24px; border-top: 1px solid var(--border-soft); background: var(--surface-soft); }
.modal-actions .btn { flex: 1; }

.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; }
.custom-scrollbar { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.dark .custom-scrollbar { scrollbar-color: #475569 transparent; }

@media (max-width: 1100px) {
  .content { padding: 32px 28px 24px; }
  .page-head { align-items: flex-start; }
  .reference strong { display: none; }
}

@media (max-width: 767px) {
  body { overflow: hidden; }
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-101%); box-shadow: 20px 0 50px rgb(2 6 23 / .22); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .app-main { width: 100%; }
  .mobile-header { height: 64px; flex: 0 0 auto; padding: 0 15px; border-bottom: 1px solid var(--border-soft); background: var(--surface); display: flex; align-items: center; justify-content: space-between; }
  .mobile-title { color: var(--heading); font-size: 16px; font-weight: 700; }
  .content { padding: 24px 16px 20px; }
  .page { min-height: auto; }
  .page-head { display: block; margin-bottom: 22px; }
  .page h1 { font-size: 25px; }
  .subtitle { line-height: 1.55; }
  .context-badge { padding: 5px 8px; }
  .page-actions { justify-content: flex-start; margin-top: 18px; }
  .page-actions .btn { flex: 1 1 auto; }
  .tabs { gap: 22px; margin-right: -16px; padding-right: 16px; }
  .toolbar { align-items: stretch; flex-direction: column; padding: 10px; }
  .search-wrap { width: 100%; }
  .reference { border-left: 0; border-top: 1px solid var(--border-soft); padding: 10px 0 0; justify-content: flex-end; }
  .reference strong { display: inline; margin-right: auto; }
  .table-card { margin: 0 -1px; }
  .table-footer { align-items: flex-start; flex-direction: column; }
  .pagination { align-self: flex-end; }
  .selection-bar { position: fixed; width: calc(100% - 24px); bottom: 12px; gap: 10px; padding-right: 8px; }
  .selection-copy { min-width: 0; flex: 1; padding-right: 10px; }
  .selection-send { padding: 0 14px; }
  .selection-send svg { display: none; }
  .modal { padding: 28px 24px 0; }
  .modal-actions { margin: 24px -24px 0; }
}

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