:root {
  --background: #ffffff;
  --surface: #f6f7f8;
  --text: #17191c;
  --muted: #656b73;
  --border: #dfe2e5;
  --border-strong: #b9bec4;
  --accent: #1d5fa7;
  --danger: #a92d2d;
  --success: #227448;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
  color: var(--text);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 10;
  padding: 8px 10px;
  transform: translateY(-150%);
  background: var(--text);
  color: #fff;
}

.skip-link:focus {
  transform: none;
}

.topbar {
  border-bottom: 1px solid var(--border);
}

.topbar-inner,
main {
  width: min(1080px, calc(100% - 32px));
  margin-inline: auto;
}

.topbar-inner {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-actions,
.footer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

main {
  padding-block: 24px 48px;
}

.button {
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.button:hover:not(:disabled) {
  border-color: #777e86;
  background: var(--surface);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

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

.button-primary:hover:not(:disabled) {
  border-color: #164b85;
  background: #164b85;
}

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

.button-quiet {
  border-color: transparent;
  color: var(--muted);
}

.message-panel,
.editor-panel {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}

.message-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.message-panel span {
  color: var(--muted);
}

.message-panel .button {
  margin-left: auto;
}

.editor-panel {
  margin-bottom: 16px;
  padding: 12px;
}

.editor-panel form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-panel label {
  font-size: 13px;
  font-weight: 700;
}

.editor-panel input {
  width: min(280px, 45vw);
  height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
}

.form-message,
.notice {
  min-height: 0;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message:not(:empty) {
  margin-top: 8px;
}

.form-message[data-tone="error"],
.notice[data-tone="error"] {
  color: var(--danger);
}

.notice[data-tone="success"] {
  color: var(--success);
}

.totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.total,
.total-placeholder {
  min-width: 0;
  padding: 12px 14px;
  border-right: 1px solid var(--border);
}

.total:last-child,
.total-placeholder:last-child {
  border-right: 0;
}

.total-bank {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
  font-weight: 700;
}

.total-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.total-count {
  color: var(--muted);
  font-size: 12px;
}

.total-amount,
.amount {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.total-amount {
  font-size: 15px;
}

.total-placeholder {
  color: var(--muted);
  font-size: 12px;
}

.record-tools {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-strong);
}

.record-tools label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.record-tools select {
  height: 32px;
  padding: 4px 28px 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
}

.record-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.notice:not(:empty) {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

th:first-child,
td:first-child {
  width: 165px;
  padding-left: 0;
}

th:nth-child(2),
td:nth-child(2) {
  width: 110px;
}

.amount-column,
.amount-cell {
  width: 130px;
  text-align: right;
}

.actions-column,
.actions-cell {
  width: 132px;
  padding-right: 0;
  text-align: right;
}

.table-wrap:not(.editor-enabled) .actions-column,
.table-wrap:not(.editor-enabled) .actions-cell {
  display: none;
}

.date {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bank {
  font-weight: 650;
}

.detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-empty {
  color: var(--muted);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.row-actions .button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.edit-input,
.edit-select {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: #fff;
}

.edit-input[type="number"] {
  text-align: right;
}

.editing-row td {
  background: var(--surface);
}

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

.footer-actions {
  justify-content: center;
  padding-top: 14px;
}

.noscript {
  margin: 16px;
  padding: 12px;
  border: 1px solid var(--danger);
  color: var(--danger);
}

@media (max-width: 720px) {
  .topbar-inner,
  main {
    width: min(100% - 20px, 1080px);
  }

  .topbar-inner {
    min-height: 52px;
  }

  .topbar-actions {
    gap: 2px;
  }

  .topbar-actions .button {
    padding-inline: 7px;
  }

  main {
    padding-top: 14px;
  }

  .totals {
    grid-template-columns: 1fr;
  }

  .total,
  .total-placeholder {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .total:last-child,
  .total-placeholder:last-child {
    border-bottom: 0;
  }

  .total {
    display: grid;
    grid-template-columns: 90px 1fr;
    align-items: center;
  }

  .total-bank {
    margin: 0;
  }

  .message-panel,
  .editor-panel form {
    align-items: stretch;
    flex-direction: column;
  }

  .message-panel .button {
    margin-left: 0;
  }

  .editor-panel input {
    width: 100%;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  td,
  th:first-child,
  td:first-child,
  th:nth-child(2),
  td:nth-child(2),
  .amount-cell,
  .actions-cell {
    width: auto;
    padding: 0;
    border: 0;
    text-align: left;
  }

  .date-cell {
    grid-column: 1;
    grid-row: 1;
  }

  .bank-cell {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
  }

  .detail-cell {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }

  .amount-cell {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  .actions-cell {
    grid-column: 1 / -1;
    grid-row: 3;
    padding-top: 4px;
  }

  .editing-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--surface);
  }

  .editing-row td {
    display: grid;
    grid-column: 1;
    grid-row: auto;
    grid-template-columns: 80px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    background: transparent;
  }

  .editing-row td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
  }

  .editing-row .actions-cell {
    display: block;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 14px;
  }

  #refresh {
    display: none;
  }
}
