:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d7dde7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --warning: #b54708;
  --ok: #15803d;
  --focus: #2563eb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 30%, transparent);
  outline-offset: 2px;
}

button.secondary {
  background: #eef2f6;
  color: #243044;
}

button.secondary:hover {
  background: #dfe6ef;
}

button:disabled,
button:disabled:hover {
  background: #eef2f6;
  color: var(--muted);
  cursor: default;
}

button.compact {
  min-height: 34px;
  margin-top: 8px;
}

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

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(20, 30, 50, 0.08);
}

.login-panel h1 {
  margin: 0 0 22px;
  font-size: 26px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 14px;
}

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

textarea {
  resize: vertical;
}

.login-panel label + label,
.login-panel button {
  margin-top: 14px;
}

.form-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 14px;
}

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

.sidebar {
  background: #1f2937;
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #14b8a6;
  color: #062925;
}

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

.nav-button {
  width: 100%;
  justify-content: start;
  text-align: left;
  background: transparent;
  color: #d5dae3;
}

.nav-button.active,
.nav-button:hover {
  background: #334155;
  color: #fff;
}

.wide {
  width: 100%;
  margin-top: auto;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metric b {
  display: block;
  font-size: 24px;
}

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

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(2, minmax(150px, 1fr)) auto auto auto;
  align-items: end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.checkbox-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.checkbox-row input {
  width: 16px;
  min-height: 16px;
}

.split {
  display: grid;
  grid-template-columns: minmax(480px, 1.1fr) minmax(420px, 0.9fr);
  gap: 12px;
  align-items: start;
}

.form-mode .metrics,
.form-mode .filters,
.form-mode .table-panel {
  display: none;
}

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

.form-mode .detail-panel {
  padding: 20px;
}

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

.table-panel,
.detail-panel {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  background: #f8fafc;
  color: #475467;
  font-weight: 600;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eef8f6;
}

.status-pill,
.priority-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.priority-pill {
  background: #475467;
}

.doc-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
}

.doc-state.complete {
  background: #dcfce7;
  color: #166534;
}

.doc-state.missing {
  background: #fef3c7;
  color: #92400e;
}

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

.nested-table {
  margin-top: 6px;
  border: 1px solid var(--line);
}

.nested-table tbody tr {
  cursor: default;
}

.nested-table tbody tr:hover {
  background: transparent;
}

.detail-panel {
  padding: 16px;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.order-head {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.order-head h2 {
  margin: 0;
  font-size: 20px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

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

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  text-decoration: none;
  font-weight: 600;
}

.button-link:hover {
  background: var(--accent-strong);
}

.button-link.disabled {
  background: #eef2f6;
  color: var(--muted);
  cursor: default;
  pointer-events: none;
}

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

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

.form-section-title {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}

.line-editor {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.5fr) repeat(5, minmax(90px, 1fr)) 34px;
  gap: 8px;
  align-items: end;
}

.payment-row {
  grid-template-columns: minmax(140px, 1fr) minmax(150px, 1fr) 34px;
}

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

.documents-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.documents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.documents-head h3 {
  margin: 0;
  font-size: 16px;
}

.documents-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.document-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 1fr);
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

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

.document-row.complete {
  background: #f0fdf4;
}

.document-row.missing {
  background: #fffbeb;
}

.document-row b,
.document-row span {
  display: block;
}

.document-row span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.document-files {
  display: flex;
  align-items: start;
  flex-wrap: wrap;
  gap: 6px;
}

.document-file-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 5px 8px;
}

.document-file-choice input {
  width: 16px;
  min-height: 16px;
}

.document-files a,
.document-file-choice a {
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 13px;
}

.document-files > a {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  padding: 5px 8px;
  text-decoration: none;
  font-size: 13px;
}

.document-download-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.document-download-actions span {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin: 16px -16px 12px;
  padding: 0 16px;
}

.tab {
  background: transparent;
  color: #475467;
  border-radius: 6px 6px 0 0;
}

.tab.active {
  background: #eef2f6;
  color: var(--text);
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.timeline-item {
  border-left: 3px solid var(--line);
  padding: 7px 0 7px 10px;
}

.timeline-item b {
  display: block;
}

.timeline-item span {
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

#documentsDialog {
  width: min(860px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-form {
  max-height: min(86vh, 780px);
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.dialog-form h2 {
  margin: 0;
  font-size: 20px;
}

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    align-items: center;
  }

  nav {
    display: flex;
    flex-wrap: wrap;
  }

  .wide {
    width: auto;
    margin-top: 0;
    margin-left: auto;
  }

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

@media (max-width: 680px) {
  .workspace {
    padding: 12px;
  }

  .topbar,
  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .line-row,
  .payment-row,
  .payment-pair,
  .document-row {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
