:root {
  color-scheme: light;
  --ink: #17231f;
  --ink-soft: #34443f;
  --muted: #6a7772;
  --bg: #eef2ef;
  --surface: #ffffff;
  --surface-soft: #f6f8f7;
  --line: #dce4e0;
  --line-strong: #c7d2cd;
  --brand: #176b5d;
  --brand-dark: #173d35;
  --brand-soft: #e5f2ee;
  --receipt: #14755d;
  --receipt-soft: #e6f4ef;
  --payment: #b53f3b;
  --payment-soft: #faeae8;
  --contract: #946612;
  --contract-soft: #faf1df;
  --blue: #28658c;
  --blue-soft: #e8f1f7;
  --warning: #8b5c0a;
  --danger: #b53f3b;
  --shadow: 0 14px 38px rgba(27, 51, 44, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body.dialog-open {
  overflow: hidden;
}

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

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(23, 107, 93, 0.24);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.svg-defs {
  position: fixed;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

h1,
h2,
h3 {
  color: var(--ink);
}

button {
  border: 0;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.danger-text-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 7px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 3px 8px rgba(23, 107, 93, 0.15);
}

.primary-button:hover {
  border-color: #105b4e;
  background: #105b4e;
}

.primary-button.receipt-button {
  border-color: var(--receipt);
  background: var(--receipt);
}

.primary-button.payment-button {
  border-color: var(--payment);
  background: var(--payment);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
}

.secondary-button:hover {
  border-color: #aebdb7;
  background: var(--surface-soft);
}

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}

.text-button,
.danger-text-button {
  min-height: 34px;
  padding: 5px 7px;
  background: transparent;
  color: var(--brand);
}

.text-button:hover {
  background: var(--brand-soft);
}

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

.danger-text-button:hover {
  background: var(--payment-soft);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button {
  position: relative;
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--brand);
}

.icon-button[data-tooltip]::after {
  position: absolute;
  z-index: 50;
  top: calc(100% + 7px);
  right: 0;
  width: max-content;
  max-width: 160px;
  padding: 5px 8px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  content: attr(data-tooltip);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: 0.14s ease;
}

.icon-button[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateY(0);
}

.pill {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--receipt-soft);
  color: var(--receipt);
  font-size: 12px;
  font-weight: 800;
}

.status-badge.muted {
  background: #eff2f1;
  color: var(--muted);
}

.login-screen {
  display: grid;
  min-height: 100dvh;
  padding: 28px;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(23, 61, 53, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(23, 61, 53, 0.06) 1px, transparent 1px),
    #f3f5f2;
  background-size: 28px 28px;
}

.login-column {
  width: min(100%, 460px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
  background: var(--brand-dark);
  color: #f7f0db;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
  font-size: 25px;
  font-weight: 900;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 18px;
}

.login-brand h1 {
  margin: 0;
  font-size: 27px;
  line-height: 1.1;
}

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

.login-heading {
  margin-bottom: 23px;
}

.login-heading h2 {
  margin: 0 0 7px;
  font-size: 24px;
  line-height: 1.2;
}

.login-heading > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.login-method-switch {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 19px;
}

.login-method-switch button {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.login-method-switch .pill {
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-fields {
  display: grid;
  gap: 15px;
}

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

.field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.field > span:first-child {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

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

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 8px 10px;
}

textarea {
  padding: 9px 10px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #99a49f;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 93, 0.1);
}

input[type="checkbox"] {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}

.password-wrap {
  position: relative;
  display: block;
}

.password-wrap input {
  padding-right: 58px;
}

.password-toggle {
  position: absolute;
  top: 4px;
  right: 4px;
  min-height: 34px;
}

.sms-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 8px;
}

.sms-send-button {
  min-height: 42px;
  padding-inline: 10px;
  white-space: nowrap;
}

.login-button {
  min-height: 46px;
  font-size: 15px;
}

.qr-login-button {
  min-height: 46px;
}

.qr-login-button .pill {
  margin-left: auto;
}

.login-footnote {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.login-footnote .icon {
  color: var(--brand);
}

.form-error {
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  background: var(--payment-soft);
  color: #8f302d;
  font-size: 12px;
}

.form-note {
  margin: 0;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  z-index: 40;
  top: 0;
  display: flex;
  height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 9px 22px;
  border-bottom: 1px solid rgba(220, 228, 224, 0.95);
  background: rgba(251, 252, 251, 0.97);
}

.topbar-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.topbar-brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.15;
}

.topbar-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.mobile-menu-button {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.account-menu-wrap {
  position: relative;
}

.account-menu-button {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.account-menu-button:hover,
.account-menu-button[aria-expanded="true"] {
  border-color: var(--line);
  background: var(--surface-soft);
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 14px;
  font-weight: 850;
}

.account-label {
  display: grid;
  min-width: 70px;
  text-align: left;
}

.account-label strong {
  font-size: 13px;
  line-height: 1.2;
}

.account-label small {
  color: var(--muted);
  font-size: 10px;
}

.account-menu-button .chevron {
  width: 15px;
  color: var(--muted);
}

.account-menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 8px);
  right: 0;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-menu-head {
  display: grid;
  gap: 2px;
  padding: 9px 10px 11px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

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

.account-menu button {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.account-menu button:hover {
  background: var(--surface-soft);
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100dvh - 70px);
}

.sidebar {
  position: sticky;
  top: 70px;
  display: flex;
  height: calc(100dvh - 70px);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f8faf8;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 17px 12px;
}

.nav-label {
  margin: 15px 10px 7px;
  color: #8a9691;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.nav-label:first-child {
  margin-top: 0;
}

.main-nav {
  display: grid;
  gap: 3px;
}

.nav-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.nav-button:hover {
  background: #eef2ef;
}

.nav-button.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
}

.receipt-nav.active {
  background: var(--receipt-soft);
  color: var(--receipt);
}

.payment-nav.active {
  background: var(--payment-soft);
  color: var(--payment);
}

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #21a779;
  box-shadow: 0 0 0 3px rgba(33, 167, 121, 0.12);
}

.sidebar-account div {
  display: grid;
  gap: 1px;
}

.sidebar-account strong {
  font-size: 11px;
}

.sidebar-account small {
  color: var(--muted);
  font-size: 9px;
}

.main-content {
  min-width: 0;
  padding: 25px max(22px, calc((100vw - 220px - 1220px) / 2)) 50px;
}

.initial-password-banner {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 15px;
  padding: 9px 12px;
  border: 1px solid #ecd7a7;
  border-radius: 7px;
  background: var(--contract-soft);
  color: #6e4d0e;
  font-size: 12px;
}

.initial-password-banner span {
  flex: 1;
}

.view {
  max-width: 1200px;
  margin: 0 auto;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.page-heading h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.page-heading > div > p:last-child {
  max-width: 640px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.heading-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 8px;
}

.compact-field {
  display: grid;
  min-width: 125px;
  gap: 4px;
}

.compact-field span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.compact-field input,
.compact-field select {
  min-height: 40px;
  font-size: 13px;
}

.compact-field.grow {
  min-width: 220px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px;
  margin-bottom: 14px;
}

.metric-card {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 7px;
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-card > div:last-child {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.metric-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.metric-card strong {
  overflow: hidden;
  font-size: clamp(18px, 2vw, 24px);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-card small {
  color: var(--muted);
  font-size: 10px;
}

.receipt-metric {
  border-top: 3px solid var(--receipt);
}

.receipt-metric .metric-icon {
  background: var(--receipt-soft);
  color: var(--receipt);
}

.payment-metric {
  border-top: 3px solid var(--payment);
}

.payment-metric .metric-icon {
  background: var(--payment-soft);
  color: var(--payment);
}

.balance-metric {
  border-top: 3px solid var(--brand);
}

.balance-metric .metric-icon {
  background: var(--brand-soft);
  color: var(--brand);
}

.debt-metric {
  border-top: 3px solid var(--contract);
}

.debt-metric .metric-icon {
  background: var(--contract-soft);
  color: var(--contract);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.view > .panel,
.view > .account-grid,
.view > .customer-columns,
.view > .contract-metrics,
.view > .admin-tabs {
  margin-bottom: 14px;
}

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

.panel-heading h3 {
  margin: 0;
  font-size: 15px;
}

.panel-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.account-snapshot,
.contract-snapshot {
  display: grid;
  gap: 7px;
}

.snapshot-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  padding: 8px 0;
  border-bottom: 1px solid #edf1ef;
}

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

.snapshot-icon {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--brand);
}

.snapshot-row > div {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 1px;
}

.snapshot-row strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snapshot-row small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snapshot-row > b {
  flex: 0 0 auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.snapshot-row.receipt b {
  color: var(--receipt);
}

.snapshot-row.payment b {
  color: var(--payment);
}

.snapshot-row.contract b {
  color: var(--contract);
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.segmented-control button {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.segmented-control button.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(25, 50, 43, 0.12);
}

.segmented-control.large button {
  min-height: 34px;
  padding: 6px 14px;
  font-size: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}

th {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-align: left;
}

td {
  padding: 10px 9px;
  border-bottom: 1px solid #edf1ef;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fafcfb;
}

.amount-cell {
  text-align: right;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.money.receipt {
  color: var(--receipt);
}

.money.payment {
  color: var(--payment);
}

.money.contract {
  color: var(--contract);
}

.direction-badge,
.type-badge,
.invoice-badge,
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
}

.direction-badge.receipt,
.type-badge.sales {
  background: var(--receipt-soft);
  color: var(--receipt);
}

.direction-badge.payment,
.type-badge.expense {
  background: var(--payment-soft);
  color: var(--payment);
}

.type-badge.purchase {
  background: var(--contract-soft);
  color: var(--contract);
}

.invoice-badge {
  background: #eef2f1;
  color: var(--muted);
}

.invoice-badge.issued {
  background: var(--blue-soft);
  color: var(--blue);
}

.role-badge.admin {
  background: var(--brand-soft);
  color: var(--brand);
}

.role-badge.clerk {
  background: #eef2f1;
  color: var(--muted);
}

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

.row-action {
  display: inline-grid;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.row-action:hover {
  background: var(--surface-soft);
  color: var(--brand);
}

.row-action.delete:hover {
  background: var(--payment-soft);
  color: var(--payment);
}

.row-action .icon {
  width: 16px;
  height: 16px;
}

.table-subline {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.empty-state {
  display: grid;
  min-height: 180px;
  padding: 24px;
  place-items: center;
  align-content: center;
  gap: 8px;
  text-align: center;
}

.empty-state .icon {
  width: 30px;
  height: 30px;
  color: #8ca19a;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state h3 {
  font-size: 16px;
}

.empty-state p {
  color: var(--muted);
  font-size: 12px;
}

.empty-state.small {
  min-height: 90px;
  padding: 14px;
}

.ledger-panel {
  padding: 0;
  overflow: hidden;
}

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

.search-field {
  position: relative;
  display: block;
  min-width: 220px;
  max-width: 430px;
  flex: 1;
}

.search-field .icon {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.search-field input {
  min-height: 38px;
  padding-left: 34px;
  font-size: 12px;
}

.search-field.wide {
  max-width: none;
  margin-bottom: 10px;
}

.ledger-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.ledger-summary div {
  display: grid;
  gap: 1px;
}

.ledger-summary span {
  color: var(--muted);
  font-size: 9px;
}

.ledger-summary strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.ledger-summary .receipt strong {
  color: var(--receipt);
}

.ledger-summary .payment strong {
  color: var(--payment);
}

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

.account-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.account-card.inactive {
  opacity: 0.65;
}

.account-card-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.account-card-head .snapshot-icon {
  background: var(--brand-soft);
}

.account-card-head > div {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 1px;
}

.account-card-head strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card-head small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-balance {
  display: grid;
  gap: 2px;
  margin: 15px 0 11px;
}

.account-balance span {
  color: var(--muted);
  font-size: 9px;
}

.account-balance strong {
  overflow: hidden;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding-top: 10px;
  border-top: 1px solid #edf1ef;
}

.account-card-stats div {
  display: grid;
  gap: 1px;
}

.account-card-stats span {
  color: var(--muted);
  font-size: 9px;
}

.account-card-stats strong {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.account-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 9px;
}

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

.contract-metrics > div {
  display: grid;
  gap: 3px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.contract-metrics span {
  color: var(--muted);
  font-size: 10px;
}

.contract-metrics strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.contract-progress {
  min-width: 145px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 9px;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ef;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.customer-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.people-list {
  display: grid;
  gap: 6px;
}

.person-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid #edf1ef;
  border-radius: 7px;
  background: #fcfdfc;
}

.person-avatar {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.person-row.purchase .person-avatar {
  background: var(--contract-soft);
  color: var(--contract);
}

.person-row > div {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 1px;
}

.person-row strong,
.person-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-row strong {
  font-size: 12px;
}

.person-row small {
  color: var(--muted);
  font-size: 9px;
}

.person-row.inactive {
  opacity: 0.6;
}

.report-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 9px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.report-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-tabs button {
  display: inline-flex;
  min-height: 38px;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.admin-tabs button.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.backup-note {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 12px;
  padding: 13px;
  border: 1px solid #d8e7e2;
  border-radius: var(--radius);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.backup-note > .icon {
  color: var(--brand);
}

.backup-note strong {
  font-size: 13px;
}

.backup-note p {
  margin: 3px 0 0;
  color: #47665e;
  font-size: 11px;
}

.backup-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.backup-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.backup-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.backup-card-head > div {
  display: grid;
  gap: 2px;
}

.backup-card-head strong {
  font-size: 13px;
}

.backup-card-head small {
  color: var(--muted);
  font-size: 9px;
}

.backup-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  color: var(--muted);
  font-size: 10px;
}

.backup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid #edf1ef;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.user-row > div {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 2px;
}

.user-row strong {
  font-size: 13px;
}

.user-row small {
  color: var(--muted);
  font-size: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.settings-list {
  display: grid;
  gap: 9px;
}

.setting-row > div {
  display: grid;
  gap: 3px;
}

.setting-row strong {
  font-size: 13px;
}

.setting-row p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.setting-status {
  color: var(--brand-dark);
  font-size: 10px;
}

.setting-row > .backup-schedule-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
}

.backup-schedule-controls .compact-field {
  min-width: 126px;
}

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

.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #cbd4d0;
  cursor: pointer;
  transition: 0.16s ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  content: "";
  transition: 0.16s ease;
}

.switch input:checked + span {
  background: var(--brand);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.bottom-nav {
  display: none;
}

.mobile-backdrop {
  position: fixed;
  z-index: 75;
  inset: 0;
  background: rgba(13, 26, 22, 0.47);
}

.app-dialog,
.confirm-dialog {
  max-width: calc(100vw - 28px);
  max-height: calc(100dvh - 30px);
  padding: 0;
  overflow: hidden auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(14, 31, 26, 0.22);
}

.app-dialog {
  width: 680px;
}

.record-dialog {
  width: 760px;
}

.small-dialog {
  width: 460px;
}

.qr-login-dialog {
  width: 620px;
}

.app-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(14, 28, 23, 0.52);
  backdrop-filter: blur(2px);
}

.dialog-head {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 17px 19px 13px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.dialog-head h2 {
  margin: 0;
  font-size: 21px;
}

.dialog-close {
  width: 34px;
  height: 34px;
}

.dialog-body {
  display: grid;
  gap: 13px;
  padding: 17px 19px;
}

.qr-login-body {
  grid-template-columns: 238px minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  padding: 22px;
}

.qr-paper {
  display: grid;
  min-width: 0;
  padding: 12px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-paper img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.qr-placeholder {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  padding: 18px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(23, 107, 93, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(23, 107, 93, 0.035) 1px, transparent 1px),
    var(--surface-soft);
  background-size: 16px 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.qr-placeholder.is-error {
  border-color: #e5bcb9;
  background: var(--payment-soft);
  color: var(--danger);
}

.qr-login-copy {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.qr-lead,
.qr-note {
  margin: 0;
  font-size: 13px;
}

.qr-lead {
  color: var(--ink-soft);
}

.qr-address {
  display: grid;
  gap: 5px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  background: var(--surface-soft);
}

.qr-address span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.qr-address code {
  overflow-wrap: anywhere;
  color: var(--brand-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

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

.qr-login-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.qr-login-actions .secondary-button {
  flex: 1 1 160px;
}

.qr-open-link {
  min-height: 40px;
  border: 1px solid transparent;
  text-decoration: none;
}

.qr-network {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--warning);
  font-size: 11px;
}

.qr-network .icon {
  width: 17px;
  height: 17px;
}

.qr-copy-source {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.dialog-actions {
  position: sticky;
  z-index: 2;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 19px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.action-spacer {
  flex: 1;
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.check-row {
  display: flex;
  min-height: 30px;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
}

.compact-check {
  align-self: end;
  padding-bottom: 7px;
}

.picker-field {
  position: relative;
}

.picker-suggestions {
  position: absolute;
  z-index: 70;
  top: calc(100% + 3px);
  right: 0;
  left: 0;
  max-height: 230px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.picker-option {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
}

.picker-option:hover,
.picker-option.highlighted {
  background: var(--brand-soft);
}

.picker-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-option small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 9px;
}

.picker-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.contract-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid #e9dcc1;
  border-radius: 7px;
  background: #e9dcc1;
}

.contract-preview > div {
  display: grid;
  gap: 2px;
  padding: 9px;
  background: var(--contract-soft);
}

.contract-preview span {
  color: #80642e;
  font-size: 9px;
}

.contract-preview strong {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.form-details {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.form-details summary {
  padding: 10px 12px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.details-content {
  padding: 0 12px 12px;
}

.attachment-field {
  display: grid;
  gap: 8px;
}

.attachment-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.attachment-title > span {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

.attachment-title small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 400;
  text-align: right;
}

.upload-zone {
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px dashed #a8bbb4;
  border-radius: 7px;
  background: #fafcfb;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.upload-zone:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.large-upload {
  min-height: 95px;
  flex-direction: column;
}

.attachment-list {
  display: grid;
  gap: 5px;
}

.attachment-item {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.attachment-item > div {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 1px;
}

.attachment-item a,
.attachment-item strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-item small {
  color: var(--muted);
  font-size: 9px;
}

.attachment-remove {
  display: inline-grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border-radius: 5px;
  background: transparent;
  color: var(--payment);
  cursor: pointer;
}

.attachment-remove:hover {
  background: var(--payment-soft);
}

.inline-reset {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.import-columns {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding-bottom: 3px;
}

.import-columns span {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 9px;
}

.import-result {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 11px;
}

.import-result p {
  margin: 0 0 5px;
}

.import-result ul {
  margin: 5px 0 0;
  padding-left: 18px;
  color: var(--danger);
}

.confirm-dialog {
  width: 380px;
  padding: 22px;
  text-align: center;
}

.confirm-dialog form {
  display: grid;
  gap: 10px;
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 19px;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
}

.confirm-icon {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 3px;
  place-items: center;
  border-radius: 50%;
  background: var(--contract-soft);
  color: var(--warning);
}

.confirm-icon.danger {
  background: var(--payment-soft);
  color: var(--danger);
}

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 7px;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  display: flex;
  max-width: min(380px, calc(100vw - 28px));
  align-items: center;
  gap: 12px;
  padding: 11px 12px 11px 14px;
  border: 1px solid #304b43;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.toast.error {
  border-color: #7e2724;
  background: #8f302d;
}

.toast span {
  flex: 1;
}

.toast button {
  display: inline-grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
  cursor: pointer;
}

.skeleton {
  min-height: 160px;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, #edf1ef 20%, #f7f9f8 45%, #edf1ef 70%);
  background-size: 220% 100%;
  animation: skeleton 1.2s linear infinite;
}

@keyframes skeleton {
  to {
    background-position: -220% 0;
  }
}

@media (max-width: 1080px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .heading-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: 62px;
    padding: calc(7px + env(safe-area-inset-top)) 13px 7px;
  }

  .topbar-brand .brand-mark {
    display: none;
  }

  .mobile-menu-button {
    display: inline-grid;
  }

  .account-label,
  .account-menu-button .chevron {
    display: none;
  }

  .account-menu-button {
    padding: 2px;
  }

  .workspace {
    display: block;
    min-height: calc(100dvh - 62px);
  }

  .sidebar {
    position: fixed;
    z-index: 80;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(82vw, 290px);
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    border-right: 1px solid var(--line);
    box-shadow: 20px 0 60px rgba(10, 25, 20, 0.2);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  body.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .main-content {
    padding: 19px 13px calc(94px + env(safe-area-inset-bottom));
  }

  .view {
    max-width: none;
  }

  .page-heading {
    margin-bottom: 16px;
  }

  .page-heading h2 {
    font-size: 22px;
  }

  .heading-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .heading-actions .compact-field {
    min-width: 0;
  }

  .heading-actions > .secondary-button:only-child {
    justify-self: start;
  }

  .metric-grid,
  .report-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .metric-card {
    padding: 12px;
  }

  .metric-card strong {
    font-size: 18px;
  }

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

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

  .contract-metrics {
    grid-template-columns: 1fr;
  }

  .contract-metrics > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .bottom-nav {
    position: fixed;
    z-index: 45;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-height: 66px;
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(252, 253, 252, 0.98);
  }

  .bottom-nav button {
    display: grid;
    min-width: 0;
    place-items: center;
    align-content: center;
    gap: 3px;
    padding: 4px;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 9px;
    font-weight: 650;
  }

  .bottom-nav button.active {
    background: var(--brand-soft);
    color: var(--brand);
  }

  .bottom-nav .receipt-nav.active {
    background: var(--receipt-soft);
    color: var(--receipt);
  }

  .bottom-nav .payment-nav.active {
    background: var(--payment-soft);
    color: var(--payment);
  }

  .bottom-nav .icon {
    width: 20px;
    height: 20px;
  }

  .ledger-toolbar {
    flex-wrap: wrap;
  }

  .search-field {
    min-width: 100%;
    max-width: none;
  }

  .report-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .report-controls .segmented-control,
  .report-controls .compact-field.grow {
    grid-column: 1 / -1;
  }

  .compact-field.grow {
    min-width: 0;
  }

  .backup-schedule-row {
    align-items: stretch;
    flex-direction: column;
  }

  .backup-schedule-controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
  }

  .backup-schedule-controls .compact-field {
    flex: 1 1 auto;
    min-width: 0;
  }

  .backup-schedule-controls .secondary-button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  @media (max-width: 340px) {
    .backup-schedule-controls {
      flex-wrap: wrap;
    }

    .backup-schedule-controls .secondary-button {
      flex: 1 0 100%;
      justify-content: center;
    }
  }

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

  .admin-tabs {
    justify-content: flex-start;
  }

  .admin-tabs button {
    flex: 0 0 auto;
  }

  .app-dialog {
    width: 100%;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }

  .app-dialog[open] {
    margin: 0;
  }

  .qr-login-dialog {
    width: 100%;
  }

  .dialog-head {
    padding-top: calc(15px + env(safe-area-inset-top));
  }

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

  .contract-preview {
    grid-template-columns: 1fr 1fr;
  }

  .toast {
    right: 14px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: 14px;
    max-width: none;
  }
}

@media (max-width: 640px) {
  .admin-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .admin-tabs button {
    min-width: 0;
  }

  .admin-tabs button[data-admin-tab="settings"] {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .login-screen {
    padding: 16px;
  }

  .login-brand {
    margin-bottom: 13px;
  }

  .login-brand .brand-mark {
    width: 45px;
    height: 45px;
    font-size: 21px;
  }

  .login-brand h1 {
    font-size: 23px;
  }

  .login-panel {
    padding: 21px 18px;
  }

  .qr-login-body {
    grid-template-columns: 1fr;
    gap: 17px;
    padding: 18px;
  }

  .qr-paper {
    width: min(100%, 250px);
    justify-self: center;
  }

  .qr-login-copy {
    width: 100%;
  }

  .metric-grid,
  .report-metrics {
    gap: 8px;
  }

  .metric-card {
    align-items: flex-start;
    gap: 8px;
  }

  .metric-icon {
    width: 30px;
    height: 30px;
  }

  .metric-icon .icon {
    width: 17px;
    height: 17px;
  }

  .metric-card span {
    font-size: 10px;
  }

  .metric-card strong {
    font-size: 16px;
  }

  .metric-card small {
    font-size: 9px;
  }

  .heading-actions {
    grid-template-columns: 1fr;
  }

  .heading-actions .primary-button,
  .heading-actions .secondary-button {
    width: 100%;
  }

  .panel {
    padding: 12px;
  }

  .ledger-panel {
    padding: 0;
  }

  .panel-heading {
    align-items: flex-start;
  }

  .panel-heading .segmented-control {
    max-width: 150px;
    overflow-x: auto;
  }

  .report-controls {
    grid-template-columns: 1fr;
  }

  .report-controls .segmented-control,
  .report-controls .compact-field.grow {
    grid-column: auto;
  }

  .segmented-control.large {
    width: 100%;
  }

  .segmented-control.large button {
    flex: 1;
  }

  .ledger-summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .contract-preview {
    grid-template-columns: 1fr;
  }

  .attachment-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .attachment-title small {
    text-align: left;
  }

  .dialog-actions {
    flex-wrap: wrap;
  }

  .dialog-actions .primary-button,
  .dialog-actions .secondary-button,
  .dialog-actions .danger-text-button {
    flex: 1;
  }

  .dialog-actions .action-spacer {
    display: none;
  }

  .setting-row {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
