:root {
  color-scheme: light;
  --balances-red: #e4002b;
  --balances-red-dark: #b90024;
  --balances-ink: #17191d;
  --balances-muted: #69707d;
  --balances-line: #dfe3ea;
  --balances-soft: #f5f6f8;
  --balances-green: #15803d;
  --balances-green-soft: #dcfce7;
  --balances-red-soft: #fee2e2;
  --balances-shadow: 0 1px 2px rgba(23, 25, 29, 0.04), 0 10px 28px rgba(23, 25, 29, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: transparent;
  color: var(--balances-ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

button {
  cursor: pointer;
}

.balances-app {
  display: grid;
  gap: 18px;
  max-width: 100%;
  min-width: 0;
  padding: 1px;
  overflow-x: hidden;
}

.balances-header,
.panel {
  background: #fff;
  border: 1px solid var(--balances-line);
  border-radius: 8px;
  box-shadow: var(--balances-shadow);
}

.balances-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 96px;
  padding: 20px;
  border-top: 4px solid var(--balances-red);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--balances-red);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.balances-header p:last-child {
  margin-bottom: 0;
  color: var(--balances-muted);
  font-weight: 750;
}

.sync-chip {
  flex: 0 0 auto;
  min-width: 148px;
  padding: 10px 12px;
  border: 1px solid var(--balances-line);
  border-radius: 999px;
  background: var(--balances-soft);
  color: var(--balances-muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.sync-chip[data-state="synced"] {
  background: var(--balances-green-soft);
  border-color: #86efac;
  color: #166534;
}

.sync-chip[data-state="loading"] {
  background: #fef3c7;
  border-color: #fbbf24;
  color: #92400e;
}

.sync-chip[data-state="error"] {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.balances-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  min-width: 0;
}

.panel {
  min-width: 0;
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--balances-ink);
  font-size: 0.9rem;
  font-weight: 900;
}

input,
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--balances-ink);
  padding: 0 13px;
  font-weight: 800;
}

input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  line-height: 48px;
  text-align: center;
}

input:focus,
select:focus {
  border-color: var(--balances-red);
  box-shadow: 0 0 0 3px rgba(228, 0, 43, 0.12);
  outline: none;
}

.new-client-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--balances-line);
}

.balance-card {
  display: grid;
  gap: 5px;
  margin-top: 16px;
  padding: 18px;
  border-radius: 8px;
  background: #17191d;
  color: #fff;
}

.balance-card span,
.balance-card small {
  color: #b9bec7;
  font-weight: 850;
}

.balance-card strong {
  color: #fff;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1;
}

.balance-card strong.negative,
.client-card b.negative {
  color: #ff8da0;
}

.movement-form {
  display: grid;
  gap: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.field-row + .field-row {
  grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.3fr);
}

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

.primary-button,
.secondary-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 900;
}

.primary-button {
  background: var(--balances-red);
  color: #fff;
}

.primary-button:hover {
  background: var(--balances-red-dark);
}

.danger-button {
  background: var(--balances-red);
  color: #fff;
}

.secondary-button {
  border-color: #cbd5e1;
  background: #fff;
  color: var(--balances-ink);
}

.secondary-button:hover {
  background: #f8fafc;
}

.overview-panel,
.history-panel {
  min-width: 0;
}

.search-field {
  min-width: min(380px, 100%);
}

.client-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
}

.client-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  border: 1px solid var(--balances-line);
  border-left: 4px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
}

.client-card.active {
  border-color: #111318;
  border-left-color: var(--balances-red);
  box-shadow: 0 0 0 3px rgba(23, 25, 29, 0.08);
}

.client-card strong,
.client-card small {
  display: block;
  overflow-wrap: anywhere;
}

.client-card small {
  margin-top: 3px;
  color: var(--balances-muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.client-card b {
  flex: 0 0 auto;
  font-size: 1.15rem;
  white-space: nowrap;
}

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

.movement-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--balances-line);
  border-left: 5px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.movement-card.credit {
  border-left-color: var(--balances-green);
  background: var(--balances-green-soft);
}

.movement-card.debit {
  border-left-color: var(--balances-red);
  background: var(--balances-red-soft);
}

.movement-card strong,
.movement-card span,
.movement-card p {
  display: block;
  overflow-wrap: anywhere;
}

.movement-card span,
.movement-card p {
  color: var(--balances-muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.movement-card p {
  margin: 5px 0 0;
}

.movement-amount {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.movement-amount b {
  font-size: 1.25rem;
  white-space: nowrap;
}

.movement-amount span {
  display: flex;
  gap: 6px;
}

.movement-amount button {
  min-height: 32px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: var(--balances-ink);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 10px;
  white-space: nowrap;
}

.movement-amount button:last-child {
  color: var(--balances-red);
}

.empty-state {
  margin: 0;
  padding: 24px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--balances-muted);
  font-weight: 800;
  text-align: center;
}

.print-frame {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.balances-modal-backdrop {
  position: absolute;
  top: var(--balances-modal-top, 0);
  right: 0;
  left: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--balances-modal-height, 100vh);
  padding: 18px;
  background: rgba(17, 19, 24, 0.48);
}

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

.balances-modal-card {
  width: min(430px, 100%);
  border: 1px solid #2b3038;
  border-radius: 10px;
  background: #17191d;
  color: #fff;
  box-shadow: 0 24px 70px rgba(17, 19, 24, 0.32);
  padding: 22px;
}

.balances-modal-card h2 {
  margin-bottom: 10px;
  color: #fff;
}

.balances-modal-card p:not(.eyebrow) {
  color: #d7dbe3;
  font-weight: 750;
  line-height: 1.45;
}

.balances-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.balances-modal-card .secondary-button {
  background: #fff;
}

@media (max-width: 760px) {
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .balances-app {
    gap: 14px;
    width: 100%;
    max-width: 100%;
  }

  .balances-header,
  .panel-heading,
  .balances-grid,
  .field-row,
  .field-row + .field-row,
  .movement-card {
    display: grid;
    grid-template-columns: 1fr;
  }

  .balances-header {
    min-height: 0;
    padding: 16px;
  }

  h1 {
    font-size: 2rem;
  }

  .sync-chip {
    min-width: 0;
    width: 100%;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    padding: 16px;
  }

  input,
  select,
  input[type="date"] {
    height: 48px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  select {
    line-height: 48px;
  }

  input[type="date"] {
    padding-top: 0;
    padding-bottom: 0;
    text-align: center;
  }

  input[type="date"]::-webkit-date-and-time-value {
    min-height: 48px;
    line-height: 48px;
    text-align: center;
  }

  .form-actions,
  .movement-amount,
  .movement-amount span {
    justify-items: stretch;
    justify-content: stretch;
  }

  .form-actions button,
  .movement-amount button {
    width: 100%;
  }

  .movement-amount span {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    display: grid;
    width: 100%;
  }

  .movement-amount button {
    min-width: 0;
    white-space: nowrap;
  }

  .movement-amount {
    justify-items: start;
    min-width: 0;
    width: 100%;
  }

  .movement-amount b {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .client-list {
    grid-template-columns: 1fr;
  }

  .balances-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
