:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #687386;
  --line: #dce1e8;
  --blue: #255f9f;
  --green: #177245;
  --red: #b42318;
  --amber: #9a6700;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

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

h1, h2, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
p { color: var(--muted); margin-top: 4px; }

.health {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fafbfc;
}

main { padding: 18px 24px 28px; }

.moduleTabs {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding: 8px;
  background: #eef1f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.moduleTab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 128px;
  height: 54px;
  padding: 0;
  background: #ffffff;
  color: var(--muted);
  border-color: var(--line);
  border-radius: 6px;
  box-shadow: 0 1px 1px rgba(24, 32, 42, 0.04);
}

.moduleTab.active {
  background: #ffffff;
  color: var(--text);
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue), 0 2px 8px rgba(37, 95, 159, 0.12);
}

.moduleTab img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
}

.moduleTab {
  overflow: hidden;
}

.moduleTab.utilityTab {
  margin-left: auto;
  color: var(--blue);
  background: #ffffff;
  border-color: var(--line);
}

.moduleTab.utilityTab.active {
  color: var(--blue);
  background: #ffffff;
  border-color: var(--blue);
}

.moduleTab:disabled {
  background: transparent;
  border-color: transparent;
  color: #9aa4b2;
}

body.waiting {
  overflow: hidden;
}

.waitingModal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.waitingBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 28, 38, 0.62);
  backdrop-filter: blur(2px);
}

.waitingDialog {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(420px, 100%);
  padding: 30px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.waitingDialog h2 {
  font-size: 20px;
}

.waitingDialog p {
  max-width: 340px;
  margin: 0;
  line-height: 1.5;
}

.waitingSpinner {
  width: 54px;
  height: 54px;
  border: 6px solid #dce4ed;
  border-top-color: var(--blue);
  border-right-color: var(--green);
  border-radius: 50%;
  animation: waiting-spin 0.85s linear infinite;
}

@keyframes waiting-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .waitingSpinner { animation-duration: 1.8s; }
}

.controls {
  display: flex;
  gap: 12px;
  align-items: end;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input, select, button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  background: #fff;
}

.monthStepper {
  display: grid;
  grid-template-columns: 36px 150px 36px;
  gap: 6px;
  align-items: center;
}

.monthStepper input {
  width: 150px;
}

.iconButton {
  width: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

button {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  cursor: pointer;
  font-weight: 600;
}

.secondaryButton {
  color: var(--text);
  background: #ffffff;
  border-color: var(--line);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 32, 42, 0.55);
}

.settingsDialog {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.settingsHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.settingsTabs {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.settingsTab {
  color: var(--text);
  background: #fff;
  border-color: var(--line);
}

.settingsTab.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.settingsForm { display: grid; gap: 16px; padding: 18px; }
.settingsSection { display: grid; gap: 10px; margin-bottom: 18px; }
.settingsSection h3 { margin: 0; font-size: 14px; }
.settingsGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.settingsGrid label { font-size: 12px; }
.settingsGrid input { width: 100%; }
.configuredHint { color: var(--green); font-size: 11px; }
.settingsActions { display: flex; gap: 10px; flex-wrap: wrap; }
.settingsMessage { min-height: 20px; color: var(--muted); }

button:disabled {
  background: #c5ccd6;
  border-color: #c5ccd6;
  cursor: not-allowed;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.summary div {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.amazonPanel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.amazonHeader {
  display: flex;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
}

.amazonHeader > div {
  flex: 1;
}

.downloadButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 190px;
  height: 36px;
  padding: 0 12px;
  color: #fff;
  text-decoration: none;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 6px;
  font-weight: 600;
}

.spacedAction {
  margin-left: 24px;
}

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

.amazonLink {
  display: grid;
  gap: 2px;
  padding: 10px;
  color: var(--text);
  text-decoration: none;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 6px;
  height: auto;
  text-align: left;
}

.amazonLink strong { font-size: 16px; }
.amazonLink span { color: var(--muted); font-size: 12px; }
.amazonLink em { color: var(--blue); font-style: normal; font-weight: 700; }

.amazonLink.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.emptyState {
  padding: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

aside, .tableWrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 420px;
}

aside { padding: 14px; }

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

.toggleLine {
  display: flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.toggleLine input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.errors {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
}

.errorItem {
  padding: 10px;
  border: 1px solid #f3c7c2;
  border-radius: 6px;
  background: #fff7f6;
  color: var(--red);
}

.warningItem {
  padding: 10px;
  border: 1px solid #f6d58a;
  border-radius: 6px;
  background: #fff8e5;
  color: var(--amber);
}

.issueGroup {
  display: grid;
  gap: 7px;
}

.issueGroup h3 {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 13px;
}

.issueGroup h3 span {
  color: var(--muted);
  font-weight: 600;
}

.issueLink {
  cursor: pointer;
}

.issueLink:focus {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.tableHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.tableHeader input { width: 260px; }

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

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: #fafbfc;
}

td.customer { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

tr.rowHighlight td {
  background: #eaf2ff;
  box-shadow: inset 0 1px 0 #9dc3f5, inset 0 -1px 0 #9dc3f5;
}

td.amountPositive {
  color: var(--green);
  font-weight: 700;
}

td.amountNegative {
  color: var(--red);
  font-weight: 700;
}

td.copyAccount[data-copy-account]:not([data-copy-account=""]) {
  cursor: copy;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

td.copyAccount.copied {
  color: var(--green);
  background: #eaf7ef;
  font-weight: 700;
}

td.copyDocNo[data-copy-doc-no]:not([data-copy-doc-no=""]) {
  cursor: copy;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

td.copyDocNo.copied {
  color: var(--green);
  background: #eaf7ef;
  font-weight: 700;
}

.rowAction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 9px;
  color: #fff;
  text-decoration: none;
  background: var(--blue);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.rowActionButton {
  height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 12px;
}

.oposPanel {
  margin-top: 14px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.oposMessage {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  min-width: 48px;
  text-align: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.ok { color: var(--green); background: #eaf7ef; }
.error { color: var(--red); background: #fff0ee; }
.warning { color: var(--amber); background: #fff8e5; }

.loginBody {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.loginShell {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
}

.loginPanel {
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.loginForm {
  display: grid;
  gap: 12px;
}

.loginError {
  padding: 10px;
  color: var(--red);
  background: #fff7f6;
  border: 1px solid #f3c7c2;
  border-radius: 6px;
}

@media (max-width: 980px) {
  .topbar, .controls { align-items: stretch; flex-direction: column; }
  .topbarActions { align-items: stretch; flex-direction: column; }
  .moduleTabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .moduleTab { width: 100%; }
  .moduleTab.utilityTab { margin-left: 0; }
  .amazonLinks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
