/* ---------- Reset & base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-900: #0f2f5c;
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-100: #e8f0fe;
  --blue-50:  #f4f8ff;

  --green-600: #16a34a;
  --green-100: #e8f8ee;

  --amber-600: #b45309;
  --amber-100: #fef3e0;

  --red-600: #dc2626;
  --red-100: #fdecec;

  --gray-900: #111827;
  --gray-700: #374151;
  --gray-500: #6b7280;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.14);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--gray-900);
  background: var(--gray-50);
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 14px; }

/* ---------- Buttons ---------- */
.primary-btn {
  background: var(--blue-600);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s ease;
}
.primary-btn:hover { background: var(--blue-700); }
.primary-btn.full { width: 100%; margin-top: 10px; }
.primary-btn.small { padding: 8px 14px; font-size: 13px; }

.ghost-btn {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s ease, border-color .15s ease;
}
.ghost-btn:hover { background: var(--gray-100); }
.ghost-btn.small { padding: 6px 10px; font-size: 12px; }
.ghost-btn.danger { color: var(--red-600); border-color: #f3c9c9; }
.ghost-btn.danger:hover { background: var(--red-100); }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, #eaf1ff 0%, #f7f9fc 45%, #ffffff 100%);
  padding: 24px;
}

.login-wrap {
  display: flex;
  width: 100%;
  max-width: 960px;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-200);
}

.login-brand {
  flex: 1;
  background: linear-gradient(160deg, var(--blue-900), var(--blue-700));
  color: #fff;
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}
.login-brand h1 { font-size: 30px; letter-spacing: -0.5px; }
.login-brand p { color: #cfe0ff; font-size: 14.5px; line-height: 1.5; max-width: 320px; }

.brand-logo {
  width: 84px; height: 84px;
  flex-shrink: 0;
  background-color: #fff;
  background-image: url('../assets/logo.jpeg');
  background-repeat: no-repeat;
  background-size: 250% 250%;
  background-position: 50% 25%;
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.brand-logo.small { width: 40px; height: 40px; border-radius: 11px; box-shadow: none; }

.brand-points { list-style: none; display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.brand-points li {
  font-size: 13.5px; color: #eaf1ff;
  padding-left: 22px; position: relative;
}
.brand-points li::before {
  content: "✓"; position: absolute; left: 0; color: #7ee0a8; font-weight: 700;
}

.login-card { flex: 1; padding: 48px 44px; display: flex; flex-direction: column; justify-content: center; }
.login-card h2 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--gray-500); font-size: 13.5px; margin-bottom: 24px; }

#loginForm label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; margin-top: 16px; }
#loginForm label:first-of-type { margin-top: 0; }

#loginForm input[type="text"], #loginForm input[type="password"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#loginForm input:focus { border-color: var(--blue-600); box-shadow: 0 0 0 3px var(--blue-100); }

.pass-field { position: relative; }
.pass-field input { padding-right: 44px; }
.pass-field .ghost-btn { position: absolute; right: 4px; top: 4px; border: none; padding: 6px 10px; }

.form-error {
  background: var(--red-100);
  color: var(--red-600);
  border: 1px solid #f3c9c9;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 16px;
}

.login-foot { margin-top: 22px; font-size: 12px; color: var(--gray-500); text-align: center; }
.login-version { margin-top: 4px; font-size: 11px; color: #9aa5b8; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #101a2c;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text small { color: #93a4c3; font-size: 11px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none;
  color: #b8c4dc;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-item .nav-ico { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--blue-600); color: #fff; }

.sidebar-foot { padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .ghost-btn { width: 100%; background: transparent; color: #f2a8a8; border-color: rgba(255,255,255,.15); }
.sidebar-foot .ghost-btn:hover { background: rgba(220,38,38,.15); }
.version-tag { margin-top: 10px; font-size: 10.5px; color: #93a4c3; text-align: center; }

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

.topbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 14px; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip strong { display: block; font-size: 13px; }
.user-chip small { display: block; font-size: 11px; color: var(--gray-500); }

.content { flex: 1; padding: 26px 28px 60px; overflow-y: auto; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Cards ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.cards-grid.single-stat {
  grid-template-columns: minmax(220px, 340px);
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--gray-500); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--gray-900); }
.stat-hint { font-size: 11.5px; color: var(--gray-500); }
.stat-card.highlight { border-color: #fcd9a0; background: var(--amber-100); }
.stat-card.highlight .stat-value { color: var(--amber-600); }
.stat-card.credit { border-color: #a7e3bd; background: var(--green-100); }
.stat-card.credit .stat-value { color: var(--green-600); }

/* ---------- Panel ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.panel-head { margin-bottom: 18px; }
.panel-head h3 { font-size: 16px; font-weight: 700; }
.panel-sub { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 46px 20px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  text-align: center;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--blue-600); background: var(--blue-50); }
.dropzone-ico { font-size: 30px; color: var(--blue-600); margin-bottom: 4px; }
.dropzone strong { font-size: 14.5px; }
.dropzone span { font-size: 12.5px; color: var(--gray-500); }

.upload-log { margin-top: 20px; border-top: 1px solid var(--gray-200); padding-top: 16px; }
.upload-log-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.upload-log-head h4 { font-size: 13.5px; }
#uploadLogList { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
#uploadLogList li { font-size: 13px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--gray-50); border: 1px solid var(--gray-200); }
#uploadLogList li.ok { border-color: #a7e3bd; background: var(--green-100); color: #14532d; }
#uploadLogList li.warn { border-color: #fcd9a0; background: var(--amber-100); color: #7c3d05; }
#uploadLogList li.err { border-color: #f3c9c9; background: var(--red-100); color: #7f1d1d; }

/* ---------- Filters ---------- */
.filters-bar {
  display: flex; flex-wrap: wrap; align-items: end; gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}
.filter-field { display: flex; flex-direction: column; gap: 5px; min-width: 130px; }
.filter-field.grow { flex: 1; min-width: 220px; }
.filter-field label { font-size: 11.5px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .3px; }
.filter-field input, .filter-field select {
  padding: 9px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); font-size: 13.5px;
}
.chk-inline { display: flex !important; align-items: center; gap: 6px; font-size: 13px !important; text-transform: none !important; font-weight: 500 !important; padding-bottom: 4px; }

/* ---------- Bulk bar ---------- */
.bulk-bar {
  display: flex; align-items: center; gap: 12px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--blue-700);
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .3px;
  color: var(--gray-500); font-weight: 700;
  padding: 10px 12px; border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
.data-table tbody tr:hover { background: var(--gray-50); }
.col-check { width: 34px; }

.code-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--gray-100); color: var(--gray-700);
}
.code-pill.changed { background: var(--amber-100); color: var(--amber-600); }
.code-pill .arrow { color: var(--gray-500); font-weight: 400; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.pendente { background: var(--gray-100); color: var(--gray-500); }
.badge.ajustado { background: var(--green-100); color: var(--green-600); }
.badge.entrada { background: var(--blue-100); color: var(--blue-700); }
.badge.saida { background: #f3e8ff; color: #7c3aed; }

.row-action-btn {
  border: none; background: transparent; color: var(--blue-600);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.row-action-btn:hover { text-decoration: underline; }

.table-foot { padding: 12px 4px 0; font-size: 12.5px; color: var(--gray-500); }

.empty-state { text-align: center; color: var(--gray-500); font-size: 13.5px; padding: 34px 10px; }

/* ---------- Report ---------- */
.report-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.report-summary .mini-card {
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.report-summary .mini-card span { display: block; }
.report-summary .mini-card .mc-label { font-size: 11px; color: var(--gray-500); font-weight: 700; text-transform: uppercase; }
.report-summary .mini-card .mc-value { font-size: 18px; font-weight: 800; margin-top: 3px; }

.rel-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.rel-toolbar .panel-sub { margin: 0; }
.rel-toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Cabeçalho e rodapé de marca do relatório ---------- */
.rel-report-header {
  background: linear-gradient(135deg, var(--blue-900), var(--blue-700));
  color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 22px;
  margin: -20px -22px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.rel-header-brand { display: flex; align-items: center; gap: 10px; }
.rel-header-brand strong { font-size: 15px; letter-spacing: -0.2px; }
.rel-header-empresa { text-align: right; }
.rel-header-empresa .rhe-label {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .4px;
  color: #cfe0ff; font-weight: 700; margin-bottom: 2px;
}
.rel-header-empresa .rhe-value { display: block; font-size: 14px; font-weight: 700; }

.rel-report-footer {
  margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--gray-200);
  text-align: center; font-size: 11.5px; font-weight: 700; letter-spacing: .5px; color: var(--blue-700);
}

/* ---------- Cores de marca nos cards e tabelas do relatório ---------- */
#modalRelatorio .report-summary .mini-card {
  border-left: 3px solid var(--blue-600);
}
#modalRelatorio .report-summary .mini-card .mc-value { color: var(--blue-900); }

.rel-code-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.rel-code-block {
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 14px;
}
.rel-code-block h4 {
  font-size: 12.5px; font-weight: 700; color: var(--blue-700);
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 2px solid var(--blue-100);
}
.rel-code-block .table-wrap { max-height: 260px; overflow-y: auto; }
.data-table.small th, .data-table.small td { padding: 6px 9px; font-size: 12px; }
#modalRelatorio .data-table.small thead th {
  position: sticky; top: 0; background: var(--blue-50); color: var(--blue-700);
}
.rel-empty { text-align: center; color: var(--gray-500); font-size: 12.5px; padding: 14px !important; white-space: normal; }

.hint-text { font-size: 12px; color: var(--gray-500); margin-bottom: 12px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 100; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-overlay:not([hidden]) { display: flex; align-items: center; justify-content: center; }
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 880px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--gray-200);
}
.modal-head h3 { font-size: 15.5px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }

.modal-item-info {
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 12.5px; color: var(--gray-700); margin-bottom: 18px; line-height: 1.6;
}
.modal-item-info strong { color: var(--gray-900); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; font-weight: 700; color: var(--gray-700); margin-bottom: 6px; }
.form-grid input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); font-size: 13.5px;
}
.form-grid input:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px var(--blue-100); }

/* ---------- Toolbar row (Documentos) ---------- */
.toolbar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }

/* ---------- NCM picker (modal Ajustar por NCM) ---------- */
.ncm-selected-wrap {
  background: var(--blue-50); border: 1px solid var(--blue-100); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 14px;
}
.ncm-selected-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; font-size: 12.5px; font-weight: 700; color: var(--blue-700);
}
.ncm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ncm-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--blue-100); color: var(--blue-700);
  border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; font-weight: 600;
}
.ncm-chip button {
  border: none; background: var(--blue-100); color: var(--blue-700);
  width: 16px; height: 16px; border-radius: 50%; font-size: 11px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.ncm-chip button:hover { background: var(--blue-600); color: #fff; }

.ncm-list-wrap {
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.ncm-list-wrap .data-table { font-size: 12.5px; }
.ncm-list-wrap thead th { position: sticky; top: 0; background: #fff; }
.ncm-list-wrap tr.ncm-row-selected { background: var(--blue-50); }

/* ---------- Documento fiscal (modal Ver documento) ---------- */
.doc-info-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 20px;
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 16px;
}
.doc-info-grid .di-item { display: flex; flex-direction: column; gap: 2px; }
.doc-info-grid .di-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: var(--gray-500); }
.doc-info-grid .di-value { font-size: 13px; color: var(--gray-900); font-weight: 600; word-break: break-word; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--gray-900); color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 200;
}
.toast.err { background: var(--red-600); }
.toast.ok { background: var(--green-600); }

/* ---------- Misc ---------- */
@media print {
  .sidebar, .topbar, .filters-bar, .toolbar-row { display: none !important; }
  .content { padding: 0; }
  .panel { box-shadow: none; border: none; }

  #modalRelatorio:not([hidden]) {
    position: static;
    background: none;
    padding: 0;
    display: block;
  }
  #modalRelatorio .modal { max-width: 100%; max-height: none; box-shadow: none; }
  #modalRelatorio .modal-head, #modalRelatorio .modal-foot, #modalRelatorio .rel-toolbar-actions {
    display: none !important;
  }
  #modalRelatorio .rel-code-block .table-wrap { max-height: none; overflow: visible; }
  #modalRelatorio .rel-code-grid { break-inside: avoid; }
  #modalRelatorio .rel-code-block { break-inside: avoid; }
  #modalRelatorio .rel-report-header { break-inside: avoid; break-after: avoid; }
  body.printing-relatorio .app-shell { display: none !important; }

  /* mantém as cores de marca (gradiente do cabeçalho, faixas azuis) na impressão */
  #modalRelatorio, #modalRelatorio * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 18px; }
  .login-brand { display: none; }
}
