:root {
  --bg: #ebe4d6;
  --bg-2: #e3dac8;
  --ink: #161410;
  --ink-soft: #5c574e;
  --paper: #fffaf2;
  --line: #d5ccbb;
  --copper: #b4451a;
  --copper-dark: #8c3010;
  --sage: #3d5a4c;
  --shadow: 0 28px 60px -24px rgba(40, 28, 12, 0.35);
  --sans: "Figtree", "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #f4ecdc 0%, transparent 50%),
    radial-gradient(900px 400px at 100% 0%, #dfd3bc 0%, transparent 45%),
    var(--bg);
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.mark {
  width: 32px;
  height: 32px;
  display: block;
  border-radius: 10px;
  box-shadow: 0 10px 20px -10px rgba(180, 69, 26, 0.85);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.brand:hover .mark,
.brand:focus-visible .mark {
  transform: rotate(-10deg) scale(1.08);
}

.brand-name {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -0.03em;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--ink);
  background: transparent;
  padding: 9px 14px;
  cursor: pointer;
  border-radius: 2px;
}

.btn:hover {
  background: rgba(22, 20, 16, 0.06);
}

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

.btn-primary:hover {
  background: var(--copper-dark);
  border-color: var(--copper-dark);
}

.btn-copper {
  background: var(--copper);
  border-color: var(--copper);
  color: #fffaf2;
}

.btn-copper:hover {
  background: var(--copper-dark);
  border-color: var(--copper-dark);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 28px;
  padding: 24px;
  max-width: 1440px;
  margin: 0 auto;
}

.panel {
  background: rgba(255, 250, 242, 0.55);
  border: 1px solid var(--line);
  padding: 8px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--ink-soft);
}

.tab[aria-selected="true"] {
  color: var(--ink);
  background: var(--paper);
  box-shadow: inset 0 -2px 0 var(--copper);
}

.panel-body {
  padding: 14px 12px 16px;
  max-height: calc(100vh - 170px);
  overflow: auto;
}

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

.stack-gap {
  margin-top: 18px;
}

label.field {
  display: grid;
  gap: 5px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field select,
.field textarea {
  text-transform: none;
  letter-spacing: 0;
  font-size: 15px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 2px;
  width: 100%;
}

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

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

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}

h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  margin: 4px 0 10px;
  letter-spacing: -0.03em;
}

.hint {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 0 0 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 64px 72px 88px 32px;
  gap: 6px;
  align-items: end;
  margin-bottom: 8px;
}

.item-row input,
.item-row select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--paper);
  height: 36px;
  cursor: pointer;
}

.preview-wrap {
  display: flex;
  justify-content: center;
  padding-bottom: 40px;
}

.sheet {
  width: min(100%, 210mm);
  min-height: 297mm;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 18mm 18mm 16mm;
  position: relative;
  color: var(--ink);
}

.sheet.demo::after {
  content: "MINIBILLS";
  position: absolute;
  inset: 40% auto auto 50%;
  transform: translate(-50%, -50%) rotate(-18deg);
  font-family: var(--serif);
  font-size: 110px;
  color: rgba(180, 69, 26, 0.12);
  letter-spacing: 0.12em;
  pointer-events: none;
}

.sheet-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
}

.logo {
  max-width: 160px;
  max-height: 72px;
  object-fit: contain;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--copper);
  margin: 0 0 6px;
}

.sheet h1 {
  font-family: var(--serif);
  font-size: 54px;
  font-weight: 400;
  margin: 0;
  letter-spacing: -0.04em;
  line-height: 0.9;
}

.meta {
  text-align: right;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.meta strong {
  color: var(--ink);
  font-weight: 600;
}

.parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin: 8px 0 28px;
  font-size: 14px;
  line-height: 1.5;
}

.parties .label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

table.positions {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.positions th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  border-bottom: 1px solid var(--ink);
  padding: 0 8px 8px 0;
}

table.positions td {
  padding: 11px 8px 11px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

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

.totals {
  width: min(320px, 100%);
  margin-left: auto;
  margin-top: 18px;
  font-size: 14px;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
}

.totals .grand {
  border-top: 1px solid var(--ink);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 18px;
  font-family: var(--serif);
}

.paybox,
.legal {
  margin-top: 28px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.paybox {
  background: #f3ece0;
  padding: 14px 16px;
  color: var(--ink);
}

.paybox strong {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--sage);
}

.archive-item,
.client-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

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

.demo-banner {
  background: var(--copper);
  color: #fffaf2;
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  align-items: center;
}

.demo-banner a {
  color: inherit;
}

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

  .app-header {
    flex-wrap: wrap;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    min-height: 44px;
    white-space: nowrap;
  }

  .panel-body {
    max-height: none;
  }

  .sheet h1 {
    font-size: 40px;
  }
}

@media print {
  body {
    background: white;
  }

  .no-print {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .sheet {
    box-shadow: none;
    width: 210mm;
    min-height: 297mm;
    padding: 16mm;
  }

  .sheet.demo::after {
    color: rgba(180, 69, 26, 0.2);
  }

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