:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(27, 37, 65, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

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

.sidebar {
  background: #101828;
  color: #f8fafc;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
}

.brand span,
.field span,
.eyebrow,
.metric span {
  color: var(--muted);
  font-size: 13px;
}

.sidebar .brand span,
.sidebar .field span {
  color: #b7c0ce;
}

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

.nav-group-title {
  margin: 12px 4px 2px;
  color: #98a2b3;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.nav-separator {
  height: 1px;
  margin: 8px 2px;
  background: #344054;
}

.nav-plain-bottom {
  margin-top: 0;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #d7deea;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #243044;
  color: #ffffff;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rate-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  min-width: 250px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.hidden {
  display: none !important;
}

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

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.content-grid,
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.split {
  grid-template-columns: 380px minmax(0, 1fr);
}

.panel {
  padding: 18px;
  min-width: 0;
}

.detail-panel {
  display: none;
}

.detail-panel.active {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: auto;
  padding: 28px;
  background: rgba(16, 24, 40, 0.58);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.pdf-modal-host {
  display: none;
}

.pdf-modal-host.active {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 300;
  overflow: auto;
  padding: 28px;
  background: rgba(16, 24, 40, 0.58);
}

.pdf-modal-host .modal-card {
  width: min(860px, 100%);
}

.modal-card {
  width: min(1120px, 100%);
  margin: 0 auto;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(16, 24, 40, 0.28);
  padding: 22px;
}

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

.form-panel {
  display: grid;
  gap: 12px;
  align-self: start;
}

.field {
  display: grid;
  gap: 6px;
}

.field.compact {
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
  min-height: 42px;
}

textarea {
  resize: vertical;
}

.sidebar select {
  background: #1d2939;
  color: #ffffff;
  border-color: #344054;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.three-col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

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

.check-grid label {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.check-grid input {
  width: auto;
  min-height: auto;
  margin-right: 8px;
}

.soft-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: none;
  background: #f8fafc;
}

.muted-panel {
  opacity: 0.62;
  background: #f1f5f9;
}

.status-note {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.align-end {
  align-self: end;
}

.primary-button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 14px;
  cursor: pointer;
}

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

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

.ghost-button {
  background: #eef3f8;
  color: #1f2937;
  border: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr,
.clickable {
  cursor: pointer;
}

tbody tr:hover,
.clickable:hover {
  background: #f8fafc;
}

.group-row {
  font-weight: 700;
  background: #f8fafc;
}

.sub-row {
  background: #ffffff;
}

.sub-row td:first-child {
  padding-left: 26px;
}

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

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

button.list-item {
  width: 100%;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.document-item {
  cursor: pointer;
}

.list-item small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.amount-positive {
  color: var(--accent-dark);
  font-weight: 700;
}

.amount-negative {
  color: var(--danger);
  font-weight: 700;
}

.status-pill {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  background: #eef3f8;
  font-size: 12px;
  font-weight: 700;
}

.label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.label-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 168px;
  display: grid;
  grid-template-rows: 22px auto;
  gap: 7px;
  align-content: start;
  background: #ffffff;
}

.label-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(19, 127, 111, 0.14);
}

.label-select {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.label-preview-real {
  width: calc(100% - 18px);
  justify-self: center;
  aspect-ratio: 5 / 3;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 4px;
  align-items: center;
  background: #ffffff;
  box-sizing: border-box;
}

.label-preview-text {
  display: grid;
  gap: 2px;
  font-family: "Courier New", monospace;
  color: #111827;
  text-transform: uppercase;
  line-height: 1.05;
  min-width: 0;
}

.label-preview-text strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label-preview-text span {
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label-preview-real img {
  width: 58px;
  height: 58px;
  justify-self: start;
}

.label-card small {
  color: var(--muted);
}

.drop-zone {
  border: 2px dashed #9aa7b8;
  border-radius: 8px;
  padding: 24px;
  min-height: 190px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 10px;
  background: #f8fafc;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #eefcf9;
}

.drop-zone input {
  max-width: 280px;
}

.invoice-preview {
  margin-top: 14px;
}

.pdf-preview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
  display: grid;
  gap: 12px;
}

.pdf-preview-card .panel-header {
  padding-bottom: 0;
}

.pdf-preview-card .detail-grid {
  margin-bottom: 0;
}

.preview-warning {
  border: 1px solid #f3c57a;
  border-radius: 8px;
  padding: 10px;
  background: #fff7e6;
  color: #7a4b00;
  font-weight: 700;
}

.pdf-text-sample {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  color: var(--muted);
}

.pdf-text-sample p {
  margin-top: 6px;
  max-height: 120px;
  overflow: auto;
  line-height: 1.45;
}

.pdf-import-issues {
  border: 1px solid #f3c57a;
  border-radius: 8px;
  padding: 12px;
  background: #fffaf0;
  display: grid;
  gap: 10px;
}

.issue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.issue-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

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

.compact-button {
  padding: 8px 10px;
  font-size: 13px;
}

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

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.activity-controls {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.chart-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 2fr 36px;
  gap: 10px;
  align-items: center;
  margin: 8px 0;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #eef2f6;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.statement {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-height: 420px;
  background: #ffffff;
}

.statement-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid var(--text);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.statement-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.statement td:nth-child(3),
.statement td:nth-child(4),
.statement td:nth-child(5),
.statement th:nth-child(3),
.statement th:nth-child(4),
.statement th:nth-child(5) {
  text-align: right;
}

.statement-opening-row,
.statement tfoot tr {
  font-weight: 700;
  background: #f8fafc;
}

.statement tfoot td {
  border-top: 2px solid var(--text);
  border-bottom: 0;
}

.statement-final td {
  font-size: 15px;
}

.statement-detail-row td {
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}

.statement-detail-row div + div {
  margin-top: 4px;
}

.quick-account {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.quick-account summary {
  cursor: pointer;
  font-weight: 700;
}

.quick-account[open] {
  display: grid;
  gap: 12px;
}

.quote-lines,
.totals {
  display: grid;
  gap: 8px;
}

.quote-line,
.total-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.quote-line small {
  color: var(--muted);
}

.total-row {
  background: #f8fafc;
  font-weight: 700;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  min-width: 0;
}

.detail-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.detail-card strong {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
  max-width: 100%;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.close-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.edit-form {
  display: none;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.edit-form.active {
  display: grid;
}

.print-document {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #ffffff;
  max-width: 794px;
  min-height: 1123px;
  margin: 0 auto;
}

.print-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid var(--text);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.brand-print {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-print img {
  max-width: 150px;
  max-height: 74px;
  object-fit: contain;
}

.info-note {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  line-height: 1.5;
}

.info-note p {
  margin-top: 6px;
}

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

  .metrics,
  .content-grid,
  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .statement-head,
  .top-actions,
  .print-head {
    align-items: stretch;
    flex-direction: column;
  }

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

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

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

  .detail-panel.active {
    padding: 12px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #ffffff;
  }

  .sidebar,
  .topbar,
  .nav,
  .panel-header .inline-actions,
  .detail-actions,
  .edit-form {
    display: none;
  }

  .app-shell,
  .main {
    display: block;
    padding: 0;
  }

  body:has(#production.active-view) #production .metrics,
  body:has(#production.active-view) #production .split > .panel:first-child,
  body:has(#production.active-view) #production > .panel,
  body:has(#production.active-view) #productionDetail {
    display: none !important;
  }

  body:has(#production.active-view) #production,
  body:has(#production.active-view) #production .split,
  body:has(#production.active-view) #production .split > .panel:nth-child(2) {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
  }

  body:has(#production.active-view) .label-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 8mm;
  }

  body:has(#production.active-view) .label-card {
    break-inside: avoid;
  }

  body.printing-statement .view,
  body.printing-document .view {
    display: none;
  }

  body.printing-statement #statements {
    display: block;
  }

  body.printing-document .view.active-view {
    display: block;
  }

  body.printing-document .view.active-view > :not(.detail-panel) {
    display: none;
  }

  body.printing-document .modal-card > .panel-header {
    display: none;
  }

  body.printing-document .detail-panel.active {
    display: block;
    position: static;
    inset: auto;
    overflow: visible;
    padding: 0;
    background: #ffffff;
  }

  body.printing-document .modal-card {
    box-shadow: none;
    border: 0;
    width: 100%;
    padding: 0;
  }

  body.printing-document .print-document {
    display: block;
    max-width: none;
    min-height: auto;
    margin: 0;
    padding: 0;
    border: 0;
  }

  body.printing-document .detail-grid,
  body.printing-document .print-document .table-wrap,
  body.printing-document .print-document .totals,
  body.printing-document .info-note {
    display: grid;
  }

  .panel,
  .statement {
    box-shadow: none;
    border: 0;
  }
}
