:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-soft: #f0f0ec;
  --line: #deded8;
  --line-strong: #c7c7bf;
  --ink: #20211f;
  --muted: #686b63;
  --muted-2: #8b8e85;
  --accent: #1f7a62;
  --accent-dark: #145441;
  --accent-soft: #e5f2ec;
  --warn: #9a6417;
  --warn-soft: #fff4dc;
  --danger: #a23a3a;
  --danger-soft: #fbe8e6;
  --ok: #24714f;
  --ok-soft: #e5f5ec;
  --shadow: 0 16px 40px rgba(31, 33, 31, 0.08);
  --radius: 8px;
  --sidebar-width: 264px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: #fbfbf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 4px 8px 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid #2c2e2b;
  border-radius: 8px;
  color: #ffffff;
  background: #2c2e2b;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

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

.nav-item,
.ghost-button,
.primary-button,
.secondary-button,
.icon-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    transform 120ms ease;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  padding: 9px 10px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  color: var(--ink);
  background: var(--surface-soft);
}

.nav-item.is-active {
  border-color: var(--line);
}

.nav-icon,
.button-icon,
.meta-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.nav-icon svg,
.button-icon svg,
.meta-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 86px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 246, 243, 0.92);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  line-height: 1.16;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.05rem;
  line-height: 1.2;
}

h3 {
  margin-bottom: 8px;
  font-size: 0.94rem;
  line-height: 1.25;
}

.topbar-actions,
.action-row,
.form-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.content {
  display: grid;
  gap: 18px;
  width: min(1480px, 100%);
  padding: 24px 28px 36px;
}

.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section {
  padding: 18px;
}

.section-header,
.table-header,
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-header p,
.detail-header p {
  margin-bottom: 0;
}

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

.small {
  font-size: 0.84rem;
}

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

.metric {
  display: grid;
  gap: 8px;
  min-height: 122px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric-value {
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  font-weight: 800;
  line-height: 1;
}

.metric-foot {
  align-self: end;
  color: var(--muted);
  font-size: 0.84rem;
}

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

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

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

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

.field.full {
  grid-column: 1 / -1;
}

.field > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
}

input,
select {
  padding: 8px 10px;
}

textarea {
  min-height: 150px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(31, 122, 98, 0.16);
}

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

.primary-button {
  padding: 8px 13px;
  color: #ffffff;
  background: var(--accent);
}

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

.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  padding: 8px 12px;
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line-strong);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  background: var(--surface-soft);
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  background: var(--danger-soft);
}

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8f8f5;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  font-size: 0.91rem;
}

td .field {
  min-width: 128px;
}

td .field > span {
  font-size: 0.68rem;
}

tr:last-child td {
  border-bottom: 0;
}

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

.nowrap {
  white-space: nowrap;
}

.status,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-paid,
.status-active,
.status-completed,
.status-success {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: #bde4cd;
}

.status-inactive {
  color: var(--muted);
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.status-pending {
  color: #605a22;
  background: #f7f2d5;
  border-color: #e8dea1;
}

.status-failed,
.status-overdue,
.status-out,
.status-out-of-stock {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #efbeb9;
}

.status-low,
.status-low-stock {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: #f0d8a3;
}

.summary-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.summary-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.summary-row span:first-child {
  color: var(--muted);
}

.summary-row strong {
  text-align: right;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 36px;
  flex: 0 0 46px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eceae3;
}

.thumb svg {
  width: 38px;
  height: 28px;
}

.contract-detail {
  display: grid;
  gap: 16px;
}

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

.detail-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf8;
}

.detail-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid #bde4cd;
  border-radius: var(--radius);
  color: var(--ok);
  background: #f4fbf7;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.is-hidden {
  display: none !important;
}

.print-root {
  display: none;
}

.print-document {
  color: #151613;
  background: #ffffff;
}

.print-doc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 2px solid #151613;
}

.print-doc-header p {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.print-doc-header h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
}

.print-doc-header span,
.print-footer span {
  color: #555950;
  font-size: 0.86rem;
}

.print-doc-header > div:last-child {
  min-width: 180px;
  text-align: right;
}

.print-doc-header strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1rem;
}

.print-document h2 {
  margin: 22px 0 10px;
  font-size: 1rem;
}

.print-key-values {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border: 1px solid #cfcfc8;
  border-bottom: 0;
}

.print-key-values div {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1fr);
  min-height: 38px;
  border-bottom: 1px solid #cfcfc8;
}

.print-key-values div:nth-child(odd) {
  border-right: 1px solid #cfcfc8;
}

.print-key-values dt,
.print-key-values dd {
  margin: 0;
  padding: 8px 10px;
  font-size: 0.86rem;
}

.print-key-values dt {
  color: #555950;
  background: #f5f5f1;
  font-weight: 800;
}

.print-key-values dd {
  font-weight: 700;
}

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

.print-table th,
.print-table td {
  padding: 8px 9px;
  border: 1px solid #cfcfc8;
  font-size: 0.8rem;
  text-align: left;
  vertical-align: top;
}

.print-table th {
  color: #555950;
  background: #f5f5f1;
  font-weight: 800;
}

.print-total-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 14px 16px;
  border: 2px solid #151613;
  font-size: 1rem;
}

.print-total-row strong {
  font-size: 1.2rem;
}

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

.signature-grid div {
  min-height: 72px;
  border-bottom: 1px solid #151613;
}

.signature-grid span {
  display: block;
  padding-top: 78px;
  color: #555950;
  font-size: 0.82rem;
}

.print-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 28px;
  padding-top: 10px;
  border-top: 1px solid #cfcfc8;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(160px, 220px) auto;
  gap: 10px;
  align-items: end;
}

.csv-preview {
  display: grid;
  gap: 14px;
}

.code-box {
  max-height: 230px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #272a27;
  color: #f7f7f2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

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

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 0 4px 12px;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .content {
    padding: 18px;
  }

  .form-grid,
  .form-grid.three,
  .filters,
  .input-row {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 520px) {
  .topbar-actions,
  .action-row,
  .form-actions,
  .inline-actions {
    width: 100%;
  }

  .topbar-actions > *,
  .form-actions > *,
  .action-row > * {
    flex: 1 1 100%;
  }

  .section-header,
  .table-header,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  html,
  body {
    background: #ffffff;
  }

  .app-shell,
  .toast {
    display: none !important;
  }

  .print-root {
    display: block;
  }

  .print-document {
    display: block;
    width: 100%;
    box-shadow: none;
  }

  .print-doc-header,
  .print-key-values,
  .print-table,
  .print-total-row,
  .signature-grid,
  .print-footer {
    break-inside: avoid;
  }

  .print-document h2 {
    break-after: avoid;
  }
}
