:root {
  color-scheme: light;
  --workspace: #f2f3f5;
  --panel: #fbfbfc;
  --paper: #ffffff;
  --ink: #17191c;
  --muted: #62676f;
  --line: #d8dbe0;
  --line-strong: #7f858e;
  --accent: #215da7;
  --accent-dark: #17477f;
  --danger: #a52d2d;
  --radius-control: 8px;
  --radius-panel: 12px;
  --paper-width: 793.7px;
  --paper-height: 1122.52px;
  font-family: Aptos, "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

html {
  background: var(--workspace);
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--workspace);
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 200;
  padding: 10px 14px;
  color: #fff;
  border-radius: var(--radius-control);
  background: var(--accent-dark);
  font-weight: 700;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

button,
input,
textarea {
  font: inherit;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

button {
  cursor: pointer;
}

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

h1[tabindex="-1"]:focus {
  outline: 3px solid var(--accent);
  outline-offset: 5px;
}

#invoiceListTitle,
#editorTitle,
#storageRecoveryTitle {
  scroll-margin-top: calc(76px + env(safe-area-inset-top));
}

input,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
  transition: border-color 180ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: none;
}

input:user-invalid,
textarea:user-invalid,
input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.offline-banner {
  padding: calc(9px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 9px calc(16px + env(safe-area-inset-left));
  color: #fff;
  background: #34383e;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top)) calc(22px + env(safe-area-inset-right)) 10px calc(22px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgb(251 251 252 / 0.94);
  backdrop-filter: blur(18px);
}

.brand-lockup,
.header-actions,
.panel-heading,
.preview-toolbar,
.editor-total {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 11px;
}

.brand-lockup img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.brand-name,
.save-status,
.preview-toolbar p,
.field-help,
.invoice-label,
.invoice-party,
.invoice-notes p,
.invoice-footer p {
  margin: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  gap: 9px;
}

.button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-control);
  font-weight: 700;
  white-space: nowrap;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), background-color 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.button:active {
  transform: translateY(1px) scale(0.99);
}

.button:disabled {
  color: #858a92;
  border-color: var(--line);
  cursor: not-allowed;
  background: #f1f2f3;
  transform: none;
}

.button-primary {
  color: #fff;
  border: 1px solid #111316;
  background: #17191c;
}

.button-primary:hover {
  background: #30343a;
}

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

.button-secondary:hover {
  border-color: #7b818a;
  background: #f6f7f8;
}

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

.button-danger:hover {
  color: #7f2020;
  border-color: #b86666;
  background: #fff5f5;
}

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

.account-identity {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.account-email {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-status {
  max-width: 240px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-status[data-state="waiting"],
.sync-status[data-state="syncing"] {
  color: var(--accent-dark);
}

.sync-status[data-state="error"],
.sync-status[data-state="conflict"] {
  color: var(--danger);
}

.auth-page {
  display: grid;
  min-height: calc(100dvh - 72px);
  padding: 40px 20px;
  place-items: center;
}

.auth-card {
  width: min(460px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--paper);
}

.auth-label,
.auth-intro,
.auth-help,
.auth-message {
  margin: 0;
}

.auth-label {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.auth-card h1 {
  margin: 5px 0 0;
  font-size: 30px;
  letter-spacing: -0.035em;
}

.auth-intro,
.auth-card > div > p:not(.auth-label),
.auth-help {
  margin-top: 9px;
  color: var(--muted);
  line-height: 1.5;
}

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

.auth-form .field-stack {
  margin-top: 0;
}

.auth-google-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  margin-top: 22px;
  color: #1f1f1f;
  border-color: #747775;
  background: #fff;
  font-size: 14px;
  font-weight: 500;
}

.auth-google-button svg {
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-divider + .auth-form {
  margin-top: 20px;
}

.auth-primary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.auth-primary-actions .button,
.auth-form > .button {
  width: 100%;
}

.auth-text-button {
  justify-self: start;
  min-height: 44px;
  padding: 8px 0;
  color: var(--accent-dark);
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-message {
  min-height: 20px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-message[data-state="error"] {
  color: var(--danger);
}

.auth-card code {
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--workspace);
  font-size: 0.9em;
}

.history-page {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 38px 0 32px;
}

.history-hero,
.history-section-heading,
.draft-notice,
.invoice-record-actions {
  display: flex;
  align-items: center;
}

.history-hero {
  justify-content: space-between;
  gap: 32px;
  padding: 4px 0 26px;
}

.history-hero h1 {
  margin: 0;
  font-size: clamp(30px, 3vw, 38px);
  letter-spacing: -0.035em;
}

.history-intro {
  max-width: 620px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.draft-notice {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
  padding: 18px 20px;
  border: 1px solid #b9cde7;
  border-radius: var(--radius-panel);
  background: #f3f7fc;
}

.draft-notice-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 9px;
}

.draft-notice-label {
  margin: 0 0 3px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.draft-notice h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.draft-notice p:last-child {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.history-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--paper);
}

.history-section-heading {
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.history-section-heading h2,
.history-empty-state h2 {
  margin: 0;
  letter-spacing: -0.025em;
}

.history-section-heading h2 {
  font-size: 19px;
}

.history-count {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.history-search {
  display: grid;
  gap: 5px;
  width: min(320px, 42vw);
}

.history-search label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.history-search input {
  min-height: 44px;
  padding-block: 8px;
}

.invoice-history-list {
  display: grid;
}

.history-feedback {
  margin: 0;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.history-error {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.history-error p {
  margin: 0;
}

.history-pagination {
  display: flex;
  justify-content: center;
  padding: 0 20px 20px;
}

.history-pagination:empty {
  display: none;
}

.history-pagination .button {
  min-width: 150px;
}

.invoice-record {
  display: grid;
  grid-template-columns: minmax(210px, 1.15fr) minmax(280px, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 21px 22px;
  border-bottom: 1px solid var(--line);
}

.invoice-record:last-child {
  border-bottom: 0;
}

.invoice-number {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.015em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-customer {
  display: -webkit-box;
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.invoice-record-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 14px;
  margin: 0;
}

.invoice-record-meta div {
  min-width: 0;
}

.invoice-record-meta dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.invoice-record-meta dd {
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-record-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.invoice-record-actions .button {
  min-height: 44px;
  padding: 8px 13px;
  font-size: 13px;
}

.history-empty-state {
  display: grid;
  justify-items: center;
  padding: 54px 24px 60px;
  text-align: center;
}

.history-empty-state h2 {
  font-size: 22px;
}

.history-empty-state p {
  max-width: 430px;
  margin: 9px 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.history-no-results {
  padding-block: 50px 56px;
}

.history-no-results p {
  margin-bottom: 0;
}

.history-storage-note {
  margin: 16px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.78fr) minmax(650px, 1.22fr);
  min-height: calc(100dvh - 72px);
}

.editor-panel {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-heading {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
.preview-toolbar h2 {
  margin: 0;
  letter-spacing: -0.025em;
}

h1 {
  margin-top: 3px;
  font-size: 27px;
  line-height: 1.1;
}

.save-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.form-section {
  min-width: 0;
  min-inline-size: 0;
  margin: 0 0 16px;
  padding: 16px;
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
}

.form-section legend {
  float: left;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  margin: 0 0 16px;
  padding: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 20px;
}

.form-section legend + * {
  clear: both;
}

.field-grid {
  display: grid;
  gap: 12px;
  margin-top: 13px;
}

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

.field-stack {
  display: grid;
  min-width: 0;
  gap: 7px;
  margin-top: 13px;
}

/* Keep iOS native date controls inside the grid and at the normal tap height. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  line-height: normal;
}

input[type="date"]::-webkit-date-and-time-value {
  min-height: 1em;
  text-align: left;
}

.field-grid.invoice-date-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-stack label {
  color: #30343a;
  font-size: 12px;
  font-weight: 700;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px 14px;
}

.checkbox-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
}

.checkbox-control input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 0;
  padding: 0;
  accent-color: var(--ink);
}

input[readonly] {
  color: #50555d;
  border-color: var(--line);
  background: #f1f2f3;
  cursor: default;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.optional-label {
  color: var(--muted);
  font-weight: 600;
}

.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
}

.item-formatting-help {
  margin: 4px 0 0;
}

.mobile-formatting-help,
.item-format-button {
  display: none;
}

.item-limit-help {
  margin: 4px 0 12px;
}

.items-section {
  position: relative;
}

.item-column-labels,
.item-row {
  display: grid;
  grid-template-columns: 64px minmax(112px, 1fr) 112px 44px;
  gap: 8px;
}

.items-section .item-column-labels {
  clear: both;
  margin: 17px 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.mobile-field-label {
  display: none;
}

.item-row {
  align-items: start;
  min-width: 0;
  margin-bottom: 9px;
}

.item-row > *,
.item-row .mobile-field,
.item-row input,
.item-row textarea {
  min-width: 0;
  max-width: 100%;
}

.item-row textarea {
  min-height: 66px;
}

.remove-item {
  display: grid;
  place-items: center;
  width: 44px;
  max-width: 100%;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  color: var(--danger);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.remove-item:not(:disabled):hover {
  color: #7f2020;
  border-color: #cb8e8e;
  background: #fff5f5;
}

.remove-item:not(:disabled):active {
  background: #fbe8e8;
}

.remove-item:disabled {
  color: #a7abb1;
  cursor: not-allowed;
  background: #f1f2f3;
}

.add-item-button {
  margin-top: 3px;
}

.editor-total {
  justify-content: flex-end;
  gap: 22px;
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}

.editor-total strong {
  min-width: 92px;
  text-align: right;
  font-size: 19px;
}

.mobile-output-action {
  display: none;
}

.stacked-preview-button {
  display: none;
}

.clear-draft-button {
  display: block;
  min-height: 44px;
  margin: 16px auto 0;
  padding: 10px 8px;
  color: var(--muted);
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.preview-panel {
  min-width: 0;
  scroll-margin-top: 72px;
  background: #e9eaec;
}

@media screen {
  #preview-panel:focus {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
  }
}

.preview-toolbar {
  justify-content: space-between;
  min-height: 67px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.preview-toolbar h2 {
  font-size: 15px;
}

.preview-toolbar p,
.preview-hint {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.preview-toolbar-actions,
.preview-zoom-controls {
  display: flex;
  align-items: center;
}

.preview-toolbar-actions {
  gap: 9px;
}

.preview-zoom-controls {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
}

.preview-tool-button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 11px;
  color: var(--ink);
  border: 0;
  background: var(--paper);
  font-size: 12px;
  font-weight: 750;
}

.preview-zoom-controls .preview-tool-button + .preview-tool-button {
  border-left: 1px solid var(--line-strong);
}

.preview-tool-button[aria-pressed="true"] {
  color: #fff;
  background: var(--ink);
}

.preview-tool-button:hover {
  background: #f1f2f3;
}

.preview-tool-button[aria-pressed="true"]:hover {
  background: #30343a;
}

.preview-back-button {
  display: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
}

.preview-stage {
  min-height: calc(100dvh - 139px);
  padding: 24px;
  overflow: auto;
}

.paper-scale-wrap {
  position: relative;
  margin: 0 auto;
}

.invoice-sheet {
  width: 210mm;
  min-height: 297mm;
  padding: 19.4mm 23mm 20mm 18.3mm;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  color: #0c0d0f;
  background: var(--paper);
  box-shadow: 0 14px 44px rgb(48 51 57 / 0.16), 0 2px 8px rgb(48 51 57 / 0.1);
  transform-origin: top left;
  font-family: "Segoe UI", sans-serif;
  font-size: 6.25pt;
  line-height: 1.25;
}

.invoice-header {
  display: grid;
  grid-template-columns: 1fr 38mm;
  min-height: 27mm;
}

.invoice-heading-block h2 {
  margin: 0 0 7mm;
  font-size: 12pt;
  line-height: 1;
}

.invoice-meta {
  display: grid;
  gap: 3mm;
  margin: 0;
}

.invoice-meta div {
  display: grid;
  grid-template-columns: 20mm 1fr;
}

.invoice-meta dt,
.invoice-meta dd {
  margin: 0;
}

.invoice-meta dd {
  font-weight: 760;
}

.invoice-logo {
  justify-self: end;
  width: 20.6mm;
  height: auto;
  margin-top: -2mm;
  margin-right: 0;
  object-fit: contain;
}

.billing-grid {
  display: grid;
  grid-template-columns: 75mm 1fr;
  gap: 18.5mm;
  min-height: 10mm;
  margin-top: 4mm;
}

.invoice-label,
.invoice-party {
  font-size: 6.25pt;
}

.invoice-party {
  min-height: 5mm;
  white-space: pre-line;
  text-transform: uppercase;
}

.invoice-party-to {
  font-weight: 760;
}

.invoice-table {
  width: 100%;
  margin-top: 4mm;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice-table thead th {
  padding: 0 1mm 1.2mm;
  border-bottom: 0.55mm solid #0c0d0f;
  font-size: 6.25pt;
  text-align: left;
}

.invoice-table thead th:first-child {
  text-align: left;
}

.invoice-table thead th:nth-child(2),
.invoice-table thead th:nth-child(3) {
  text-align: center;
}

.invoice-table thead th:nth-child(3) {
  padding-right: 3mm;
}

.invoice-table .serial-column {
  width: 4mm;
}

.invoice-table .symbol-column {
  width: 7mm;
}

.invoice-table .value-column {
  width: 20.7mm;
}

.invoice-table tbody td {
  padding: 1.6mm 1mm 2.2mm;
  border-bottom: 0.55mm solid #0c0d0f;
  vertical-align: top;
}

.invoice-table tbody td:first-child {
  text-align: center;
}

.invoice-table tbody td:nth-child(2) {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}

.invoice-table .amount-symbol {
  padding-right: 0;
  text-align: center;
}

.invoice-table .amount-value {
  padding-right: 6mm;
  text-align: right;
}

.invoice-table tfoot th,
.invoice-table tfoot td {
  padding: 0.7mm 1mm;
  border-bottom: 0.55mm solid #0c0d0f;
  font-weight: 800;
}

.invoice-table tfoot th {
  padding-right: 0;
  text-align: right;
}

.invoice-table tfoot td:first-of-type {
  padding-right: 0;
  text-align: center;
}

.invoice-table tfoot td:last-child {
  padding-right: 6mm;
  text-align: right;
}

.invoice-notes {
  margin-top: 1.2mm;
  font-size: 6.25pt;
  line-height: 1.4;
}

.payment-section {
  margin-top: 2mm;
}

.payment-section h3 {
  margin: 0 0 4mm;
  font-size: 6.25pt;
}

.payment-detail {
  margin-left: 5mm;
  font-size: 6.25pt;
}

.invoice-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8.8mm;
  padding-top: 2mm;
  padding-right: 5.7mm;
  border-top: 0.55mm solid #0c0d0f;
  text-align: right;
  font-size: 6.25pt;
}

.toast {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 15px;
  color: #fff;
  border-radius: var(--radius-control);
  background: #25292e;
  box-shadow: 0 12px 34px rgb(23 25 28 / 0.18);
  font-size: 13px;
  font-weight: 600;
}

.output-dialog {
  width: min(520px, calc(100vw - 28px));
  max-width: none;
  padding: 0;
  color: var(--ink);
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--paper);
  box-shadow: 0 24px 70px rgb(23 25 28 / 0.26);
}

.output-dialog::backdrop {
  background: rgb(18 21 25 / 0.56);
  backdrop-filter: blur(2px);
}

.output-dialog-card {
  position: relative;
  padding: 26px;
}

.output-dialog h2 {
  margin: 0 42px 6px 0;
  font-size: 26px;
  letter-spacing: -0.03em;
}

.output-dialog-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.dialog-close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 27px;
  line-height: 1;
}

.dialog-close-button:hover {
  color: var(--ink);
  background: var(--workspace);
}

.output-file-summary {
  display: grid;
  gap: 3px;
  margin: 20px 0;
  padding: 12px 14px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: #f7f8f9;
}

.output-file-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.cloud-pdf-panel {
  margin: -6px 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--workspace);
}

.cloud-pdf-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.cloud-pdf-panel p[data-state="error"] {
  color: var(--danger);
}

.cloud-pdf-panel p[data-state="saved"] {
  color: var(--ink);
  font-weight: 650;
}

.cloud-pdf-panel .button {
  margin-top: 10px;
}

.output-option {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 76px;
  padding: 14px 16px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
  text-align: left;
}

.output-option:hover {
  border-color: var(--ink);
  background: #f7f8f9;
}

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

.legacy-migration-dialog {
  width: min(590px, calc(100vw - 28px));
}

.legacy-migration-dialog .auth-label {
  margin-bottom: 6px;
}

.legacy-migration-dialog h2 {
  max-width: 470px;
}

.legacy-migration-summary {
  gap: 5px;
}

.legacy-migration-summary strong + span {
  margin-top: 8px;
}

.legacy-migration-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.legacy-migration-actions .button {
  width: 100%;
}

.output-option-primary:hover {
  background: var(--accent-dark);
}

.storage-recovery-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 22px 0 14px;
}

.storage-recovery-actions .button {
  width: 100%;
}

.output-option-title {
  font-weight: 750;
}

.output-option-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.output-option-primary .output-option-description {
  color: #d9dde2;
}

.output-cancel-button {
  width: 100%;
  margin-top: 12px;
}

noscript {
  display: block;
  padding: 20px;
  color: #fff;
  background: var(--danger);
}

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

  .editor-panel {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .stacked-preview-button {
    display: block;
    width: 100%;
    margin: -2px 0 16px;
  }

  .preview-back-button {
    display: block;
  }

  .preview-stage {
    min-height: 600px;
  }
}

@media (max-width: 900px) {
  .invoice-record {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .invoice-record-meta {
    grid-column: 1;
    grid-row: 2;
  }

  .invoice-record-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 767px) {
  .app-header {
    align-items: flex-start;
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  }

  .account-email,
  #newInvoiceButton,
  #printButton {
    display: none;
  }

  .sync-status {
    max-width: 112px;
    font-size: 10px;
  }

  .brand-lockup img {
    width: 40px;
    height: 40px;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .mobile-output-action {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .mobile-output-action .button {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .auth-page {
    align-items: start;
    padding: 24px 14px;
  }

  .auth-card {
    padding: 24px 20px;
  }

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

  .history-page {
    width: min(1120px, calc(100% - 28px));
    padding: 28px 0 24px;
  }

  .history-hero {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
    padding: 2px 0 22px;
  }

  .history-hero h1 {
    font-size: 30px;
  }

  .history-hero .button,
  .draft-notice .button {
    width: 100%;
  }

  .draft-notice {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  .draft-notice-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .history-section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .history-search {
    width: 100%;
  }

  .invoice-record {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    padding: 20px 18px;
  }

  .invoice-record-meta,
  .invoice-record-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .invoice-record-actions {
    flex-direction: row;
  }

  .invoice-record-actions .button {
    flex: 1;
  }

  .editor-panel {
    padding: 18px 14px calc(24px + env(safe-area-inset-bottom));
  }

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

  h1 {
    font-size: 24px;
  }

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

  .item-column-labels {
    display: none;
  }

  .item-row {
    position: relative;
    grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr) 44px;
    gap: 12px 9px;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 16px 0;
    border-top: 1px solid var(--line);
  }

  .item-row:first-child {
    padding-top: 0;
    border-top: 0;
  }

  .item-row input,
  .item-row textarea {
    padding-top: 10px;
  }

  .item-row .mobile-field {
    display: grid;
    gap: 6px;
  }

  .item-row .mobile-field:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
  }

  .item-row .mobile-field:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .item-row .mobile-field:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
  }

  .desktop-formatting-help {
    display: none;
  }

  .mobile-formatting-help {
    display: inline;
  }

  .description-field {
    position: relative;
  }

  .description-field textarea {
    padding-right: 70px;
  }

  .item-format-button {
    position: absolute;
    top: 25px;
    right: 6px;
    display: block;
    min-width: 54px;
    min-height: 44px;
    padding: 7px 9px;
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: calc(var(--radius-control) - 2px);
    background: #f6f7f8;
    font-size: 12px;
    font-weight: 750;
  }

  .mobile-field-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .remove-item {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    width: 44px;
    color: var(--danger);
    font-size: 24px;
  }

  .remove-item:disabled {
    display: none;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
    padding: 12px 14px;
  }

  .preview-toolbar-actions {
    width: 100%;
  }

  .preview-hint {
    display: none;
  }

  .preview-back-button {
    margin-left: auto;
  }

  .preview-stage {
    min-height: 430px;
    padding: 12px;
  }

  .output-dialog-card {
    padding: 22px 18px 18px;
  }

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

@media (max-width: 420px) {
  .brand-lockup > div {
    display: none;
  }

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

@media (max-width: 340px) {
  .invoice-record-meta {
    grid-template-columns: minmax(88px, 1.25fr) minmax(44px, 0.6fr) minmax(76px, 1fr);
    gap: 8px;
  }
}

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

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    height: 297mm;
    max-height: 297mm;
    margin: 0 !important;
    overflow: hidden !important;
    background: #fff;
  }

  .app-header,
  .offline-banner,
  .auth-page,
  .history-page,
  .editor-panel,
  .preview-toolbar,
  .output-dialog,
  .skip-link,
  .toast {
    display: none !important;
  }

  .workspace,
  .preview-panel,
  .preview-stage,
  .paper-scale-wrap {
    display: block;
    width: 210mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden !important;
    background: #fff;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  #previewBillTo,
  #previewItems {
    font-family: "Arial Unicode MS", "Hiragino Sans GB", sans-serif;
  }

  .invoice-sheet {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 0;
    max-height: 297mm;
    margin: 0;
    overflow: hidden;
    box-shadow: none;
    transform: none !important;
    break-before: avoid;
    break-after: avoid;
    break-inside: avoid;
    page-break-before: avoid;
    page-break-after: avoid;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

#paymentDialog { width: min(480px, calc(100vw - 32px)); max-height: 90dvh; color: var(--ink); border: 1px solid var(--line); border-radius: 16px; padding: 28px; overflow: auto; box-shadow: 0 24px 80px rgb(23 32 51 / 18%); }
#paymentDialog::backdrop { background: rgb(23 32 51 / 38%); }
.payment-panel { display: grid; gap: 20px; }
.payment-heading h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.5px; line-height: 1.25; }
.payment-panel p { margin: 0; font-size: 13px; line-height: 1.5; }
#paymentInvoiceNumber, .payment-hint, .payment-optional { color: var(--muted); }
.payment-panel label { display: grid; gap: 8px; font-size: 14px; font-weight: 600; }
.payment-optional { float: right; font-size: 12px; font-weight: 400; }
.payment-panel select, .payment-panel textarea, #paymentFilter { width: 100%; padding: 10px 12px; color: var(--ink); background: var(--paper); border: 1px solid var(--line-strong); border-radius: 7px; font: inherit; }
.payment-panel select, .payment-panel textarea { font-size: 14px; font-weight: 400; }
.payment-panel select { min-height: 44px; }
.payment-panel textarea { min-height: 88px; }
.payment-evidence { display: grid; gap: 12px; border-top: 1px solid var(--line); padding-top: 20px; }
.payment-evidence[hidden], #paymentRemovalHint[hidden] { display: none; }
#paymentScreenshot { font-size: 13px; font-weight: 400; padding: 8px; min-width: 0; }
#paymentScreenshot::file-selector-button { font: inherit; font-weight: 600; border: 0; border-radius: 4px; padding: 8px 10px; margin-right: 10px; color: var(--accent); background: var(--workspace); cursor: pointer; }
.payment-panel .payment-confirm { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; line-height: 1.5; font-weight: 400; }
#paymentConfirmed { width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; margin: 1px 0 0; padding: 0; accent-color: var(--accent); }
#paymentPreview { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: 6px; }
.payment-actions { display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); padding-top: 20px; }
.payment-actions .button { font-size: 14px; min-height: 44px; padding: 10px 16px; }
#paymentError { color: #a12525; }
#paymentError:empty { display: none; }
@media (max-width: 480px) { #paymentDialog { padding: 20px; } .payment-actions .button { flex: 1; } }
#paymentFilterLabel { display: block; max-width: 240px; margin-bottom: 20px; }
#paymentFilterLabel[hidden] { display: none; }
