* {
  box-sizing: border-box;
}

:root {
  --navy: #17243a;
  --navy-strong: #111c2f;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --teal: #087f73;
  --red: #d92d20;
  --amber: #b54708;
  --ink: #22304a;
  --muted: #6b7890;
  --line: #dfe5ee;
  --surface: #ffffff;
  --page: #f3f6fa;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  background: var(--navy);
  color: white;
  border-bottom: 1px solid #2c3a52;
}

.header-inner,
.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
}

.header-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: var(--blue);
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: #aebbd0;
  font-size: 12px;
}

.filter-field {
  display: grid;
  gap: 5px;
}

.primary-button,
.secondary-button,
.danger-button {
  height: 36px;
  padding: 0 15px;
  border-radius: 5px;
  font-weight: 600;
}

.primary-button {
  border: 1px solid var(--blue);
  color: white;
  background: var(--blue);
}

.secondary-button {
  border: 1px solid #cbd4e1;
  color: #34425a;
  background: #f8fafc;
}

.danger-button {
  border: 1px solid #b42318;
  color: white;
  background: #b42318;
}

.page-shell {
  padding: 22px 0 40px;
}

.tabs {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 28px;
  min-height: 48px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 0 13px;
  border: 0;
  color: #718099;
  background: transparent;
  font-weight: 600;
  white-space: nowrap;
}

.tab span {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #e8edf5;
  color: #5d6b82;
  font-size: 11px;
  text-align: center;
}

.tab.active {
  color: var(--blue);
}

.tab.active::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--blue);
}

.tab.active span {
  color: #1d4ed8;
  background: #dbeafe;
}

.po-value-metric {
  display: grid;
  align-content: center;
  justify-items: end;
  margin-right: -4px;
  padding-bottom: 10px;
}

.po-value-metric span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.po-value-metric strong {
  color: var(--navy-strong);
  font-size: 24px;
  line-height: 1.15;
}

.filter-bar {
  display: grid;
  grid-template-columns:
    minmax(170px, 1fr) minmax(170px, 1fr)
    minmax(130px, 0.75fr) 145px 145px minmax(210px, 1.4fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.filter-field[hidden] {
  display: none;
}

.filter-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.filter-field input:not([type="checkbox"]),
.filter-field select,
.rows-control select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  color: #34425a;
  background: white;
  outline: none;
}

.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.filter-checkbox-group {
  position: relative;
}

.checkbox-dropdown {
  position: relative;
}

.checkbox-dropdown summary {
  position: relative;
  height: 36px;
  padding: 8px 32px 8px 10px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  color: #34425a;
  background: white;
  cursor: pointer;
  list-style: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.checkbox-dropdown summary::-webkit-details-marker {
  display: none;
}

.checkbox-dropdown summary::after {
  position: absolute;
  top: 50%;
  right: 11px;
  width: 7px;
  height: 7px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  content: "";
  transform: translateY(-65%) rotate(45deg);
}

.checkbox-dropdown[open] summary {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.checkbox-dropdown[open] summary::after {
  transform: translateY(-25%) rotate(225deg);
}

.checkbox-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  display: grid;
  gap: 7px;
  width: max(100%, 260px);
  max-height: 240px;
  padding: 10px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  background: white;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  overflow: auto;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #34425a;
  font-size: 12px;
}

.checkbox-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--blue);
}

.data-section {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  overflow: hidden;
}

.table-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.table-heading h2 {
  margin: 0;
  font-size: 16px;
}

.table-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.table-actions,
.rows-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rows-control span {
  color: var(--muted);
  font-size: 12px;
}

.rows-control select {
  width: 68px;
}

.download-dropdown {
  position: relative;
}

.download-dropdown summary {
  display: flex;
  align-items: center;
  list-style: none;
}

.download-dropdown summary::-webkit-details-marker {
  display: none;
}

.download-dropdown summary::after {
  width: 7px;
  height: 7px;
  margin-left: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  content: "";
  transform: translateY(-2px) rotate(45deg);
}

.download-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  right: 0;
  width: 180px;
  padding: 5px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  background: white;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}

.download-menu button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 4px;
  color: #34425a;
  background: transparent;
  font-size: 12px;
  text-align: left;
}

.download-menu button:hover,
.download-menu button:focus-visible {
  color: #1558d6;
  background: var(--blue-soft);
  outline: none;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1030px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf0f5;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #68768e;
  background: #f8fafc;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  color: #40506a;
  font-size: 12px;
}

tbody tr:hover {
  background: #f8fbff;
}

.selection-column {
  width: 42px;
  padding-right: 6px;
  padding-left: 14px;
  text-align: center;
}

.selection-column input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--blue);
}

.po-number {
  color: #1558d6;
  font-weight: 700;
}

.view-po-button {
  height: 30px;
  padding: 0 12px;
  border: 1px solid #b8c5d8;
  border-radius: 5px;
  color: #1558d6;
  background: white;
  font-size: 11px;
  font-weight: 700;
}

.view-po-button:hover,
.view-po-button:focus-visible {
  border-color: var(--blue);
  background: var(--blue-soft);
  outline: none;
}

.number-column {
  text-align: right;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: #2457b7;
  font-size: 10px;
  font-weight: 700;
  text-transform: capitalize;
}

.empty-row td {
  height: 160px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 12px;
}

.pagination-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pagination-buttons button {
  height: 30px;
  padding: 0 11px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  color: #42516a;
  background: white;
}

.pagination-buttons button:disabled {
  opacity: 0.45;
  cursor: default;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 15px;
  border-radius: 6px;
  color: white;
  background: var(--navy-strong);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.detail-modal[hidden] {
  display: none;
}

.modal-open {
  overflow: hidden;
}

.detail-modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 28, 47, 0.55);
  backdrop-filter: blur(2px);
}

.detail-modal-card {
  position: relative;
  width: min(1540px, 100%);
  max-height: calc(100vh - 36px);
  padding: 34px 20px 20px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  overflow-y: auto;
}

.detail-close-button {
  position: absolute;
  top: 10px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  color: #dc2626;
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.detail-close-button:hover,
.detail-close-button:focus-visible {
  color: #991b1b;
  background: #fef2f2;
}

.detail-close-button[hidden] {
  display: none;
}

.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.detail-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 48px;
}

.detail-heading p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-heading h2 {
  margin: 0;
  color: var(--navy-strong);
  font-size: 24px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

.detail-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.detail-panel h3,
.detail-lines h3 {
  margin: 0;
  font-size: 15px;
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 24px;
  margin: 18px 0 0;
}

.detail-list.supplier-details {
  grid-template-columns: 1fr;
}

.detail-list div {
  min-width: 0;
}

.detail-list dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: #34425a;
  font-size: 13px;
  font-weight: 600;
}

.detail-lines {
  margin-top: 12px;
}

.line-items-table {
  min-width: 1680px;
}

.edit-form[hidden],
.detail-heading-actions [hidden],
#detailContent[hidden] {
  display: none;
}

.edit-form {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

.edit-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.edit-field {
  display: grid;
  gap: 6px;
}

.edit-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.edit-field input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid #cfd7e3;
  border-radius: 5px;
  color: #34425a;
  background: white;
}

.edit-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
  outline: none;
}

.edit-field input[readonly] {
  color: var(--muted);
  background: #eef2f6;
}

.edit-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 20px;
}

.edit-form-primary-actions {
  display: flex;
  gap: 8px;
}

.edit-lines-section {
  margin-top: 24px;
}

.edit-lines-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.edit-lines-heading h3 {
  margin: 0;
  font-size: 15px;
}

.edit-lines-heading span {
  color: var(--muted);
  font-size: 11px;
}

.edit-line-card {
  margin: 0 0 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.edit-line-card legend {
  padding: 0 6px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
}

.edit-line-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.comments-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.comments-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.comments-heading h3 {
  margin: 0;
  font-size: 15px;
}

.comments-heading span,
.communication-empty {
  color: var(--muted);
  font-size: 12px;
}

.communication-history {
  display: grid;
  gap: 10px;
  max-height: 300px;
  margin: 12px 0;
  overflow-y: auto;
}

.communication-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.communication-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.communication-header > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.communication-header > .communication-header-actions {
  align-items: flex-end;
  flex-direction: column;
  flex-shrink: 0;
  gap: 5px;
}

.communication-header strong {
  color: var(--ink);
}

.communication-kind {
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.communication-kind.comment {
  color: #3f4d63;
  background: #e8edf5;
}

.communication-kind.email {
  color: #067066;
  background: #dff7f2;
}

.communication-subject {
  margin-top: 9px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
}

.communication-recipients {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.communication-message {
  margin-top: 8px;
  color: #34425a;
  font-size: 12px;
  line-height: 1.5;
}

.communication-error {
  margin-top: 8px;
  color: var(--red);
  font-size: 11px;
}

.communication-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.communication-actions button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid #cbd4e1;
  border-radius: 4px;
  color: #34425a;
  background: white;
  font-size: 11px;
  font-weight: 600;
}

.communication-actions .delete-communication-button {
  border-color: #fecaca;
  color: #b42318;
}

.comment-composer {
  border: 2px solid var(--blue);
  border-radius: 5px;
  background: white;
  overflow: hidden;
}

.comment-composer[hidden] {
  display: none;
}

.comment-collapsed-button {
  width: 100%;
  height: 41px;
  padding: 0 14px;
  border: 2px solid var(--blue);
  border-radius: 5px;
  color: #64748b;
  background: #f8fafc;
  text-align: left;
}

.comment-collapsed-button:hover,
.comment-collapsed-button:focus-visible {
  border-color: #1d4ed8;
  color: #34425a;
  background: white;
  outline: none;
}

.comment-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.comment-toolbar button,
.comment-toolbar select {
  min-width: 34px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid #cfd7e3;
  border-radius: 4px;
  color: #26344b;
  background: white;
}

.comment-toolbar .comment-close-button {
  margin-left: auto;
  border-color: transparent;
  border-radius: 50%;
  color: white;
  background: #ef4444;
  font-size: 18px;
  line-height: 1;
}

.comment-toolbar .comment-close-button:hover,
.comment-toolbar .comment-close-button:focus-visible {
  background: #b91c1c;
}

.comment-editor {
  min-height: 110px;
  padding: 14px;
  color: #34425a;
  outline: none;
  overflow-y: auto;
}

.comment-editor:empty::before {
  color: #94a3b8;
  content: attr(data-placeholder);
  pointer-events: none;
}

.comment-notify-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #eef2f6;
}

.comment-notify-row fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.comment-notify-row legend {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 11px;
}

.comment-recipients {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.comment-recipients label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #34425a;
  font-size: 11px;
}

@media (max-width: 1080px) {
  .filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .header-inner {
    align-items: stretch;
    flex-direction: column;
    padding: 14px 0;
  }

  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .table-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-actions {
    width: 100%;
    justify-content: space-between;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .edit-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .edit-line-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .header-inner,
  .page-shell {
    width: min(100% - 20px, 1280px);
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 14px;
  }

  .tab {
    font-size: 12px;
  }

  .table-actions,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }

  .detail-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .edit-form-grid {
    grid-template-columns: 1fr;
  }

  .edit-line-grid {
    grid-template-columns: 1fr;
  }

  .detail-modal {
    padding: 10px;
  }

  .detail-modal-card {
    max-height: calc(100vh - 20px);
    padding: 42px 12px 12px;
  }
}
