:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #17202a;
  --muted: #687382;
  --line: #dce2e8;
  --blue: #1768ac;
  --blue-dark: #0d4778;
  --red: #d61f2c;
  --green: #16835b;
  --amber: #b86b00;
  --teal: #087f83;
  --shadow: 0 16px 45px rgba(20, 34, 48, 0.09);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--blue);
  text-decoration: none;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

input:disabled,
input[readonly] {
  background: #edf1f5;
  color: #516071;
}

.locked-field {
  background: #e5eaf0 !important;
  border-color: #c8d1da !important;
  color: #596879 !important;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #aeb9c4;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

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

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

.small-button {
  min-height: 32px;
  padding: 6px 10px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 70px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: #314153;
  font-weight: 700;
}

nav a:hover {
  background: var(--surface-2);
}

.operator-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
}

.operator-pill.missing {
  border-color: #f1b6bc;
  background: #fff4f5;
  color: var(--red);
  font-weight: 800;
}

.page {
  width: min(1440px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.hero,
.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.hero {
  min-height: 190px;
  padding: 28px;
  border-radius: 8px;
  background:
    linear-gradient(110deg, rgba(214, 31, 44, 0.97), rgba(23, 104, 172, 0.94)),
    repeating-linear-gradient(45deg, rgba(255,255,255,.13) 0 2px, transparent 2px 18px);
  color: #fff;
  box-shadow: var(--shadow);
}

.hero h1,
.section-head h1,
.auth-panel h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.05;
}

.section-head h1 {
  font-size: 34px;
}

.eyebrow {
  margin: 0;
  color: inherit;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: .78;
}

.hero-actions,
.actions,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.role-hero {
  display: grid;
  gap: 22px;
  min-height: 64vh;
  align-content: center;
}

.role-hero h1 {
  margin: 0;
  font-size: clamp(38px, 7vw, 76px);
  line-height: 1;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 14px;
}

.role-card {
  display: grid;
  gap: 10px;
  min-height: 170px;
  align-content: space-between;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

.role-card:hover {
  border-color: var(--blue);
}

.role-card strong {
  font-size: 24px;
}

.role-card span {
  color: var(--muted);
  line-height: 1.35;
}

.admin-role {
  border-color: #f0b7bd;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #e8f7ef;
  border: 1px solid #bfe5d1;
  color: #0c6242;
  font-weight: 700;
}

.flash-error {
  background: #fff0f1;
  border-color: #f1b6bc;
  color: var(--red);
}

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

.two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, .55fr);
}

.add-grid {
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: #314153;
  font-size: 13px;
  font-weight: 800;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.check input {
  width: auto;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.metrics div,
.split-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.metrics span,
.split-stat span {
  color: var(--muted);
  font-weight: 800;
}

.metrics b {
  font-size: 24px;
}

.split-stat {
  margin-bottom: 8px;
  box-shadow: none;
}

.search {
  display: flex;
  gap: 8px;
  width: min(460px, 100%);
}

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

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

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

th {
  color: #516071;
  font-size: 12px;
  text-transform: uppercase;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.status {
  display: inline-flex;
  border-radius: 6px;
  padding: 5px 8px;
  background: #edf1f5;
  font-size: 12px;
  font-weight: 900;
}

.status-w_terenie {
  background: #fff3df;
  color: var(--amber);
}

.status-w_trakcie_rozliczenia {
  background: #e9f4ff;
  color: var(--blue-dark);
}

.status-rozliczony {
  background: #e8f7ef;
  color: var(--green);
}

.status-zaswiadczenie_odebrane {
  background: #eef0f3;
  color: #516071;
}

.tiny {
  width: 74px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.bottom-grid {
  grid-template-columns: minmax(220px, 320px) minmax(260px, 1fr);
}

.final-amount-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.final-amount-control button {
  min-width: 86px;
}

.field-title {
  margin: 0 0 6px;
  color: #314153;
  font-size: 13px;
  font-weight: 800;
}

.envelope-split {
  display: grid;
  gap: 10px;
}

.second-envelope[hidden] {
  display: none;
}

.envelope-split-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 180px);
  gap: 10px;
}

.envelope-split-row label {
  margin-bottom: 0;
}

.switch-row {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 12px;
}

.money-table {
  margin: 16px 0;
}

.money-table input {
  max-width: 170px;
}

.row-error input[data-row-total] {
  border-color: var(--red);
  background: #fff5f5;
}

.field-error {
  display: block;
  min-height: 16px;
  margin-top: 4px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
}

.danger-banner {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 18px;
  border: 2px solid var(--red);
  border-radius: 8px;
  background: #fff0f1;
  color: var(--red);
  font-size: 18px;
}

.danger-check {
  padding: 12px;
  border: 1px solid var(--red);
  border-radius: 8px;
  background: #fff8f8;
  color: var(--red);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.between {
  justify-content: space-between;
}

.confirm-modal[hidden] {
  display: none;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: auto;
}

.confirm-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 28, 0.52);
}

.confirm-modal__box {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(10, 18, 28, 0.28);
}

.confirm-modal__box--wide {
  width: min(900px, 100%);
}

.confirm-modal__box h2 {
  margin: 4px 0 18px;
  font-size: 30px;
}

.confirm-copy {
  margin: -6px 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.confirm-details {
  display: grid;
  gap: 10px;
  margin: 0 0 20px;
}

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

.confirm-details div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.confirm-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.confirm-details dd {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.confirm-details--compact dd {
  font-size: 17px;
}

.scan-field {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  font-weight: 800;
}

.scan-field input {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
}

.scan-field--error input {
  border-color: var(--red);
  background: #fff5f5;
  box-shadow: 0 0 0 3px rgba(214, 31, 44, 0.12);
}

.scan-field .field-error,
.scan-field--error .field-error,
.scan-error {
  color: var(--red) !important;
}

.office-notes {
  margin: -4px 0 16px;
}

.office-notes label {
  display: grid;
  gap: 6px;
  color: #314153;
  font-weight: 800;
}

.bank-columns {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}

.bank-panel {
  padding: 14px;
}

.envelope-list {
  display: grid;
  gap: 10px;
}

.stack-form {
  display: grid;
  gap: 8px;
}

.stack-form input {
  min-width: 0;
}

.settlement-queue {
  margin-bottom: 16px;
}

.settlement-bank {
  margin-bottom: 16px;
}

.envelope-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.envelope-item span,
.envelope-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.auth-panel {
  display: grid;
  min-height: 60vh;
  place-items: center;
}

.station-card {
  width: min(440px, 100%);
}

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

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

  .two,
  .add-grid,
  .form-grid,
  .bottom-grid,
  .confirm-details--compact,
  .envelope-split-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .page {
    width: min(100% - 20px, 1440px);
    margin-top: 12px;
  }

  .confirm-modal {
    align-items: start;
    padding: 10px;
  }

  .confirm-modal__box {
    max-height: calc(100vh - 20px);
    padding: 16px;
  }

  .confirm-modal__box h2 {
    font-size: 24px;
  }

  .confirm-details div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .form-actions.between {
    display: grid;
    grid-template-columns: 1fr;
  }

  .hero,
  .section-head,
  .search {
    display: grid;
  }

  .metrics,
  .bank-columns,
  .role-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 9px 7px;
  }
}
