:root {
  --ink: #1f2329;
  --muted: #5c6570;
  --bg: #eef2f6;
  --panel: #ffffff;
  --accent: #1d5ea8;
  --line: #d8dee7;
  --highlight: #edf4ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Trebuchet MS", sans-serif;
  background: linear-gradient(135deg, #f8fbff 0%, var(--bg) 55%, #e8eef6 100%);
  color: var(--ink);
}

.shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 12px 35px rgba(11, 39, 71, 0.11);
}

#loginPanel {
  max-width: 540px;
  margin: 40px auto;
}

#appPanel {
  padding: 16px 18px;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--muted);
}

form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
}

input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
}

textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
  resize: vertical;
}

button {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

button.danger {
  border-color: #b3261e;
  color: #b3261e;
}

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

.status {
  margin-top: 8px;
  color: #b00020;
  min-height: 1.25rem;
}

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

.header-title-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.workspace {
  display: block;
}

.workspace.split {
  display: grid;
  grid-template-columns: 30% 1fr;
  gap: 16px;
}

.workspace.full-mode {
  display: block;
}

.list-pane {
  min-width: 0;
  position: relative;
  border-radius: 12px;
  transition: box-shadow 0.15s ease, background-color 0.15s ease;
}

.list-pane.pdf-drag-over {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.list-pane.pdf-drag-over::after {
  content: "+";
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(29, 94, 168, 0.82);
  color: #fff;
  font-size: clamp(5rem, 14vw, 10rem);
  font-weight: 300;
  line-height: 1;
  pointer-events: none;
}

.list-controls {
  background: #f7faff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.drop-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

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

select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  background: #fff;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.button-row.tight {
  margin-top: 0;
}

.mini-input {
  padding: 7px 9px;
  font-size: 0.85rem;
}

.users-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}

.users-actions .mini {
  white-space: nowrap;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

.doc-table tbody tr {
  cursor: pointer;
}

.doc-table tbody tr:hover {
  background: #f8fbff;
}

.doc-table tbody tr.active {
  background: var(--highlight);
}

.doc-pane {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  min-width: 0;
}

.external-document-view {
  display: grid;
  gap: 12px;
}

.external-document-view[hidden] {
  display: none;
}

.document.external-metadata-mode .letterhead,
.document.external-metadata-mode .party-grid,
.document.external-metadata-mode .doc-meta-row.four-cols,
.document.external-metadata-mode .line-items-wrap,
.document.external-metadata-mode .totals {
  display: none !important;
}

.document.external-metadata-mode .doc-meta-box {
  margin-bottom: 0;
}

.external-document-summary {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7faff;
}

.external-document-summary h2 {
  margin: 0 0 6px;
}

.external-document-summary p {
  margin: 0 0 12px;
  color: var(--muted);
}

.button-link {
  display: inline-block;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

#externalPdfFrame {
  width: 100%;
  min-height: calc(100vh - 260px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.full-pane {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  min-width: 0;
}

.pane-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
}

.search-filter-grid {
  grid-template-columns: minmax(16rem, 2fr) minmax(10rem, 1fr) minmax(12rem, 1fr) auto;
  align-items: end;
  width: 100%;
}

.checkbox-label {
  display: flex;
  grid-auto-flow: column;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.checkbox-label input,
.check-col input {
  width: auto;
}

.full-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 190px);
}

.full-line-table {
  min-width: 1180px;
}

#panierTable {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1160px;
}

#panierTable .cart-col-check {
  width: 3%;
}

#panierTable .cart-col-project {
  width: 20%;
}

#panierTable .cart-col-qty {
  width: 4%;
}

#panierTable .cart-col-code,
#panierTable .cart-col-format {
  width: 8%;
}

#panierTable .cart-col-description {
  width: 18%;
}

#panierTable .cart-col-note {
  width: 12%;
}

#panierTable .cart-col-unit-price,
#panierTable .cart-col-total {
  width: 6%;
}

#panierTable .cart-col-supplier {
  width: 15%;
}

#panierTable th:nth-child(1),
#panierTable td:nth-child(1) {
  width: 3%;
}

#panierTable th:nth-child(2),
#panierTable td:nth-child(2) {
  width: 20%;
}

#panierTable th:nth-child(3),
#panierTable td:nth-child(3) {
  width: 4%;
}

#panierTable th:nth-child(4),
#panierTable td:nth-child(4),
#panierTable th:nth-child(5),
#panierTable td:nth-child(5) {
  width: 8%;
}

#panierTable th:nth-child(6),
#panierTable td:nth-child(6) {
  width: 18%;
}

#panierTable th:nth-child(7),
#panierTable td:nth-child(7) {
  width: 12%;
}

#panierTable th:nth-child(8),
#panierTable td:nth-child(8),
#panierTable th:nth-child(9),
#panierTable td:nth-child(9) {
  width: 6%;
}

#panierTable th:nth-child(10),
#panierTable td:nth-child(10) {
  width: 15%;
}

.full-line-table th,
.full-line-table td {
  font-size: 0.84rem;
}

#panierTable th,
#panierTable td {
  border: 1px solid var(--line);
  padding: 2px 4px;
  font-size: 0.72rem;
  line-height: 1.15;
}

#panierTable th {
  background: #f7faff;
}

.full-line-table select,
.full-line-table input {
  width: 100%;
  min-width: 0;
  padding: 4px;
  border: none;
  border-radius: 0;
  background: transparent;
}

#panierTable input,
#panierTable select {
  padding: 2px 3px;
  font-size: 0.72rem;
  line-height: 1.15;
  min-height: 1.35rem;
}

.full-line-table select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.check-col {
  width: 2.5rem;
}

.search-results-table {
  --search-col-date: 5rem;
  --search-col-reference: 12rem;
  --search-col-supplier: 15rem;
  --search-col-po: 8rem;
  --search-col-enterprise: 10rem;
  --search-col-project: 8rem;
  --search-col-qty: 3rem;
  --search-col-code: 8rem;
  --search-col-format: 8rem;
  --search-col-description: 12rem;
  --search-col-note: 6rem;
  --search-col-price: 5rem;
  --search-col-completed: 4rem;
  min-width: 1400px;
  font-size: 0.82rem;
  table-layout: fixed;
}

.search-results-table th:nth-child(1),
.search-results-table td:nth-child(1) {
  width: var(--search-col-date);
}

.search-results-table th:nth-child(2),
.search-results-table td:nth-child(2) {
  width: var(--search-col-reference);
}

.search-results-table th:nth-child(3),
.search-results-table td:nth-child(3) {
  width: var(--search-col-supplier);
}

.search-results-table th:nth-child(4),
.search-results-table td:nth-child(4) {
  width: var(--search-col-po);
}

.search-results-table th:nth-child(5),
.search-results-table td:nth-child(5) {
  width: var(--search-col-enterprise);
}

.search-results-table th:nth-child(6),
.search-results-table td:nth-child(6) {
  width: var(--search-col-project);
}

.search-results-table th:nth-child(7),
.search-results-table td:nth-child(7) {
  width: var(--search-col-qty);
}

.search-results-table th:nth-child(8),
.search-results-table td:nth-child(8) {
  width: var(--search-col-code);
}

.search-results-table th:nth-child(9),
.search-results-table td:nth-child(9) {
  width: var(--search-col-format);
}

.search-results-table th:nth-child(10),
.search-results-table td:nth-child(10) {
  width: var(--search-col-description);
}

.search-results-table th:nth-child(11),
.search-results-table td:nth-child(11) {
  width: var(--search-col-note);
}

.search-results-table th:nth-child(12),
.search-results-table td:nth-child(12) {
  width: var(--search-col-price);
}

.search-results-table th:nth-child(13),
.search-results-table td:nth-child(13) {
  width: var(--search-col-completed);
}

.search-results-table th,
.search-results-table td {
  padding: 6px 7px;
  vertical-align: top;
}

.search-results-table tr.completed-line {
  background: #ffe7e7;
}

.wide-dialog {
  width: min(980px, 94vw);
}

#supplierMessages {
  display: grid;
  gap: 10px;
  max-height: 45vh;
  overflow: auto;
}

.supplier-email-block {
  border: 1px solid #d8dee7;
  border-radius: 8px;
  padding: 10px;
}

.supplier-email-block h4 {
  margin: 0 0 8px;
}

.email-recipient-preview {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border-radius: 7px;
  background: #f1f3f6;
  overflow-wrap: anywhere;
}

.supplier-email-block .email-recipient-preview {
  margin-bottom: 10px;
}

.process-meta-box {
  margin-bottom: 10px;
}

.process-items-wrap {
  max-height: 28vh;
  overflow: auto;
}

.process-items-table {
  min-width: 860px;
}

.process-items-table th,
.process-items-table td {
  border-color: var(--line);
  font-size: 0.82rem;
  padding: 4px 6px;
}

.process-totals {
  margin-bottom: 10px;
}

.bottom-action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 0 0;
  background: #fff;
}

.bottom-action-bar label {
  width: min(320px, 100%);
}

.doc-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.doc-actions.bottom {
  justify-content: flex-end;
  margin-top: 10px;
}

.close-btn {
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  font-weight: 700;
  background: #c43131;
}

.document {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  background: #fff;
}

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

.doc-header-grid label:last-child {
  grid-column: 1 / -1;
}

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

.inline-input select {
  flex: 1 1 14rem;
}

.inline-input .mini {
  white-space: nowrap;
}

.letterhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 0;
  border-top: 2px solid #1f2329;
  border-bottom: 1px solid #1f2329;
  padding: 12px 0;
}

.letterhead img {
  max-height: 80px;
  max-width: 280px;
  object-fit: contain;
}

.letterhead h2 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
}

#docDateLine,
#docOrderIdLine {
  margin: 0.2rem 0 0;
}

.party-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.party-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.party-grid h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.party-grid p {
  margin: 0;
  min-height: 70px;
  white-space: pre-line;
  line-height: 1.35;
}

.doc-meta-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.doc-meta-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.doc-meta-row.two-cols {
  grid-template-columns: none;
}

.doc-meta-row.four-cols {
  grid-template-columns: none;
}

.doc-meta-row > label {
  flex: 1 1 0;
  min-width: 0;
}

.doc-meta-box label {
  font-size: 0.85rem;
  gap: 4px;
}

.doc-meta-box input {
  padding: 7px 9px;
  font-size: 0.9rem;
}

.line-items {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.line-items .col-project {
  width: 11rem;
}

.line-items .col-qty {
  width: 4.5rem;
}

.line-items .col-code {
  width: 6.5rem;
}

.line-items .col-format {
  width: 7.5rem;
}

.line-items .col-note {
  width: 9rem;
}

.line-items .col-unit-price,
.line-items .col-total {
  width: 7rem;
}

.line-items th,
.line-items td {
  border: 1px solid #232323;
  padding: 6px;
  font-size: 0.9rem;
}

.line-items th {
  background: #f1f3f6;
}

.line-items input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 4px;
}

.line-items .total-cell {
  text-align: right;
}

.quote-mode .order-only {
  display: none;
}

.totals {
  margin-top: 10px;
  margin-left: auto;
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.totals label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.totals div {
  display: flex;
  justify-content: space-between;
}

dialog {
  border: none;
  border-radius: 12px;
  width: min(520px, 90vw);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.users-dialog {
  width: min(900px, 94vw);
}

.dialog-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-title-row h3 {
  margin: 0;
}

dialog form {
  gap: 10px;
}

@media (max-width: 1080px) {
  .workspace.split {
    grid-template-columns: 1fr;
  }

  .doc-header-grid {
    grid-template-columns: 1fr 1fr;
  }

  .doc-meta-row {
    flex-wrap: wrap;
  }

  .doc-meta-row.four-cols > label {
    flex: 1 1 calc(50% - 8px);
  }

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

  .pane-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-filter-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .doc-header-grid {
    grid-template-columns: 1fr;
  }

  .doc-meta-row.two-cols > label,
  .doc-meta-row.four-cols > label {
    flex: 1 1 100%;
  }
}

.shipping-address-controls {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.shipping-address-controls textarea {
  width: 100%;
  resize: vertical;
}

.shipping-address-controls [hidden] {
  display: none;
}

.document.external-metadata-mode .shipping-address-controls {
  display: none;
}

@media print {
  body {
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  .print-area,
  .print-area * {
    visibility: visible;
  }

  .print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: none;
    margin: 0;
    padding: 0;
  }

  .doc-header-grid,
  .shipping-address-controls {
    display: none !important;
  }

  .party-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .doc-meta-row {
    flex-wrap: nowrap !important;
  }

  .doc-meta-row.two-cols > label,
  .doc-meta-row.four-cols > label {
    flex: 1 1 0 !important;
  }

  .line-items tr.placeholder-row {
    display: none !important;
  }

  .line-items .internal-note,
  .line-items col.internal-note {
    display: none !important;
  }

  .line-items input,
  .totals input,
  select,
  button {
    border: none;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    color: #000;
  }
}
