:root {
  --color-primary: #c41230;
  --color-secondary: #263238;
  --color-bg: #f4f6f8;
  --color-panel: #ffffff;
  --color-border: #d9dee5;
  --color-text: #1d252d;
  --color-muted: #6f7b88;
  --shadow: 0 16px 32px rgba(29, 37, 45, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f7f9fb 0%, #edf1f5 100%);
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  padding: 32px;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-block,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: #fff;
  background: var(--color-primary);
  border-radius: 8px;
  font-weight: 700;
}

.brand-logo {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: contain;
  padding: 4px;
  background: #fff;
  border-radius: 8px;
}

.brand-block h1,
.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.brand-block p,
.topbar p,
.sidebar-brand small {
  margin: 4px 0 0;
  color: var(--color-muted);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.login-form input,
.topbar input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #fff;
}

.login-form button,
.sidebar-nav button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.login-form button {
  margin-top: 8px;
  color: #fff;
  background: var(--color-primary);
  font-weight: 700;
}

.alert {
  padding: 10px 12px;
  border-radius: 6px;
}

.alert-error {
  color: #842029;
  background: #f8d7da;
  border: 1px solid #f1aeb5;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  color: #fff;
  background: var(--color-secondary);
}

.sidebar .brand-mark {
  background: var(--color-primary);
}

.sidebar-brand small {
  color: rgba(255, 255, 255, 0.68);
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.sidebar-nav button {
  padding: 10px 12px;
  color: rgba(255, 255, 255, 0.88);
  text-align: left;
  background: transparent;
}

.sidebar-nav button:hover,
.sidebar-nav button:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.logout-link {
  margin-top: auto;
  color: #fff;
  text-decoration: none;
}

.app-main {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr minmax(180px, 280px);
  align-items: center;
  gap: 16px;
  min-height: 76px;
  padding: 14px 22px;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
}

.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #fff;
}

.content-area {
  flex: 1;
  padding: 22px;
}

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

.metric-card,
.panel,
.loading-box {
  padding: 18px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.metric-card span {
  color: var(--color-muted);
}

.panel {
  margin-top: 18px;
  overflow-x: auto;
}

.table {
  width: 100%;
  min-width: 680px;
}

.table th,
.table td {
  vertical-align: middle;
}

.actions-cell {
  width: 1%;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

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

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

.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.module-header h2 {
  margin: 0;
  font-size: 24px;
}

.module-header p {
  margin: 5px 0 0;
  color: var(--color-muted);
}

.module-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar input,
.toolbar select {
  flex: 1;
}

.toolbar input,
.toolbar select,
.form-grid input,
.form-grid select,
.form-grid textarea {
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #fff;
}

.toolbar button,
.button,
.primary,
.form-actions button,
.table button,
.report-grid button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #6ac093;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

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

.danger {
  color: #fff;
  background: #b42318;
  border-color: #b42318;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--color-muted);
}

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

.checkbox-line {
  align-items: center;
  display: flex !important;
  flex-direction: row;
  gap: 8px;
}

.checkbox-line input {
  width: auto;
  min-height: 0;
}

.role-checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 18px;
  padding: 6px 0;
}

.role-checks .checkbox-line {
  min-height: 36px;
}

.form-grid textarea {
  resize: vertical;
}

.periodo-selects {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.form-actions button {
  min-width: 112px;
  white-space: nowrap;
}

.form-actions button.primary {
  min-width: 136px;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

input:disabled,
select:disabled,
textarea:disabled {
  color: var(--color-muted);
  background: #eef2f5;
  cursor: not-allowed;
}

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

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.report-grid button {
  min-height: 86px;
  text-align: left;
  background: #fff;
}

.detail-list {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px 18px;
  margin: 0;
}

.detail-list dt {
  color: var(--color-muted);
}

.detail-list dd {
  margin: 0;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table .actions-cell {
  width: 1%;
  min-width: 170px;
  white-space: nowrap;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.table .row-actions button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 14px;
  line-height: 1;
  background: #fff;
}

.table .row-actions .primary {
  color: #fff;
  background: #4f9f78;
  border-color: #4f9f78;
}

.table .row-actions .danger {
  color: #fff;
  background: #b42318;
  border-color: #b42318;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  padding: 12px 16px;
  color: #fff;
  background: var(--color-secondary);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.receipt-body {
  min-height: 100vh;
  background: #eef2f6;
}

.receipt-page {
  display: grid;
  place-items: start center;
  padding: 28px;
}

.receipt-card {
  width: min(820px, 100%);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}

.receipt-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 22px;
}

.receipt-toolbar button {
  min-height: 40px;
  padding: 8px 14px;
}

.receipt-toolbar .primary {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.receipt-header,
.receipt-brand,
.receipt-title,
.receipt-footer {
  display: flex;
  gap: 18px;
}

.receipt-header {
  justify-content: space-between;
  padding-bottom: 22px;
  border-bottom: 2px solid var(--color-primary);
}

.receipt-brand {
  align-items: center;
}

.receipt-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.receipt-brand h1,
.receipt-title h2 {
  margin: 0;
}

.receipt-brand p,
.receipt-title p,
.receipt-footer p {
  margin: 4px 0 0;
  color: var(--color-muted);
}

.receipt-number {
  min-width: 170px;
  text-align: right;
}

.receipt-number span,
.receipt-grid span,
.receipt-total span,
.receipt-note span {
  display: block;
  color: var(--color-muted);
  font-size: 14px;
}

.receipt-number strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.receipt-title {
  justify-content: space-between;
  align-items: baseline;
  margin: 26px 0;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--color-border);
}

.receipt-grid > div {
  padding: 14px 16px;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.receipt-grid > div:nth-child(2n) {
  border-right: 0;
}

.receipt-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}

.receipt-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding: 18px;
  color: #fff;
  background: var(--color-secondary);
}

.receipt-total span {
  color: #d9e2ea;
}

.receipt-total strong {
  font-size: 34px;
}

.receipt-note {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
}

.receipt-note p {
  margin: 6px 0 0;
}

.receipt-footer {
  justify-content: space-between;
  align-items: end;
  margin-top: 36px;
}

.receipt-signature {
  min-width: 220px;
  padding-top: 36px;
  text-align: center;
  border-top: 1px solid var(--color-text);
}

@media print {
  .no-print {
    display: none !important;
  }

  .receipt-body {
    background: #fff;
  }

  .receipt-page {
    display: block;
    padding: 0;
  }

  .receipt-card {
    width: 100%;
    padding: 0;
    border: 0;
    box-shadow: none;
  }
}

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

  .sidebar {
    display: none;
  }

  body.sidebar-open .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(290px, 86vw);
  }

  .menu-button {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    grid-template-columns: auto 1fr;
    align-items: start;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar-actions {
    grid-column: 1 / -1;
  }

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

  .panel-list,
  .report-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .content-area {
    padding: 16px;
  }

  .metric-card,
  .panel,
  .loading-box {
    padding: 14px;
  }
}

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

  .footer {
    flex-direction: column;
  }

  .module-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar input,
  .toolbar select,
  .toolbar button,
  .module-header button,
  .form-actions button {
    width: 100%;
  }

  .form-actions,
  .receipt-toolbar,
  .row-actions {
    justify-content: stretch;
  }

  .row-actions button,
  .receipt-toolbar button {
    flex: 1 1 100%;
  }
}
