:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --brand: #6f4228;
  --brand-dark: #4a2b1b;
  --accent: #9a5b34;
  --soft: #f2e6dc;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(246, 247, 249, 0.78), rgba(246, 247, 249, 0.86)),
    url("/assets/papier.jpg?v=20260524") center center / 640px 640px repeat;
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #21150f;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.18);
}

.login-card h1 {
  margin-bottom: 8px;
}

.login-logo {
  width: min(260px, 100%);
  height: auto;
  display: block;
  margin-bottom: 24px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: #21150f;
  color: white;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 34px;
}

.portal-brand {
  display: grid;
  gap: 10px;
}

.portal-brand h1 {
  color: #d8d8d8;
}

.portal-logo {
  width: 100%;
  max-width: 236px;
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 4px;
}

.eyebrow {
  color: #d2a47d;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
}

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

h1,
h2,
h3,
.section-head h3,
.items-head h3 {
  color: var(--brand-dark);
  font-weight: 800;
}

h1 {
  font-size: 1.8rem;
  line-height: 1.1;
}

nav {
  display: grid;
  gap: 8px;
}

.nav,
.ghost,
.primary {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
}

.nav {
  background: transparent;
  color: #dce6e4;
  text-align: left;
}

.nav.sub {
  padding-left: 24px;
}

.nav-group {
  margin: 14px 0 4px;
  color: #b9a79c;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav.active,
.nav:hover {
  background: rgba(154, 91, 52, 0.28);
  color: white;
}

main {
  padding: 28px;
  overflow: auto;
  position: relative;
  isolation: isolate;
  background:
    linear-gradient(rgba(246, 247, 249, 0.72), rgba(246, 247, 249, 0.8)),
    url("/assets/papier.jpg?v=20260524") center center / 640px 640px repeat;
}

main::before {
  content: "";
  position: fixed;
  inset: 0 0 0 280px;
  z-index: -1;
  pointer-events: none;
  background: rgba(246, 247, 249, 0.08);
}

.topbar,
.section-head,
.items-head,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.profit-inline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--muted);
}

.profit-inline span,
.profit-inline small {
  font-size: 0.9rem;
}

.profit-inline strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.profit-inline strong.negative {
  color: #b42318;
}

.section-tools {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mailbox-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.mailbox-tabs .active {
  background: var(--brand);
  color: white;
}

.compact-label {
  min-width: 220px;
  margin: 0;
  font-size: 0.82rem;
}

.compact-label select {
  min-height: 42px;
  padding: 8px 10px;
}

.muted {
  color: var(--muted);
  margin-bottom: 6px;
}

.primary {
  background: var(--brand);
  color: white;
  font-weight: 700;
}

.primary:hover {
  background: var(--brand-dark);
}

.ghost {
  background: var(--soft);
  color: var(--brand-dark);
  font-weight: 700;
}

.ghost:hover {
  background: #ead7c8;
}

.ghost.danger {
  color: #8a2f1a;
  background: #f3ded5;
}

.ghost.danger:hover {
  background: #ebc9bc;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.command-center {
  margin-bottom: 18px;
}

.stats article,
.panel,
.split > section {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(2px);
}

.stats article {
  padding: 18px;
}

.stats span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.stats strong {
  font-size: 1.45rem;
  color: var(--brand-dark);
}

.split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.split > section,
.panel {
  padding: 20px;
}

.table {
  display: grid;
  gap: 10px;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.row.clickable {
  cursor: pointer;
}

.row.clickable:hover {
  border-color: #c9a78d;
  background: #fffaf6;
}

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

.invoice-row {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.invoice-row .row-actions {
  width: 100%;
  margin-top: 4px;
}

.inline-edit {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  min-width: min(640px, 100%);
}

.inline-edit textarea {
  min-height: 150px;
}

.ad-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ad-images img {
  width: 76px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5f1ec;
}

.mailbox-row {
  align-items: start;
}

.mail-actions {
  max-width: 360px;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.small-select {
  width: min(260px, 100%);
  min-height: 32px;
  padding: 4px 8px;
  font-size: 0.9rem;
}

.inline-control {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.inline-form textarea {
  grid-column: 1 / -1;
}

.done-text {
  text-decoration: line-through;
  color: var(--muted);
}

.ai-output {
  min-height: 180px;
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  white-space: pre-wrap;
  line-height: 1.55;
}

.inline-control select {
  width: min(360px, 100%);
  min-height: 36px;
}

.negative {
  color: #b42318;
}

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

.account-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.account-grid h4 {
  margin: 0 0 10px;
}

.customer-recurring-notes {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.customer-recurring-note {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.92rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef1f5;
  color: #344054;
  font-size: 0.82rem;
}

.pill.paid {
  background: #e7f6ed;
  color: #157347;
}

.pill.sent {
  background: #fff4de;
  color: #946200;
}

.pill.partial {
  background: #e7f0ff;
  color: #2457a7;
}

.pill.archived {
  background: #f1f1f1;
  color: #60646c;
}

.pill.overdue {
  background: #fdecec;
  color: #b42318;
}

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

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

.grid .wide {
  grid-column: 1 / -1;
}

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

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-weight: 650;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
  font-weight: 400;
}

textarea {
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check input {
  width: 18px;
}

.line-item {
  display: grid;
  grid-template-columns: 170px 90px 1fr 80px 110px 90px 42px;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.subpanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 16px 0;
}

.subpanel legend {
  color: var(--muted);
  font-weight: 700;
  padding: 0 6px;
}

.icon {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.report-preview {
  margin-top: 18px;
}

.report-table {
  overflow-x: auto;
}

.report-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0 10px;
}

.report-subhead h3 {
  margin: 0;
}

.summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.summary-line span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  color: var(--muted);
  font-size: 0.9rem;
}

.report-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.report-table th,
.report-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

.report-table td:nth-child(7),
.report-table td:nth-child(8),
.report-table th:nth-child(7),
.report-table th:nth-child(8) {
  text-align: right;
}

.report-table tfoot th {
  background: #f3f5f7;
}

#print-area {
  display: none;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 18px;
  }

  nav,
  .stats,
  .split,
  .account-grid,
  .grid.two {
    grid-template-columns: 1fr;
  }

  .line-item {
    grid-template-columns: 1fr 1fr;
  }

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

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

  body > .app {
    display: none;
  }

  #print-area {
    display: block;
    padding: 0;
    color: #111827;
  }

  .print-invoice {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 0 18mm 14mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .invoice-bg {
    position: absolute;
    inset: 0;
    width: 210mm;
    height: 297mm;
    object-fit: fill;
    z-index: 0;
    pointer-events: none;
  }

  .print-invoice > :not(.invoice-bg) {
    position: relative;
    z-index: 1;
  }

  .print-book {
    max-width: 1040px;
    margin: 0 auto;
  }

  .print-head,
  .print-payment,
  .print-meta,
  .invoice-facts,
  .print-total {
    display: flex;
    justify-content: space-between;
    gap: 24px;
  }

  .sender-line {
    font-size: 10px;
    margin: 0 0 10px;
    text-decoration: underline;
    white-space: nowrap;
  }

  .invoice-letterhead {
    height: 112mm;
    margin: 0 -18mm 10mm;
    padding: 0;
    position: relative;
    overflow: hidden;
    background: transparent;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .invoice-letterhead::before {
    content: none;
  }

  .invoice-letterhead::after {
    content: none;
  }

  .brand-row,
  .letterhead-content {
    position: relative;
    z-index: 1;
  }

  .brand-row {
    display: none;
    position: absolute;
    inset: 0;
  }

  .letterhead-logo {
    position: absolute;
    top: 5.6mm;
    left: 11.4mm;
    width: 142.6mm;
    height: auto;
    display: block;
    filter: drop-shadow(3px 6px 4px rgba(0,0,0,0.36));
  }

  .brand-claim {
    position: absolute;
    top: 25mm;
    left: 101mm;
    margin: 0;
    font-family: "Brush Script MT", "Segoe Script", cursive;
    font-size: 25px;
    white-space: nowrap;
  }

  .letterhead-qr {
    position: absolute;
    top: 10.5mm;
    right: 8.5mm;
    width: 40.5mm;
    height: 40.5mm;
    object-fit: cover;
    transform: rotate(9deg);
    border: 2.8mm solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.28);
  }

  .letterhead-content {
    position: absolute;
    left: 18mm;
    right: 17mm;
    top: 60mm;
    display: grid;
    grid-template-columns: 1fr 92mm;
    gap: 18mm;
    margin: 0;
  }

  .recipient-block {
    padding-left: 0;
    font-size: 14px;
    line-height: 1.15;
  }

  .recipient-block p:last-child {
    font-size: 16px;
  }

  .header-contact {
    font-size: 14px;
    line-height: 1.15;
    transform: translateX(7mm);
  }

  .header-contact > strong {
    text-decoration: underline;
  }

  .header-contact dl {
    display: grid;
    grid-template-columns: 24mm 1fr;
    margin: 6px 0 20px;
  }

  .header-contact dt,
  .header-contact dd {
    margin: 0;
  }

  .header-facts {
    row-gap: 4px;
  }

  .contact-box {
    min-width: 240px;
  }

  .invoice-facts {
    justify-content: flex-end;
    gap: 36px;
    margin-top: 20px;
  }

  .invoice-footer {
    margin-top: auto;
    padding-top: 28px;
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 24px;
    font-size: 12px;
    line-height: 1.35;
  }

  .invoice-footer strong {
    font-weight: 700;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 32px;
    table-layout: fixed;
    font-size: 13px;
  }

  .print-table th,
  .print-table td {
    border-bottom: 1px solid #d0d5dd;
    padding: 8px 4px;
    text-align: left;
    vertical-align: top;
  }

  .print-table th {
    white-space: nowrap;
    font-size: 12px;
    line-height: 1.1;
  }

  .print-table .col-pos {
    width: 8mm;
  }

  .print-table .col-article {
    width: 17mm;
  }

  .print-table .col-description {
    width: auto;
  }

  .print-table .col-quantity {
    width: 16mm;
  }

  .print-table .col-price {
    width: 24mm;
  }

  .print-table .col-amount {
    width: 24mm;
  }

  .print-table td:nth-child(1),
  .print-table th:nth-child(1),
  .print-table td:nth-child(2),
  .print-table th:nth-child(2) {
    white-space: nowrap;
  }

  .print-table td:nth-child(4),
  .print-table th:nth-child(4),
  .print-table td:nth-child(5),
  .print-table th:nth-child(5),
  .print-table td:last-child,
  .print-table th:last-child {
    text-align: right;
  }

  .print-total {
    margin-top: 28mm;
    align-items: flex-start;
    font-size: 13px;
  }

  .print-total h3 {
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .invoice-closing-text {
    max-width: 150mm;
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.35;
  }

  .book-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 24px;
    margin-bottom: 20px;
  }

  .book-head h1 {
    font-size: 18px;
  }

  .book-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
  }

  .book-table th,
  .book-table td {
    border-bottom: 1px solid #d0d5dd;
    padding: 6px 5px;
    text-align: left;
    vertical-align: top;
  }

  .book-table td:nth-child(7),
  .book-table td:nth-child(8),
  .book-table th:nth-child(7),
  .book-table th:nth-child(8) {
    text-align: right;
  }

  .book-table tfoot th {
    padding-top: 12px;
  }
}
