:root {
  --blue: #123c69;
  --blue2: #1769aa;
  --background: #f3f6fa;
  --border: #dce3ec;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #b42318;
  --success: #067647;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button {
  border: 0;
  border-radius: 7px;
  padding: 11px 16px;
  color: white;
  background: var(--blue2);
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  filter: brightness(.92);
}

button.secondary {
  background: #e8eef5;
  color: var(--blue);
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 11px;
  background: white;
  color: var(--text);
}

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

.login-page {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 20px 20px 40px;
  overflow-y: auto;
  background: linear-gradient(135deg, #0b1220 0%, #0f2447 45%, #123c69 100%);
}

.login-card {
  width: min(420px, 100%);
  background: white;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 14px 45px #03081366;
}

.login-header {
  background: linear-gradient(135deg, #1769aa, #123c69);
  padding: 30px 26px 26px;
  text-align: center;
  color: white;
}

.login-header > h1 {
  margin: 0;
  font-size: 26px;
  color: white;
}

.login-header > p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, .75);
  font-size: 14px;
}

.login-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  display: grid;
  place-items: center;
  font-size: 26px;
}

.login-body {
  padding: 26px 30px 0;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 16px;
}

.banner-ok {
  background: #e8f7ef;
  border: 1px solid #b7e6c9;
  color: var(--success);
}

.banner-trial {
  background: #fff6e3;
  border: 1px solid #f3d9a4;
  color: #8a5a00;
}

.unlock-trigger {
  flex: none;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  color: white;
  background: #f5a623;
}

.unlock-trigger:hover {
  background: #e09213;
}

.login-body label {
  margin-bottom: 0;
}

.login-body label + input,
.login-body input {
  margin-bottom: 14px;
}

#loginSubmitBtn {
  display: block;
  width: 100%;
  margin: 22px 0 0;
}

.first-access-link {
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.first-access-link a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.first-access-link a:hover {
  text-decoration: underline;
}

#activateForm h3 {
  margin: 0 0 8px;
  color: var(--blue);
}

#activateForm .hint {
  margin: 0 0 14px;
}

#activateForm button:not(.btn-cancel) {
  display: block;
  width: 100%;
  margin: 22px 0 0;
}

#activSubmitBtn + .btn-cancel {
  margin-top: 10px;
}

.login-footer {
  margin-top: 24px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  text-align: center;
}

.login-footer p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.modal-card {
  width: min(380px, 100%);
  background: white;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 18px 50px #0b16266b;
  animation: modalIn .18s ease-out;
}

.modal-card h3 {
  margin: 0 0 6px;
  color: var(--blue);
}

.modal-card > p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1;
  margin-top: 0;
}

.btn-cancel {
  background: #e8eef5;
  color: var(--blue);
}

.btn-unlock {
  background: #f5a623;
}

.btn-unlock:hover {
  background: #e09213;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0b1220 0%, #0f2447 45%, #123c69 100%);
  color: white;
}

.splash[hidden] {
  display: none !important;
}

.splash-box {
  width: min(360px, 90%);
  text-align: center;
}

.splash-logo {
  margin-bottom: 8px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
}

.splash-status {
  margin: 0 0 16px;
  font-size: 14px;
  color: rgba(255, 255, 255, .85);
  min-height: 20px;
}

.splash-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}

.splash-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #34d399, #fbbf24, #3b82f6);
  transition: width .2s linear;
}

.splash-pct {
  margin: 10px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, .6);
  font-family: Consolas, monospace;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  color: white;
  background: var(--blue);
}

.topbar > div {
  display: flex;
  align-items: center;
  gap: 16px;
}

.layout {
  display: flex;
  min-height: calc(100vh - 64px);
}

.sidebar {
  width: 150px;
  padding: 14px 8px;
  background: white;
  border-right: 1px solid var(--border);
  position: relative;
  transition: width .25s ease;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 0;
  padding: 0;
  border-right: 0;
}

.sidebar.collapsed .sidebar-nav {
  display: none;
}

button.sidebar-toggle {
  position: absolute;
  top: 34px;
  right: 0;
  transform: translate(100%, -50%);
  z-index: 20;
  width: 16px;
  height: 40px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, var(--blue2), var(--blue));
  box-shadow: 0 3px 10px rgba(0, 0, 0, .28),
    inset 0 1px 0 rgba(255, 255, 255, .4),
    inset -2px 0 4px rgba(0, 0, 0, .18);
  transition: filter .2s, box-shadow .2s;
}

button.sidebar-toggle:hover {
  filter: brightness(1.15);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35),
    inset 0 1px 0 rgba(255, 255, 255, .4),
    inset -2px 0 4px rgba(0, 0, 0, .18);
}

button.sidebar-toggle .seta {
  display: block;
  font-size: 11px;
  line-height: 1;
  transition: transform .25s ease;
}

.sidebar.collapsed button.sidebar-toggle .seta {
  transform: rotate(180deg);
}

.sidebar button[data-page] {
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
}

.sidebar button[data-page]:hover {
  background: #edf4fb;
  color: var(--blue2);
}

.sidebar button[data-page].ativo {
  background: var(--blue2);
  color: white;
}

.content {
  width: 100%;
  padding: 18px 20px;
  overflow: auto;
}

.page {
  max-width: 1500px;
  margin: auto;
}

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 24px;
}

.chart-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.chart-box h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text);
}

.chart-wrap {
  position: relative;
  height: 280px;
  overflow: hidden;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.barcode-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.barcode-row input {
  flex: 1;
}

.barcode-row button {
  white-space: nowrap;
}

table.compact {
  margin: 8px 0 16px;
}

table.compact td,
table.compact th {
  padding: 6px 10px;
}

.muted {
  color: #999;
}

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

.page h2 {
  margin-top: 0;
  color: var(--blue);
}

.page-title {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

.card {
  padding: 22px;
  background: white;
  border-radius: 12px;
  border-left: 5px solid var(--blue2);
  box-shadow: 0 3px 12px #102a4310;
}

.card small {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.card b {
  font-size: 26px;
  color: var(--blue);
}

.card.warning {
  border-left-color: #d97706;
}

.card.warning b {
  color: #d97706;
}

.table-wrap {
  overflow: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 14px 0;
}

.table-wrap th,
.table-wrap td {
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  background: #f7f9fc;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.status.ok {
  background: #e7f6ef;
  color: var(--success);
}

.status.alert {
  background: #fef3e2;
  color: #b45309;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin: 18px 0;
}

.form-grid label.wide {
  grid-column: 1 / -1;
}

.form-grid button {
  align-self: end;
  justify-self: start;
}

.message {
  margin: 14px 0;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 700;
  display: none;
}

.message.show {
  display: block;
}

.message.ok {
  background: #e7f6ef;
  color: var(--success);
}

.message.err {
  background: #fdecea;
  color: var(--danger);
}

.message.info {
  background: #e8f0fb;
  color: #1b5fb0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 22, 39, .55);
}

.modal {
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: white;
  border-radius: 14px;
  box-shadow: 0 18px 50px #0b16266b;
  animation: modalIn .18s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.modal-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

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

button.close {
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
  font-weight: 400;
}

button.close:hover {
  color: var(--danger);
  filter: none;
}

.modal-wide {
  width: min(780px, 100%);
  min-height: min(680px, 90vh);
}

.ficha-cab {
  margin-bottom: 14px;
}

.ficha-cab .hint {
  margin-top: 4px;
}

.ficha h4 {
  margin: 20px 0 8px;
  font-size: 14px;
  color: var(--blue);
}

table.ficha-tabela {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}

table.ficha-tabela th,
table.ficha-tabela td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  white-space: nowrap;
}

table.ficha-tabela th {
  background: #f4f8fc;
}

#modalBody {
  padding: 22px;
  flex: 1;
  overflow-y: auto;
}

#modalBody h3 {
  margin: 22px 0 4px;
  font-size: 15px;
  color: var(--blue);
}

#ajNovoBtn {
  margin-bottom: 14px;
}

#ajSearch {
  margin-bottom: 12px;
}

#modalAjusteLista .table-wrap {
  max-height: 58vh;
  overflow: auto;
  margin: 0;
}

#modalAjusteForm {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

#modalAjusteForm label.wide,
#modalAjusteForm .btn-group {
  grid-column: 1 / -1;
}

#modalAjusteForm .btn-group {
  position: sticky;
  bottom: 0;
  background: white;
  padding-top: 10px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 11px;
  background: white;
  color: var(--text);
}

.modal-form button {
  margin-top: 6px;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title .btn-group {
  flex-wrap: nowrap;
}

button.small {
  padding: 6px 8px;
  font-size: 12.5px;
  background: #e8eef5;
  color: var(--blue);
}

button.small.icon-only {
  padding: 6px 10px;
  vertical-align: middle;
}
button.small.icon-only svg {
  display: inline-block;
  vertical-align: middle;
}

button.danger {
  background: var(--danger);
}

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

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 14px;
}

.csv-help {
  background: #f4f7fb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  font-size: 13px;
}

.loc-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
}

.loc-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fbfcfe;
}

.page input,
.page select {
  max-width: 420px;
}

#stockSearch {
  margin: 14px 0;
}

@media (max-width: 900px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .sidebar {
    width: 150px;
  }
}

@media (max-width: 600px) {
  .layout {
    flex-direction: column;
  }

  .sidebar,
  .sidebar.collapsed {
    width: 100%;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar.collapsed .sidebar-nav {
    display: block;
  }

  button.sidebar-toggle {
    display: none;
  }

  .cards,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  .topbar,
  .sidebar,
  button,
  .btn-group,
  .message,
  .hint,
  .muted {
    display: none !important;
  }

  .layout {
    display: block;
  }

  .content {
    padding: 0;
    overflow: visible;
  }

  .page {
    max-width: none;
    margin: 0;
  }

  .page[hidden] {
    display: none;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    margin: 0;
  }

  thead {
    display: table-header-group;
  }

  tr {
    page-break-inside: avoid;
  }

  table {
    font-size: 10px;
  }
}