:root {
  color-scheme: light;
  --background: #eef3f4;
  --foreground: #17202a;
  --card: #ffffff;
  --card-foreground: #17202a;
  --popover: #ffffff;
  --popover-foreground: #17202a;
  --primary: #145c54;
  --primary-foreground: #ffffff;
  --primary-subtle: #e1efec;
  --secondary: #d45b37;
  --secondary-foreground: #ffffff;
  --accent: #f2b84b;
  --accent-foreground: #17202a;
  --muted: #f4f7f9;
  --muted-foreground: #64717f;
  --border: #d9e0e7;
  --input: #ffffff;
  --destructive: #b42318;
  --destructive-foreground: #ffffff;
  --success: #18794e;
  --success-background: #ecf8f1;
  --success-border: #b8dfc8;
  --danger-background: #fff0ed;
  --danger-border: #f1c5bc;
  --warning-background: #fff3cf;
  --warning-foreground: #815900;
  --status-positive-background: #dff4ec;
  --status-negative-background: #fde2e2;
  --status-negative-foreground: #9f2d2d;
  --sidebar: #17202a;
  --sidebar-foreground: #ffffff;
  --sidebar-muted: #b7c4ce;
  --sidebar-navigation: #dbe5ea;
  --sidebar-interactive: rgba(255, 255, 255, 0.12);
  --sidebar-interactive-hover: rgba(255, 255, 255, 0.2);
  --overlay: rgba(23, 32, 42, 0.54);
  --login-card: rgba(255, 255, 255, 0.96);
  --login-card-border: rgba(255, 255, 255, 0.48);
  --login-primary-overlay: rgba(20, 92, 84, 0.95);
  --login-secondary-overlay: rgba(212, 91, 55, 0.78);
  --shadow: 0 18px 45px rgba(25, 39, 52, 0.12);
  --shadow-card: 0 8px 22px rgba(25, 39, 52, 0.05);
  --radius: 6px;
  --radius-card: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --background: #11181d;
  --foreground: #edf3f5;
  --card: #182127;
  --card-foreground: #edf3f5;
  --popover: #182127;
  --popover-foreground: #edf3f5;
  --primary: #77c9b9;
  --primary-foreground: #0d2823;
  --primary-subtle: #1d3934;
  --secondary: #e48768;
  --secondary-foreground: #24110c;
  --accent-foreground: #241b08;
  --muted: #202b32;
  --muted-foreground: #aab7c0;
  --border: #33414a;
  --input: #141d22;
  --success: #74d3a2;
  --success-background: #153326;
  --success-border: #285f45;
  --danger-background: #3b201e;
  --danger-border: #6e3731;
  --warning-background: #3a3119;
  --warning-foreground: #f0cf78;
  --status-positive-background: #193a31;
  --status-negative-background: #3b2022;
  --status-negative-foreground: #f0a2a7;
  --sidebar: #0d1418;
  --sidebar-foreground: #f7fafb;
  --sidebar-muted: #aab7c0;
  --sidebar-navigation: #dce7eb;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --shadow-card: 0 8px 22px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

.sr-only {
  border: 0;
  clip: rect(0, 0, 0, 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--foreground);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
label.btn:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 75%, transparent);
  outline-offset: 2px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, var(--login-primary-overlay), var(--login-secondary-overlay)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='520' viewBox='0 0 900 520'%3E%3Crect width='900' height='520' fill='%23eff5f4'/%3E%3Cg fill='none' stroke='%23145c54' stroke-width='2' opacity='.24'%3E%3Cpath d='M45 115h810M45 220h810M45 325h810M45 430h810M150 55v410M315 55v410M480 55v410M645 55v410M810 55v410'/%3E%3C/g%3E%3Cg fill='%23d45b37' opacity='.28'%3E%3Crect x='110' y='90' width='140' height='76' rx='5'/%3E%3Crect x='520' y='270' width='170' height='98' rx='5'/%3E%3C/g%3E%3Cg fill='%23145c54' opacity='.32'%3E%3Crect x='315' y='170' width='120' height='112' rx='5'/%3E%3Crect x='690' y='115' width='92' height='182' rx='5'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.login-card {
  width: min(430px, 100%);
  background: var(--login-card);
  border: 1px solid var(--login-card-border);
  border-radius: var(--radius-card);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1,
.page-title h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.login-card p,
.page-title p {
  color: var(--muted-foreground);
  line-height: 1.5;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  transition: grid-template-columns 300ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 84px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  padding: 22px;
  position: relative;
  transition: transform 300ms ease, width 300ms ease, padding 300ms ease;
  overflow: hidden;
}

.brand {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 42px minmax(0, 1fr) 36px;
  margin-bottom: 26px;
}

.brand-mark {
  align-items: center;
  background: var(--status-positive-background);
  border-radius: var(--radius);
  color: var(--primary);
  display: inline-flex;
  font-size: 13px;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand strong {
  font-size: 19px;
  line-height: 1.05;
  white-space: nowrap;
}

.brand span,
.user-box {
  color: var(--sidebar-muted);
  font-size: 13px;
}

.hint {
  color: var(--muted-foreground);
  font-size: 13px;
}

.sidebar-toggle,
.mobile-menu-btn {
  align-items: center;
  background: var(--sidebar-interactive);
  border-radius: var(--radius);
  color: var(--sidebar-foreground);
  display: inline-flex;
  height: 34px;
  justify-content: center;
  line-height: 1;
  width: 34px;
  transition: background 200ms ease, color 200ms ease, transform 200ms ease;
}

.sidebar-toggle:hover,
.mobile-menu-btn:hover {
  background: var(--sidebar-interactive-hover);
}

.sidebar-toggle svg,
.mobile-menu-btn svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

.mobile-menu-btn {
  background: var(--primary);
  display: none;
  flex: 0 0 auto;
}

.nav-overlay {
  display: none;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 24px minmax(0, 1fr);
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 12px;
  text-align: left;
  color: var(--sidebar-navigation);
  background: transparent;
  transition: background 300ms ease, color 300ms ease, padding 300ms ease;
}

.nav-icon {
  align-items: center;
  color: var(--sidebar-foreground);
  display: inline-flex;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.nav-icon svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 20px;
}

.nav-label,
.brand-copy,
.user-box {
  transition: opacity 200ms ease, visibility 200ms ease;
}

.nav button.active,
.nav button:hover {
  color: var(--sidebar-foreground);
  background: var(--sidebar-interactive);
}

.app-shell.sidebar-collapsed .sidebar {
  padding: 22px 14px;
}

.app-shell.sidebar-collapsed .brand {
  grid-template-columns: 42px;
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .user-box,
.app-shell.sidebar-collapsed .nav-label {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  visibility: hidden;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  bottom: 18px;
  left: 22px;
  position: absolute;
}

.app-shell.sidebar-collapsed .nav button {
  grid-template-columns: 24px;
  justify-items: center;
  justify-content: center;
  padding: 0;
}

.workspace {
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
  transition: padding 300ms ease, width 300ms ease;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.panel {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.wide-panel {
  grid-column: 1 / -1;
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

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

.field {
  display: grid;
  gap: 6px;
}

.form-fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
}

label {
  color: var(--card-foreground);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 40px;
  padding: 8px 10px;
  background: var(--input);
  color: var(--foreground);
}

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

.check-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

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

.btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--primary-foreground);
  background: var(--primary);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn-icon {
  fill: none;
  flex: 0 0 auto;
  height: 17px;
  margin-right: 7px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 17px;
}

.btn.secondary {
  color: var(--primary);
  background: var(--primary-subtle);
}

.btn.warn {
  color: var(--secondary-foreground);
  background: var(--secondary);
}

.btn.danger {
  color: var(--destructive-foreground);
  background: var(--destructive);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.report-workflow-form {
  display: grid;
}

.report-filter-row {
  padding-bottom: 20px;
}

.conciliation-module {
  align-items: center;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px 24px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 20px 0;
}

.conciliation-module h2 {
  margin-bottom: 4px;
}

.conciliation-file-control {
  align-items: center;
  display: flex;
  gap: 10px;
}

.selected-file {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: 9px;
  min-height: 40px;
  min-width: 230px;
  padding: 6px 10px;
}

.selected-file.ready {
  background: var(--success-background);
  border-color: var(--success-border);
}

.selected-file.ready strong,
.selected-file.ready small {
  color: var(--success);
}

.selected-file-icon {
  fill: none;
  flex: 0 0 auto;
  height: 18px;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 18px;
}

.selected-file-copy {
  display: grid;
  min-width: 0;
}

.selected-file-copy strong {
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file-copy small,
.file-empty {
  color: var(--muted-foreground);
  font-size: 12px;
}

.alert {
  border: 1px solid transparent;
  border-radius: var(--radius);
  line-height: 1.45;
  padding: 12px 14px;
}

.alert[hidden] {
  display: none;
}

.alert.success {
  background: var(--success-background);
  border-color: var(--success-border);
  color: var(--success);
}

.alert.error {
  background: var(--danger-background);
  border-color: var(--danger-border);
  color: var(--destructive);
}

.conciliation-alert {
  display: -webkit-box;
  grid-column: 1 / -1;
  max-height: 96px;
  overflow: hidden;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.report-action-footer {
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 18px;
}

.btn.disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}

.report-awaiting {
  border-style: dashed;
  text-align: center;
}

.report-awaiting h2 {
  margin-bottom: 5px;
}

#reportOutput {
  display: grid;
  gap: 18px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.pendente {
  color: var(--warning-foreground);
  background: var(--warning-background);
}

.status-badge.baixado {
  color: var(--primary);
  background: var(--status-positive-background);
}

.status-badge.nao-baixado {
  color: var(--status-negative-foreground);
  background: var(--status-negative-background);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 170px;
}

.row-actions .btn {
  min-height: 34px;
  padding: 0 10px;
}

.password-dialog {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  color: var(--card-foreground);
  max-width: calc(100vw - 32px);
  padding: 0;
  width: 520px;
}

.password-dialog::backdrop {
  background: var(--overlay);
}

.password-dialog form {
  padding: 22px;
}

.password-dialog h2 {
  margin: 0;
}

.password-dialog .hint {
  margin-bottom: 0;
}

.password-dialog-actions {
  justify-content: flex-end;
}

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

.check-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--muted);
  font-weight: 600;
}

.check-card input {
  width: 16px;
  min-height: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 12px;
}

.report-stats {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin: 12px 0 18px;
}

.stat {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px;
}

.stat span {
  color: var(--muted-foreground);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: uppercase;
}

small {
  color: var(--muted-foreground);
  line-height: 1.35;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--success-background);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}

.error,
.success {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 9px 12px;
}

.error {
  background: var(--danger-background);
  color: var(--destructive);
}

.success {
  background: var(--success-background);
  color: var(--success);
}

.invoice {
  display: none;
}

.print-window {
  background: var(--background);
  padding: 24px;
}

.print-toolbar {
  align-items: center;
  background: var(--sidebar);
  border-radius: var(--radius-card);
  color: var(--sidebar-foreground);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin: 0 auto 16px;
  max-width: 1080px;
  padding: 10px 12px;
}

.print-toolbar strong {
  margin-right: auto;
}

.print-toolbar button {
  background: var(--popover);
  border-radius: var(--radius);
  color: var(--popover-foreground);
  font-weight: 800;
  min-height: 34px;
  padding: 0 12px;
}

.invoice.print-preview {
  background: var(--card);
  color: var(--card-foreground);
  display: block;
  margin: 0 auto;
  max-width: 1080px;
  padding: 28px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    bottom: 0;
    left: 0;
    max-width: 84vw;
    padding: 22px;
    position: fixed;
    top: 0;
    transform: translateX(-105%);
    width: 280px;
    z-index: 20;
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding: 22px;
  }

  .app-shell.sidebar-collapsed .brand {
    grid-template-columns: 42px minmax(0, 1fr);
    justify-content: stretch;
  }

  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .user-box,
  .app-shell.sidebar-collapsed .nav-label {
    opacity: 1;
    pointer-events: auto;
    position: static;
    visibility: visible;
  }

  .app-shell.sidebar-collapsed .nav button {
    grid-template-columns: 24px minmax(0, 1fr);
    justify-items: stretch;
    justify-content: stretch;
    padding: 0 12px;
  }

  .sidebar-toggle {
    display: none;
  }

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

  .nav-overlay {
    background: var(--overlay);
    bottom: 0;
    display: block;
    left: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 0;
    transition: opacity 300ms ease;
    z-index: 15;
  }

  .app-shell.nav-open .nav-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

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

  .workspace {
    padding: 16px;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .stats {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .conciliation-module {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .conciliation-file-control {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .selected-file {
    width: 100%;
  }

  .selected-file-copy strong {
    max-width: calc(100vw - 100px);
  }

  .report-action-footer .btn {
    flex: 1 1 150px;
  }
}

@media print {
  :root {
    --background: #ffffff;
    --foreground: #17202a;
    --card: #ffffff;
    --card-foreground: #17202a;
    --muted: #f4f7f9;
    --muted-foreground: #64717f;
    --border: #d9e0e7;
    --primary: #145c54;
    --secondary: #d45b37;
  }

  body {
    background: var(--background);
  }

  .app-shell,
  .print-toolbar {
    display: none;
  }

  .invoice {
    display: block;
    padding: 26px;
    color: var(--foreground);
    font-size: 12px;
  }

  .invoice.print-preview {
    max-width: none;
    margin: 0;
    padding: 26px;
  }

  .invoice-cover {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 20px;
    margin-bottom: 18px;
  }

  .invoice h1 {
    margin: 0;
    font-size: 32px;
    color: var(--primary);
  }

  .invoice h2 {
    margin: 0;
    font-size: 18px;
  }

  .invoice p {
    margin: 6px 0 0;
    color: var(--muted-foreground);
  }

  .invoice-kicker {
    color: var(--secondary);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 11px;
  }

  .invoice-total {
    text-align: right;
    display: grid;
    gap: 4px;
  }

  .invoice-total span,
  .invoice-metrics span,
  .invoice-section-head span {
    color: var(--muted-foreground);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 800;
  }

  .invoice-total strong {
    font-size: 30px;
    color: var(--foreground);
  }

  .invoice-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
  }

  .invoice-metrics div {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
  }

  .invoice-metrics strong {
    display: block;
    margin-top: 5px;
    font-size: 18px;
  }

  .invoice-metrics small {
    display: block;
    margin-top: 4px;
  }

  .invoice-section {
    break-inside: avoid;
    margin: 18px 0;
  }

  .invoice-section-head {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-end;
    padding-bottom: 8px;
  }

  .invoice-section-head > div:last-child {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 12px;
    text-align: right;
  }

  .invoice table {
    min-width: 0;
    font-size: 11px;
  }

  .invoice th {
    background: var(--muted);
  }

  .invoice th,
  .invoice td {
    padding: 7px;
  }

  .invoice .status-badge {
    min-height: 20px;
    padding: 0 7px;
    font-size: 10px;
  }
}
