:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-strong: #eef2ea;
  --ink: #17201a;
  --muted: #627066;
  --line: #d8dfd8;
  --brand: #23684c;
  --brand-strong: #184935;
  --accent: #b45b38;
  --danger: #a23232;
  --shadow: 0 12px 32px rgba(24, 40, 30, 0.1);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 16px;
}

.unlock-view {
  display: grid;
  align-content: center;
  min-height: 100svh;
  gap: 24px;
}

.brand-lockup h1,
.app-header h1,
.section-heading h2 {
  margin: 0;
  line-height: 1.05;
}

.brand-lockup h1 {
  font-size: 42px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.auth-panel,
.panel,
fieldset,
.generated-summary,
.company-row,
.invoice-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.main-view {
  display: grid;
  gap: 14px;
  padding-bottom: 28px;
}

.app-header,
.section-heading,
.action-row,
.invoice-row,
.company-row,
.invoice-document-header,
.invoice-total-block div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header {
  padding: 8px 0 2px;
}

.header-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.app-header h1 {
  font-size: 26px;
}

.tab-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  background: rgba(244, 246, 243, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(12px);
}

.tab-button,
.segment-button,
.primary-button,
.secondary-button,
.icon-button,
.text-button {
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 750;
}

.tab-button,
.segment-button {
  color: var(--muted);
  background: transparent;
}

.tab-button.is-active,
.segment-button.is-active {
  color: #fff;
  background: var(--brand);
}

.primary-button {
  color: #fff;
  background: var(--brand);
  padding: 0 16px;
}

.primary-button:active,
.tab-button.is-active:active,
.segment-button.is-active:active {
  background: var(--brand-strong);
}

.secondary-button,
.icon-button {
  color: var(--brand-strong);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  padding: 0 14px;
}

.text-button {
  justify-self: start;
  min-height: 36px;
  color: var(--danger);
  background: transparent;
  padding: 0;
}

.panel {
  padding: 16px;
}

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

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

.stacked-form,
fieldset,
.mode-fields,
.custom-items {
  display: grid;
  gap: 12px;
}

fieldset {
  margin: 0 0 14px;
  padding: 14px;
}

legend {
  padding: 0 6px;
  color: var(--brand-strong);
  font-size: 14px;
  font-weight: 800;
}

label,
.search-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 10px 12px;
  font-size: 16px;
}

.money-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  overflow: hidden;
}

.money-input > span {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 40px;
  color: var(--brand-strong);
  background: var(--surface-strong);
  border-right: 1px solid var(--line);
  font-weight: 850;
}

.money-input input {
  min-height: 44px;
  border: 0;
  border-radius: 0;
}

.money-input:focus-within {
  outline: 3px solid rgba(35, 104, 76, 0.18);
  border-color: var(--brand);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(35, 104, 76, 0.18);
  border-color: var(--brand);
}

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

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

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px;
  background: var(--surface-strong);
  border-radius: 8px;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.custom-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f8faf7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.generated-summary {
  display: grid;
  gap: 10px;
  margin: 4px 0 14px;
  padding: 14px;
}

.generated-summary div {
  display: grid;
  gap: 4px;
}

.generated-summary span,
.invoice-muted,
.invoice-row span,
.company-row span,
.invoice-row small {
  color: var(--muted);
}

.generated-summary strong {
  overflow-wrap: anywhere;
}

.action-row {
  align-items: stretch;
}

.action-row > button {
  flex: 1;
}

.invoice-list,
.company-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.invoice-row,
.company-row {
  align-items: flex-start;
  padding: 12px;
  box-shadow: none;
}

.invoice-row > div:first-child,
.company-row > div:first-child {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.invoice-row strong,
.company-row strong {
  overflow-wrap: anywhere;
}

.invoice-row-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-strong);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.storage-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 850;
}

.storage-status.is-d1 {
  color: var(--brand-strong);
}

.storage-status.is-local {
  color: var(--danger);
}

.empty-state,
.form-error,
.helper-note,
.field-help,
.form-message {
  margin: 0;
  color: var(--muted);
}

.field-help {
  font-size: 13px;
  font-weight: 650;
}

.mode-summary {
  margin: 0;
  padding: 10px 12px;
  color: var(--brand-strong);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.form-error {
  color: var(--danger);
  font-weight: 800;
}

.form-message {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 800;
}

.form-message.is-error {
  color: var(--danger);
}

.invoice-preview {
  overflow-x: auto;
  padding-bottom: 8px;
}

.invoice-page {
  width: min(100%, 8.5in);
  min-height: 11in;
  margin: 0 auto;
  padding: 0.55in;
  color: #1b1b1b;
  background: #fff;
  border: 1px solid #d7d7d7;
  box-shadow: var(--shadow);
}

.invoice-document-header {
  align-items: flex-start;
  padding-bottom: 28px;
  border-bottom: 2px solid #1b1b1b;
}

.invoice-business {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 850;
}

.invoice-title-block {
  text-align: right;
}

.invoice-title-block h3 {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: 0;
}

.invoice-title-block p {
  margin: 0;
  font-weight: 800;
}

.invoice-party-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  padding: 24px 0;
}

.invoice-party-block {
  display: grid;
  gap: 5px;
  align-content: start;
}

.invoice-party-block p {
  margin: 0;
}

.invoice-party-block span,
.invoice-meta-list dt {
  color: #5d665f;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.invoice-meta-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.invoice-meta-list div {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 12px;
  align-items: baseline;
}

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

.invoice-meta-list dd {
  text-align: right;
  font-weight: 800;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
}

.invoice-table th,
.invoice-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #d8d8d8;
  text-align: right;
}

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

.invoice-table th {
  color: #fff;
  background: #1f3f32;
  font-size: 12px;
  text-transform: uppercase;
}

.invoice-total-block {
  display: grid;
  gap: 8px;
  width: min(100%, 280px);
  margin: 24px 0 0 auto;
}

.invoice-total-block div {
  padding: 4px 0;
}

.grand-total {
  border-top: 2px solid #1b1b1b;
  font-size: 20px;
}

.invoice-footer {
  margin-top: 42px;
  padding-top: 16px;
  border-top: 1px solid #d8d8d8;
}

.invoice-footer p {
  margin: 0 0 8px;
}

@media (max-width: 520px) {
  .app-shell {
    padding: 12px;
  }

  .tab-bar {
    gap: 4px;
    padding: 6px;
  }

  .tab-button,
  .segment-button {
    font-size: 13px;
  }

  .panel {
    padding: 12px;
  }

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

  .invoice-row {
    display: grid;
  }

  .invoice-row-actions {
    grid-template-columns: 1fr auto auto;
    justify-items: start;
    align-items: center;
    width: 100%;
  }

  .invoice-page {
    min-width: 640px;
    padding: 28px;
  }
}

@page {
  size: Letter;
  margin: 0;
}

@media print {
  html,
  body {
    background: #fff;
  }

  .app-header,
  .tab-bar,
  .section-heading,
  .action-row,
  #unlock-view,
  #recent-panel,
  #new-panel,
  #companies-panel {
    display: none !important;
  }

  .app-shell,
  .panel,
  .invoice-preview {
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .invoice-page {
    width: 8.5in;
    min-height: 11in;
    padding: 0.55in;
    border: 0;
    box-shadow: none;
  }
}
