:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --panel-soft: #f3f5ef;
  --panel-warm: #f8f5ef;
  --line: #deded8;
  --line-strong: #c9cbc4;
  --text: #1d211f;
  --muted: #6b716d;
  --faint: #929892;
  --green: #0f5b32;
  --green-2: #1d7a49;
  --green-soft: #e7f2ea;
  --sage: #8eb79b;
  --blue: #2f79b9;
  --amber: #b9802e;
  --red: #c74757;
  --shadow: 0 10px 30px rgba(31, 34, 29, 0.08);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 296px;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfaf7;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 84px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand strong {
  display: block;
  font-size: 21px;
  line-height: 1.1;
}

.brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  flex: 1;
  padding: 18px 12px;
  overflow-y: auto;
}

.nav-group {
  margin: 20px 0 8px;
  padding: 0 12px;
  color: #7c827d;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #222724;
  text-align: left;
}

.nav-item svg,
.button svg,
.icon-button svg,
.quick-create svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
}

.nav-item.active {
  background: #eef2eb;
  color: #143923;
  font-weight: 700;
}

.storage {
  margin: 12px;
  padding: 14px 12px;
  border-radius: 8px;
  background: #eef1eb;
}

.storage-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

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

.meter {
  height: 8px;
  border-radius: 999px;
  background: #dfe2dc;
  overflow: hidden;
}

.meter span {
  display: block;
  width: 18%;
  height: 100%;
  background: var(--green-2);
}

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

.topbar {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--green-soft);
  color: #1f6d3e;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8a8f8b;
}

.button,
.icon-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.button {
  padding: 8px 13px;
}

.button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--green);
}

.button.danger {
  border-color: #f0cbd0;
  color: #9a2534;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 16px;
}

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

.icon-button {
  width: 38px;
  padding: 0;
}

.workspace {
  padding: 20px 24px 18px;
}

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

.section-header h1,
.section-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.tab {
  border: 0;
  border-radius: 7px;
  padding: 6px 10px;
  background: transparent;
  color: #303532;
}

.tab.active {
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

.templates {
  display: grid;
  grid-template-columns: repeat(6, minmax(106px, 1fr));
  gap: 16px;
  padding-bottom: 26px;
}

.template-card {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
}

.template-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 0.67;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.template-card.selected .template-preview {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(15, 91, 50, 0.14);
}

.template-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.template-check {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 22px;
  height: 22px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
}

.template-card.selected .template-check {
  display: flex;
}

.template-meta {
  display: grid;
  grid-template-columns: 9px 1fr;
  gap: 8px;
  margin-top: 10px;
}

.swatch {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
}

.template-name {
  font-weight: 650;
}

.template-industry {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.recent {
  padding-top: 6px;
}

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

.search {
  position: relative;
}

.search input {
  width: 286px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 38px 0 12px;
  background: #fff;
}

.search svg {
  position: absolute;
  right: 12px;
  top: 10px;
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.document-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}

.document-table th,
.document-table td {
  height: 43px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.document-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.document-row {
  cursor: pointer;
}

.document-row:hover td,
.document-row:focus-visible td {
  background: #f4f6f0;
}

.document-row:focus-visible {
  outline: 2px solid rgba(15, 91, 50, 0.35);
  outline-offset: -2px;
}

.document-table td:first-child,
.document-table th:first-child {
  padding-left: 6px;
}

.doc-id {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge.paid {
  color: #276332;
  background: #dff0e1;
}

.badge.sent {
  color: #27699c;
  background: #dbeaf6;
}

.badge.overdue {
  color: #b22a3a;
  background: #ffe1e5;
}

.badge.draft {
  color: #555c58;
  background: #eceeeb;
}

.amount {
  text-align: right;
  font-weight: 650;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.right-panel {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: #fbfaf7;
  padding-bottom: 118px;
}

.right-sticky {
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.checklist {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--line);
}

.checklist h2,
.quick-create h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.progress-copy {
  color: var(--muted);
  margin-bottom: 10px;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: #dedfd9;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress span {
  display: block;
  height: 100%;
  width: 66%;
  background: var(--green-2);
}

.check-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 34px;
}

.check-item svg {
  width: 17px;
  height: 17px;
}

.check-item.done {
  color: #276332;
}

.check-item span:last-child {
  color: var(--text);
}

.quick-create {
  margin: 18px 0 0;
  padding: 20px;
  border-top: 1px solid var(--line);
  flex: 1;
}

.quick-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

.input-row {
  display: flex;
  gap: 8px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

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

.quick-create .button.primary {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.more-options {
  width: 100%;
  margin-top: 12px;
}

.footer-bar {
  position: fixed;
  left: 248px;
  right: 0;
  bottom: 0;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 0 24px;
  border-top: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.96);
  color: var(--muted);
  font-size: 12px;
  z-index: 30;
}

.footer-bar strong {
  color: var(--green);
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(25, 28, 24, 0.34);
}

.mobile-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 90;
  width: min(310px, 88vw);
  background: #fbfaf7;
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform 0.18s ease;
}

.mobile-drawer.open {
  transform: translateX(0);
}

.modal {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 100;
  width: min(860px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  transform: translate(-50%, -50%);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-body {
  padding: 20px;
}

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

.data-tabs {
  margin-bottom: 18px;
}

.data-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.data-row,
.data-add {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(180px, 1.2fr) 38px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.data-row.compact {
  grid-template-columns: minmax(220px, 1fr) 140px 38px;
}

.data-add {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--panel-soft);
}

.data-row .field,
.data-add .field {
  margin-bottom: 0;
}

.wide {
  min-width: 0;
}

.doc-preview {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 18px;
}

.doc-preview aside {
  display: grid;
  align-content: start;
  gap: 10px;
}

.doc-preview aside .button {
  width: 100%;
}

.paper {
  min-height: 680px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.paper-head {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 34px;
}

.paper h3 {
  margin: 0 0 8px;
  font-size: 28px;
}

.paper table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 26px;
}

.paper th,
.paper td {
  padding: 10px 0;
  border-bottom: 1px solid #e5e5df;
  text-align: left;
}

.paper th:last-child,
.paper td:last-child {
  text-align: right;
}

.paper-total {
  margin-left: auto;
  margin-top: 24px;
  width: 260px;
}

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

.total-row.final {
  margin-top: 7px;
  padding-top: 12px;
  border-top: 1px solid #bfc4bd;
  font-size: 20px;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 58px;
  z-index: 120;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #173522;
  color: #fff;
  box-shadow: var(--shadow);
}

.mobile-top {
  display: none;
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .right-panel {
    display: none;
  }

  .templates {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 760px) {
  .layout {
    display: block;
  }

  .main {
    padding-bottom: 0;
  }

  .sidebar,
  .topbar {
    display: none;
  }

  .mobile-top {
    position: sticky;
    top: 0;
    z-index: 40;
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: #fbfaf7;
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 18px;
  }

  .mobile-brand img {
    width: 32px;
    height: 32px;
    border-radius: 7px;
  }

  .workspace {
    padding: 18px 14px;
  }

  .section-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    gap: 8px;
  }

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

  .recent-tools {
    width: 100%;
  }

  .search {
    flex: 1;
  }

  .search input {
    width: 100%;
  }

  .document-table {
    table-layout: fixed;
  }

  .document-table th,
  .document-table td {
    height: 46px;
    padding: 0 7px;
    white-space: nowrap;
  }

  .document-table th:nth-child(2),
  .document-table td:nth-child(2),
  .document-table th:nth-child(3),
  .document-table td:nth-child(3),
  .document-table th:nth-child(5),
  .document-table td:nth-child(5) {
    display: none;
  }

  .document-table th:nth-child(1),
  .document-table td:nth-child(1) {
    width: 38%;
  }

  .document-table th:nth-child(4),
  .document-table td:nth-child(4) {
    width: 28%;
  }

  .document-table th:nth-child(6),
  .document-table td:nth-child(6) {
    width: 23%;
  }

  .document-table th:nth-child(7),
  .document-table td:nth-child(7) {
    width: 42px;
    padding-right: 0;
  }

  .document-table .doc-id {
    max-width: 100%;
  }

  .document-table .doc-id svg {
    display: none;
  }

  .document-table .badge {
    padding-inline: 7px;
  }

  .amount {
    text-align: right;
  }

  .right-panel {
    display: block;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .right-sticky {
    position: static;
    min-height: 0;
  }

  .footer-bar {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 8px 14px;
  }

  .form-grid,
  .doc-preview,
  .field-row,
  .data-row,
  .data-row.compact,
  .data-add {
    grid-template-columns: 1fr;
  }

  .modal {
    width: calc(100vw - 18px);
    max-height: calc(100vh - 18px);
  }

  .paper {
    padding: 22px;
  }
}
