:root {
  --bg: #f2f2f2;
  --panel: #fff;
  --ink: #111;
  --muted: #666;
  --line: #d0d0d0;
  --nav: #111;
  --nav-text: #cfcfcf;
  --nav-active: #fff;
  --accent: #111;
  --accent-ink: #fff;
  --danger: #333;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  --side-w: 156px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 420px);
  padding: 32px;
}

.auth-card h1 {
  margin: 18px 0 4px;
  font-size: 24px;
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.auth-form .btn {
  justify-self: start;
  margin-top: 4px;
}

.form-error {
  margin: 18px 0 0;
  color: #9b1c1c;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}

.side {
  display: flex;
  flex-direction: column;
  background: var(--nav);
  color: var(--nav-text);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-name {
  margin: 0;
  color: var(--nav-active);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 10px;
  opacity: 0.7;
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 36px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: transparent;
  color: var(--nav-active);
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group-line {
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-label {
  margin: 0 0 4px;
  padding: 0 8px;
  color: rgba(215, 221, 216, 0.55);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--nav-text);
  font-size: 13px;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--nav-active);
}

.nav a.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--nav-active);
  font-weight: 600;
}

.side-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  opacity: 0.65;
}

.side-foot p {
  margin: 8px 0 0;
}

.logout-link {
  color: var(--nav-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.top {
  display: block;
  padding: 28px 32px 18px;
}

.top-heading {
  min-width: 0;
}

.top-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.page-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.page-lead {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.content {
  padding: 0 32px 32px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.panel-pad {
  padding: 20px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.search {
  width: min(320px, 100%);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #e6e6e6;
  color: var(--ink);
  cursor: pointer;
}

.btn:hover {
  background: #d4d4d4;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: #000;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
}

.btn-ghost:hover {
  background: #ebebeb;
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: flex-end;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:hover {
  background: #ebebeb;
}

.icon-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(50%);
  padding: 4px 8px;
  border-radius: 4px;
  background: #111;
  color: #fff;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 5;
}

.icon-btn[data-tip]:hover::after,
.icon-btn[data-tip]:focus-visible::after {
  opacity: 1;
}

.inline-form {
  display: inline;
  margin: 0;
}

.doc-number {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.doc-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
  width: 100%;
}

.doc-row-actions .btn,
.doc-row-actions .btn-disabled,
.doc-row-actions .icon-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.doc-row-actions .btn-sm,
.doc-row-actions .btn-disabled {
  min-height: 28px;
  padding: 0 8px;
}

.doc-row-actions .inline-form {
  display: inline-flex;
  margin: 0;
}

.btn-disabled {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f3f3f3;
  color: #999;
  font-size: 12px;
  cursor: default;
}

.doc-form {
  margin-bottom: 24px;
}

.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 12px;
  margin-bottom: 16px;
}

.doc-lines-wrap {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.doc-lines-head,
.doc-line {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 88px 72px 100px 100px 36px;
  gap: 8px;
  align-items: center;
}

.doc-lines-head {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
}

.doc-line {
  margin-bottom: 6px;
}

.doc-line input {
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.doc-line input[readonly] {
  background: #f5f5f5;
  text-align: right;
}

.doc-lines-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.doc-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
}

.doc-note-field {
  margin-bottom: 14px;
}

.doc-note-field textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
}

.doc-form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.month-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.month-jump {
  margin: 0;
}

.month-input {
  width: 148px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
}

.cash-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px 24px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.cash-opening {
  display: flex;
  align-items: end;
  gap: 8px;
}

.cash-opening label {
  display: grid;
  gap: 4px;
}

.cash-opening span,
.cash-stat span {
  color: var(--muted);
  font-size: 11px;
}

.cash-opening input {
  width: 120px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-weight: 600;
}

.cash-stat {
  display: grid;
  gap: 4px;
  min-width: 100px;
}

.cash-stat strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.cash-stat-main strong {
  font-size: 20px;
}

.account-form,
.expense-form {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.account-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.account-field-name {
  flex: 1 1 280px;
}

.account-side {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.account-side legend {
  padding: 0;
  color: var(--muted);
  font-size: 11px;
}

.account-side-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 10px;
  margin-top: 6px;
  font-size: 13px;
  cursor: pointer;
}

.account-block {
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.account-block > summary {
  display: block;
  list-style: none;
  cursor: pointer;
}

.account-block > summary::-webkit-details-marker {
  display: none;
}

.account-row {
  display: grid;
  grid-template-columns: 16px minmax(120px, 1fr) 56px 56px 72px;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  font-size: 13px;
}

.account-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
}

.account-toggle::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #666;
}

.account-block[open] .account-toggle::before {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #666;
  border-bottom: 0;
}

.account-name {
  font-weight: 600;
}

.rule-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
}

.rule-item {
  display: grid;
  grid-template-columns: 16px minmax(120px, 1fr) 72px;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}

.rule-payee {
  grid-column: 2;
  font-weight: 500;
}

.rule-item > .row-actions {
  grid-column: 3;
}

.rule-empty-item {
  padding: 4px 0 4px 24px;
  font-size: 12px;
  list-style: none;
}

.rule-item-edit {
  grid-template-columns: 16px 1fr;
  padding-top: 8px;
  padding-bottom: 8px;
}

.rule-item-add {
  list-style: none;
  padding: 6px 0 10px 24px;
}

.rule-add-panel {
  margin: 0;
}

.rule-add-panel > summary {
  list-style: none;
}

.rule-add-panel > summary::-webkit-details-marker {
  display: none;
}

.rule-add-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.rule-add-toggle:hover {
  background: #ebebeb;
}

.rule-add-panel[open] > .rule-add-toggle {
  margin-bottom: 8px;
}

.rule-add-form,
.rule-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rule-item-edit .rule-edit-form {
  grid-column: 2;
}

.rule-add-form input,
.rule-edit-form input {
  flex: 1 1 180px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.cash-head,
.cash-row {
  display: grid;
  grid-template-columns: 78px 88px minmax(220px, 2.4fr) 72px 72px 88px 64px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.35;
}

.cash-head {
  color: var(--muted);
  font-size: 11px;
}

.cash-row-open {
  background: #f0f0f0;
  padding-left: 0;
  padding-right: 0;
}

.cash-row .num,
.cash-head .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cash-summary-cell {
  display: grid;
  gap: 2px;
  min-width: 0;
}

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

.cash-memo {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cash-total {
  padding-right: 64px;
}

.expense-form-row {
  display: grid;
  grid-template-columns: 128px minmax(160px, 1.6fr) 118px 88px 120px auto;
  gap: 8px;
  align-items: end;
}

.expense-field {
  position: relative;
  display: grid;
  gap: 4px;
  min-width: 0;
}

.suggest-box {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.suggest-item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: #fff;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}

.suggest-item:hover,
.suggest-item:focus {
  background: #2a2a2a;
}

.expense-field span {
  color: var(--muted);
  font-size: 11px;
}

.expense-field input,
.expense-field select,
.doc-meta-grid select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.expense-field input[type="date"] {
  min-width: 0;
}

.expense-form-actions {
  display: flex;
  gap: 6px;
  padding-bottom: 1px;
}

.expense-list {
  border-top: 1px solid var(--line);
}

.expense-head,
.expense-row {
  display: grid;
  grid-template-columns: 110px minmax(160px, 1.6fr) 120px 110px 120px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.expense-head {
  padding-top: 0;
  color: var(--muted);
  font-size: 12px;
}

.expense-row .muted {
  display: inline;
  margin-left: 6px;
  font-size: 12px;
}

.expense-row .num,
.expense-head .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.expense-empty {
  margin: 0;
  padding: 18px 0;
  color: var(--muted);
}

.expense-total {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 16px;
  padding: 12px 120px 4px 0;
  border-top: 1px solid var(--ink);
  margin-top: -1px;
}

.expense-total-label {
  font-size: 13px;
  font-weight: 600;
}

.expense-total-value {
  min-width: 110px;
  text-align: right;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 48px 24px;
  text-align: center;
}

.empty-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.empty-text {
  margin: 0 0 18px;
  color: var(--muted);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

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

.card {
  padding: 18px 18px 16px;
}

.card-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.card-value {
  margin: 8px 0 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.list-head {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1fr 0.8fr 0.8fr;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.list-row {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1fr 0.8fr 0.8fr;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.docs-list {
  border-top: 1px solid var(--line);
}

.docs-list .list-head,
.docs-list .list-row {
  padding-left: 0;
  padding-right: 0;
  background: transparent;
}

.list-head.list-docs-head,
.list-row.list-docs-row {
  grid-template-columns: 64px 72px minmax(0, 2.2fr) minmax(0, 1fr) 72px 320px;
  gap: 8px;
}

.list-docs-row > .doc-primary,
.list-docs-row > .doc-secondary {
  display: contents;
}

.list-docs-row .doc-number { order: 1; }
.list-docs-row .doc-date { order: 2; }
.list-docs-row .doc-client { order: 3; }
.list-docs-row .doc-title { order: 4; }
.list-docs-row .num { order: 5; }
.list-docs-row .doc-row-actions { order: 6; }

.list-docs-head > span:nth-child(5),
.list-docs-row .num,
.list-docs-head > span:last-child {
  text-align: right;
}

.list-docs-row .doc-number,
.list-docs-row .doc-date,
.list-docs-row .doc-client,
.list-docs-row .doc-title,
.list-docs-row .num {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-date {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.doc-title {
  min-width: 0;
}

.doc-client {
  font-weight: 600;
}

.client-form-panel > summary {
  list-style: none;
  cursor: pointer;
}

.client-form-panel > summary::-webkit-details-marker {
  display: none;
}

.client-form-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-bottom: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
}

.client-form-panel[open] > .client-form-toggle {
  margin-bottom: 12px;
}

.client-form-toggle:hover {
  background: #ebebeb;
}

.client-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: end;
}

.client-field-address {
  grid-column: 1 / -1;
}

.client-form-actions {
  grid-column: 1 / -1;
}

.client-search-form {
  flex: 1 1 auto;
  min-width: 0;
}

.client-list-head,
.client-list-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) 90px 120px minmax(160px, 1.6fr) 72px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.client-list-head {
  color: var(--muted);
  font-size: 12px;
}

.client-list-row:last-child {
  border-bottom: 0;
}

.client-list-row strong {
  display: block;
  font-weight: 600;
}

.client-sub {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.client-address {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.list-row:last-child {
  border-bottom: 0;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #ececec;
  font-size: 12px;
}

.stack {
  display: grid;
  gap: 14px;
}

.mt-14 {
  margin-top: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field-full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 13px;
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.form-field textarea {
  min-height: 88px;
  resize: vertical;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.flash {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bdbdbd;
  border-radius: 8px;
  background: #f5f5f5;
}

.flash-error {
  border-color: #999;
  background: #ececec;
}

.settings-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.settings-lead {
  margin: 0 0 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.settings-span-2 {
  grid-column: 1 / -1;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.settings-form textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
}

.settings-window-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.settings-window-nudge {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-window-stage {
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #d8d8d8;
}

.settings-sheet {
  position: relative;
  width: 210mm;
  height: 70mm;
  margin: 0 auto;
  background: #fff;
  transform-origin: top center;
  transform: scale(0.72);
  margin-bottom: -18mm;
}

.settings-window-guide {
  position: absolute;
  left: 22mm;
  top: 12mm;
  width: 90mm;
  height: 45mm;
  border: 0.4mm dashed #c0392b;
  color: #c0392b;
  font-size: 8pt;
}

.settings-window-guide span {
  position: absolute;
  top: -4.2mm;
  left: 0;
}

.settings-client-sample {
  position: absolute;
  left: var(--client-x);
  top: var(--client-y);
  width: 78mm;
  margin: 0;
  font-size: 10pt;
  line-height: 1.35;
}

.settings-client-sample p {
  margin: 0;
}

.settings-client-name {
  margin-bottom: 3mm;
  font-size: 12pt;
  font-weight: 600;
}

.settings-stamp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
}

.settings-stamp-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.settings-stamp-preview img {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
}

.settings-stamp-form {
  flex: 1 1 220px;
  min-width: 0;
}

.report-table {
  margin-top: 10px;
}

.report-head,
.report-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 80px 120px;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.report-head {
  color: var(--muted);
  font-size: 12px;
}

.report-row:last-child {
  border-bottom: 0;
}

.menu-backdrop {
  display: none;
}

@media (max-width: 960px) {
  html,
  body {
    overflow-x: hidden;
  }

  body.menu-open {
    overflow: hidden;
  }

  .app {
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
  }

  .side {
    position: sticky;
    top: 0;
    z-index: 30;
    flex: 0 0 auto;
  }

  .brand {
    min-height: 56px;
  }

  .menu-toggle {
    display: flex;
  }

  .nav,
  .side-foot {
    display: none;
  }

  .side.is-open .nav,
  .side.is-open .side-foot {
    display: flex;
  }

  .side.is-open .nav {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    flex-direction: column;
    gap: 8px;
    max-height: none;
    padding: 12px 12px 88px;
    overflow-y: auto;
    background: var(--nav);
  }

  .side.is-open .side-foot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    display: block;
    margin: 0;
    background: var(--nav);
  }

  .menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: none;
    background: rgba(0, 0, 0, 0.35);
  }

  body.menu-open .menu-backdrop:not([hidden]) {
    display: block;
  }

  .nav a {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 15px;
  }

  .main,
  .content,
  .panel {
    min-width: 0;
    max-width: 100%;
  }

  .top,
  .content {
    padding-left: 14px;
    padding-right: 14px;
  }

  .top {
    padding-top: 18px;
    padding-bottom: 12px;
  }

  .top-title-row {
    align-items: flex-start;
    gap: 8px;
  }

  .page-title {
    font-size: 20px;
    line-height: 1.3;
    word-break: break-word;
  }

  .top .actions {
    padding-top: 2px;
  }

  .top .actions .btn {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

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

  .form-grid,
  .settings-grid,
  .client-form-grid,
  .doc-meta-grid {
    grid-template-columns: 1fr;
  }

  .settings-span-2,
  .client-field-address,
  .client-form-actions {
    grid-column: auto;
  }

  .doc-lines-head,
  .doc-line {
    grid-template-columns: 1fr 1fr;
  }

  .doc-lines-head span:nth-child(n + 3),
  .doc-line > :nth-child(n + 3) {
    grid-column: auto;
  }

  .list-head.list-docs-head,
  .client-list-head,
  .cash-head,
  .expense-head {
    display: none;
  }

  .list-row.list-docs-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
  }

  .list-docs-row > .doc-primary,
  .list-docs-row > .doc-secondary {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
    width: 100%;
  }

  .list-docs-row .doc-date {
    flex: 0 0 auto;
    font-size: 12px;
  }

  .list-docs-row .doc-client {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 600;
  }

  .list-docs-row .doc-title {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
    font-size: 12px;
  }

  .list-docs-row .num {
    flex: 0 0 auto;
    margin-left: auto;
    overflow: visible;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
  }

  .list-docs-row .doc-number {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 42%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .list-docs-row .doc-row-actions {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    min-width: 0;
    width: auto;
    max-width: none;
    margin-left: auto;
    padding-top: 0;
    overflow: visible;
  }

  .doc-row-actions .btn,
  .doc-row-actions .btn-disabled,
  .doc-row-actions .btn-sm,
  .doc-row-actions .icon-btn {
    min-height: 28px;
  }

  .client-list-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "name name actions"
      "person phone address";
    gap: 2px 8px;
    padding: 8px 0;
    align-items: center;
  }

  .client-list-row > :nth-child(1) {
    grid-area: name;
    min-width: 0;
  }

  .client-list-row > :nth-child(2) {
    grid-area: person;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .client-list-row > :nth-child(3) {
    grid-area: phone;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
  }

  .client-list-row > :nth-child(4) {
    grid-area: address;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: right;
  }

  .client-list-row > .row-actions {
    grid-area: actions;
    justify-content: flex-end;
  }

  .client-list-row .client-sub {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .cash-row,
  .expense-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-areas:
      "date payee memo amount"
      "account account balance actions";
    gap: 2px 6px;
    padding: 8px 0;
    align-items: center;
  }

  .cash-row > .cash-date {
    grid-area: date;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
  }

  .cash-row > .cash-account {
    grid-area: account;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 12px;
    color: var(--muted);
  }

  .cash-row > .cash-summary-cell {
    display: contents;
  }

  .cash-row .cash-payee {
    grid-area: payee;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
  }

  .cash-row .cash-memo {
    grid-area: memo;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
  }

  .cash-row > .cash-debit:empty,
  .cash-row > .cash-credit:empty {
    display: none;
  }

  .cash-row > .cash-debit,
  .cash-row > .cash-credit {
    grid-area: amount;
    justify-self: end;
    text-align: right;
    font-weight: 600;
    white-space: nowrap;
  }

  .cash-row > .cash-balance {
    grid-area: balance;
    justify-self: end;
    text-align: right;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
  }

  .cash-row > .row-actions {
    grid-area: actions;
    justify-self: end;
  }

  .cash-row-open {
    grid-template-areas:
      "account account account amount"
      "memo memo memo memo";
  }

  .cash-row-open > :nth-child(1):empty,
  .cash-row-open > :nth-child(4):empty,
  .cash-row-open > :nth-child(5):empty,
  .cash-row-open > :nth-child(7):empty {
    display: none;
  }

  .cash-row-open > :nth-child(2) {
    grid-area: account;
    font-size: 12px;
    font-weight: 600;
    color: inherit;
  }

  .cash-row-open > :nth-child(3) {
    grid-area: memo;
    color: var(--muted);
    font-size: 12px;
  }

  .cash-row-open > :nth-child(6) {
    grid-area: amount;
    justify-self: end;
    text-align: right;
    font-size: 14px;
    font-weight: 600;
    color: inherit;
  }

  .expense-row > :nth-child(2),
  .expense-row > :nth-child(5) {
    grid-column: 1 / -1;
  }

  .cash-total,
  .expense-total {
    padding-right: 0;
  }

  .expense-form-row {
    grid-template-columns: 1fr 1fr;
  }

  .expense-form-actions {
    justify-content: flex-start;
  }

  .account-row {
    grid-template-columns: 16px minmax(0, 1fr) auto auto auto;
    gap: 6px;
    padding: 8px 0;
  }

  .account-row > .row-actions {
    grid-column: auto;
    justify-content: flex-end;
    padding-left: 0;
  }

  .rule-item {
    grid-template-columns: 16px minmax(0, 1fr) 64px;
  }

  .rule-item > .row-actions {
    min-width: 0;
  }

  .report-head,
  .report-row {
    grid-template-columns: minmax(0, 1fr) 70px 100px;
  }

  .list-head:not(.list-docs-head):not(.client-list-head),
  .list-row:not(.list-docs-row):not(.client-list-row) {
    grid-template-columns: 1fr 1fr;
  }

  .panel,
  .panel-pad,
  .settings-form,
  .settings-grid,
  .auth-card {
    overflow-x: hidden;
  }
}
