#purchaseNotesSection,
#purchaseNotesDetailOverlay {
  --pn-ink: #151c28;
  --pn-muted: #687382;
  --pn-border: #dfe5ea;
  --pn-soft: #f5f8fa;
  --pn-orange: #ff5a00;
  color: var(--pn-ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#purchaseNotesSection *,
#purchaseNotesDetailOverlay * { box-sizing: border-box; }

#purchaseNotesSection button,
#purchaseNotesSection input,
#purchaseNotesSection select,
#purchaseNotesSection textarea,
#purchaseNotesDetailOverlay button { font: inherit; }

.purchase-notes-shell { width: 100%; max-width: 1540px; margin: 0 auto; }
.purchase-notes-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.purchase-notes-eyebrow { display: block; margin-bottom: 5px; color: var(--pn-orange); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.purchase-notes-header h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.12; letter-spacing: 0; }
.purchase-notes-header p { margin: 0; color: var(--pn-muted); font-size: 14px; }

.pn-button,
.pn-icon-button {
  min-height: 42px;
  border: 1px solid var(--pn-border);
  border-radius: 8px;
  background: #fff;
  color: #263140;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.pn-button:hover,.pn-icon-button:hover { border-color: #ffa778; background: #fffaf7; transform: translateY(-1px); }
.pn-button.primary { border-color: var(--pn-orange,#ff5a00); background: var(--pn-orange,#ff5a00); color: #fff; box-shadow: 0 8px 20px rgba(255,90,0,.17); }
.pn-button.primary:hover { background: #e95000; border-color: #e95000; }
#purchaseNotesDetailOverlay .pn-button.primary { border-color: #ff5a00; background: #ff5a00; color: #fff; }
.pn-button.danger { color: #b42318; border-color: #f0c8c4; }
.pn-button:disabled,.pn-icon-button:disabled { opacity: .52; cursor: not-allowed; transform: none; }
.pn-button svg,.pn-icon-button svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pn-icon-button { width: 38px; min-height: 38px; padding: 0; }

.purchase-note-workspace { display: block; }
.purchase-note-editor,
.purchase-notes-history {
  border: 1px solid var(--pn-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(24,34,46,.045);
}
.purchase-note-editor-head { min-height: 67px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid var(--pn-border); }
.purchase-note-editor-head h2 { margin: 0 0 3px; font-size: 18px; letter-spacing: 0; }
.purchase-note-editor-head p { margin: 0; color: var(--pn-muted); font-size: 12.5px; }
.pn-status { min-height: 28px; display: inline-flex; align-items: center; border-radius: 6px; padding: 0 10px; background: #eef2f5; color: #5c6875; font-size: 11px; font-weight: 900; text-transform: uppercase; }
.pn-status.generated { background: #e7f7ed; color: #187743; }
.purchase-note-form { padding: 18px; }
.pn-form-grid { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 15px; }
.pn-field { grid-column: span 2; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.pn-field.half { grid-column: span 3; }
.pn-field.full { grid-column: 1/-1; }
.pn-field > span,.pn-field > label { color: #3e4856; font-size: 12px; font-weight: 850; }
.pn-field input,.pn-field select,.pn-field textarea {
  width: 100%; min-height: 46px; border: 1px solid #d7dde4; border-radius: 7px; background: #fff; color: var(--pn-ink); padding: 10px 12px; outline: none; font-size: 14px;
}
.pn-field textarea { min-height: 86px; resize: vertical; line-height: 1.45; }
.pn-field input:focus,.pn-field select:focus,.pn-field textarea:focus,.pn-item-row input:focus { border-color: var(--pn-orange); box-shadow: 0 0 0 3px rgba(255,90,0,.1); }
.pn-field input[readonly],.pn-field input:disabled { background: #f4f6f8; color: #3f4a58; font-weight: 750; }
.pn-field-note { color: #89929c; font-size: 11px; }
.pn-combobox { position: relative; min-width: 0; }
.pn-combobox > input { padding-right: 38px; background-image: linear-gradient(45deg,transparent 50%,#5f6975 50%),linear-gradient(135deg,#5f6975 50%,transparent 50%); background-position: calc(100% - 18px) 20px,calc(100% - 13px) 20px; background-size: 5px 5px,5px 5px; background-repeat: no-repeat; }
.pn-suggestions { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; right: 0; max-height: 280px; overflow-y: auto; padding: 6px; border: 1px solid #d9e0e5; border-radius: 8px; background: #fff; box-shadow: 0 14px 34px rgba(20,30,42,.16); }
.pn-suggestions[hidden] { display: none; }
.pn-suggestions button { width: 100%; min-height: 54px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 3px; padding: 9px 11px; border: 0; border-radius: 6px; background: transparent; color: #202936; text-align: left; cursor: pointer; }
.pn-suggestions button:hover,.pn-suggestions button.active { background: #fff3ec; }
.pn-suggestions button strong { max-width: 100%; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-suggestions button span { max-width: 100%; color: #727d89; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-suggestions-empty { padding: 15px 11px; color: #7c8793; font-size: 12px; text-align: center; }

.pn-items-block { margin-top: 22px; border-top: 1px solid var(--pn-border); padding-top: 18px; }
.pn-items-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.pn-items-head h3 { margin: 0 0 3px; font-size: 15px; letter-spacing: 0; }
.pn-items-head p { margin: 0; color: var(--pn-muted); font-size: 12px; }
.pn-items-labels,.pn-item-row { display: grid; grid-template-columns: 100px minmax(180px,1fr) 145px 118px; gap: 8px; align-items: center; }
.pn-items-labels { min-height: 34px; padding: 0 4px; color: #737e8c; font-size: 10.5px; font-weight: 900; text-transform: uppercase; }
.pn-item-row { padding: 8px 0; border-top: 1px solid #edf0f3; }
.pn-item-row input,.pn-item-row select { width: 100%; min-height: 42px; border: 1px solid #dbe0e6; border-radius: 7px; padding: 8px 10px; background: #fff; color: var(--pn-ink); outline: none; font-size: 13px; }
.pn-item-row select { cursor: pointer; }
.pn-item-row input:focus,.pn-item-row select:focus { border-color: var(--pn-orange); box-shadow: 0 0 0 3px rgba(255,90,0,.1); }
.pn-item-actions { display: flex; justify-content: flex-end; gap: 4px; }
.pn-item-actions .pn-icon-button { width: 34px; min-height: 34px; }
.pn-items-empty { padding: 24px; border: 1px dashed #d8dee5; border-radius: 7px; color: var(--pn-muted); text-align: center; font-size: 13px; }
.pn-form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 20px; padding-top: 17px; border-top: 1px solid var(--pn-border); }
.pn-form-actions .spacer { flex: 1; }

.purchase-note-preview-wrap { position: sticky; top: 18px; padding: 15px; background: #eef2f5; }
.pn-preview-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; color: #566170; font-size: 12px; font-weight: 850; }
.purchase-note-paper { position: relative; width: 100%; aspect-ratio: 210/297; min-height: 600px; background: #fff; padding: 5.4% 5.4% 13%; box-shadow: 0 8px 24px rgba(18,28,40,.12); overflow: hidden; }
.pn-paper-head { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 18px; padding-bottom: 18px; border-bottom: 2px solid #1d2735; }
.pn-paper-brand { display: flex; align-items: center; gap: 10px; }
.pn-paper-brand img { width: 84px; max-height: 48px; object-fit: contain; }
.pn-paper-brand strong { font-size: 12px; }
.pn-paper-title { text-align: right; white-space: nowrap; }
.pn-paper-title strong { display: block; font-size: 18px; }
.pn-paper-title span { color: #4f5a68; font-size: 10px; }
.pn-paper-meta { margin: 20px 0 18px; }
.pn-paper-meta div { display: grid; grid-template-columns: 105px 1fr; gap: 10px; min-height: 32px; align-items: center; border-bottom: 1px solid #9aa3ae; font-size: 10px; }
.pn-paper-meta b { color: #4d5764; }
.pn-paper-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 9px; }
.pn-paper-table th,.pn-paper-table td { border: 1px solid #69727d; padding: 7px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.pn-paper-table th { background: #f0f2f4; font-size: 8px; text-transform: uppercase; }
.pn-paper-table th:first-child,.pn-paper-table td:first-child { width: 19%; text-align: center; }
.pn-paper-table th:last-child,.pn-paper-table td:last-child { width: 24%; text-align: center; }
.pn-paper-placeholder { color: #a0a8b1; }
.pn-paper-trace { margin-top: 20px; padding: 11px; border: 1px solid #ced4dc; border-radius: 4px; font-size: 8px; color: #5f6976; }
.pn-paper-trace strong { display: block; margin-bottom: 4px; color: #202936; font-size: 9px; }
.pn-paper-footer-brand { position: absolute; left: 5.4%; bottom: 3.8%; display: flex; align-items: center; gap: 7px; color: #7a8490; font-size: 7px; }
.pn-paper-footer-brand img { width: 58px; height: 20px; object-fit: contain; object-position: left center; }

.purchase-notes-history { margin-top: 18px; overflow: hidden; }
.pn-history-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 17px 18px; border-bottom: 1px solid var(--pn-border); }
.pn-history-head h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: 0; }
.pn-history-head p { margin: 0; color: var(--pn-muted); font-size: 12px; }
.pn-history-count { color: #5e6976; font-size: 12px; font-weight: 800; }
.pn-filters { display: grid; grid-template-columns: minmax(210px,1.35fr) repeat(7,minmax(112px,1fr)) 42px; gap: 8px; padding: 13px 18px; background: #f8fafb; border-bottom: 1px solid var(--pn-border); }
.pn-filters-simple { grid-template-columns: minmax(280px,1fr) repeat(2,minmax(150px,220px)) 42px; }
.pn-filter { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.pn-filter span { color: #727d8a; font-size: 9.5px; font-weight: 900; text-transform: uppercase; }
.pn-filter input,.pn-filter select { width: 100%; height: 40px; border: 1px solid #dce2e7; border-radius: 7px; background: #fff; padding: 0 10px; color: #27313e; font-size: 12px; outline: none; }
.pn-filter input:focus,.pn-filter select:focus { border-color: var(--pn-orange); box-shadow: 0 0 0 3px rgba(255,90,0,.08); }
.pn-filters > .pn-icon-button { align-self: end; min-height: 40px; }
.pn-table-scroll { width: 100%; overflow-x: auto; }
.pn-history-table { width: 100%; min-width: 780px; border-collapse: collapse; table-layout: fixed; }
.pn-history-table th { height: 43px; padding: 0 14px; background: #fff; border-bottom: 1px solid var(--pn-border); color: #697482; font-size: 10px; font-weight: 900; text-align: left; text-transform: uppercase; }
.pn-history-table td { min-height: 62px; padding: 13px 14px; border-bottom: 1px solid #edf0f2; color: #303a47; font-size: 12.5px; vertical-align: middle; }
.pn-history-table tbody tr:hover { background: #fffaf7; }
.pn-note-number { color: #17202d; font-weight: 900; }
.pn-note-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.pn-note-heading .pn-status { min-height: 22px; padding: 0 7px; font-size: 9px; }
.pn-destination-provider { display: block; color: #26313e; font-size: 12.5px; }
.pn-secondary { display: block; margin-top: 3px; color: #7b8591; font-size: 11px; }
.pn-row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.pn-row-actions .pn-icon-button { width: 34px; min-height: 34px; }
.pn-table-empty { padding: 42px 20px !important; color: var(--pn-muted) !important; text-align: center; }
.pn-pagination { min-height: 61px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 18px; }
.pn-pagination span { color: var(--pn-muted); font-size: 12px; }
.pn-pagination-actions { display: flex; align-items: center; gap: 7px; }

.purchase-notes-overlay { position: fixed; inset: 0; z-index: 10120; display: grid; place-items: center; padding: 22px; background: rgba(15,23,34,.56); backdrop-filter: blur(4px); }
.purchase-notes-overlay[hidden] { display: none; }
body.purchase-note-detail-open .notification-center,
body.purchase-note-detail-open .mobile-bell,
body.purchase-note-detail-open .ai-launcher { display: none !important; }
.purchase-notes-detail { width: min(900px,100%); max-height: calc(100vh - 44px); overflow: auto; border-radius: 8px; background: #fff; box-shadow: 0 26px 80px rgba(0,0,0,.25); }
.pn-detail-head { position: sticky; top: 0; z-index: 2; min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--pn-border); background: #fff; }
.pn-detail-head h2 { margin: 0 0 3px; font-size: 20px; }
.pn-detail-head p { margin: 0; color: var(--pn-muted); font-size: 12px; }
.pn-detail-body { padding: 20px; }
.pn-detail-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 0; border: 1px solid var(--pn-border); border-radius: 7px; overflow: hidden; }
.pn-detail-grid div { min-height: 74px; padding: 14px; border-right: 1px solid var(--pn-border); border-bottom: 1px solid var(--pn-border); }
.pn-detail-grid div:nth-child(3n) { border-right: 0; }
.pn-detail-grid div:nth-last-child(-n+3) { border-bottom: 0; }
.pn-detail-grid span { display: block; margin-bottom: 5px; color: #798491; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.pn-detail-grid strong { font-size: 13px; overflow-wrap: anywhere; }
.pn-detail-observations { margin: 18px 0; padding: 14px; border-left: 3px solid var(--pn-orange); background: #fff8f4; color: #3c4653; font-size: 13px; white-space: pre-wrap; }
.pn-detail-items { width: 100%; border-collapse: collapse; }
.pn-detail-items th,.pn-detail-items td { padding: 11px 12px; border-bottom: 1px solid var(--pn-border); font-size: 12px; text-align: left; }
.pn-detail-items th { color: #6d7885; font-size: 10px; text-transform: uppercase; }
.pn-detail-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--pn-border); }

.pn-module-status { margin-bottom: 12px; padding: 10px 13px; border: 1px solid #f3cdb9; border-radius: 7px; background: #fff8f4; color: #a84113; font-size: 12px; font-weight: 700; }
.pn-module-status[hidden] { display: none; }

@media (max-width: 1220px) {
  .purchase-note-preview-wrap { position: static; }
  .purchase-note-paper { max-width: 650px; margin: 0 auto; }
  .pn-filters:not(.pn-filters-simple) { grid-template-columns: repeat(3,minmax(150px,1fr)); }
}

@media (max-width: 700px) {
  .purchase-notes-header { align-items: stretch; flex-direction: column; gap: 14px; }
  .purchase-notes-header h1 { font-size: 26px; }
  .purchase-notes-header .pn-button { width: 100%; }
  .purchase-note-editor-head { align-items: flex-start; }
  .purchase-note-form { padding: 14px; }
  .pn-form-grid { grid-template-columns: 1fr; }
  .pn-field,.pn-field.half,.pn-field.full { grid-column: auto; }
  .pn-items-labels { display: none; }
  .pn-item-row { grid-template-columns: 88px minmax(0,1fr); gap: 8px; padding: 12px 0; }
  .pn-item-row input[data-item-field="description"],.pn-item-row select[data-item-field="unit"] { grid-column: 1/-1; }
  .pn-item-actions { grid-column: 1/-1; justify-content: flex-start; }
  .pn-item-actions .pn-icon-button { min-width: 42px; min-height: 42px; }
  .pn-form-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .pn-form-actions .spacer { display: none; }
  .pn-form-actions .primary { grid-column: 1/-1; grid-row: 1; }
  .purchase-note-preview-wrap { display: none; }
  .pn-filters-simple { grid-template-columns: 1fr 1fr; padding: 12px; }
  .pn-filters-simple .pn-filter:first-child { grid-column: 1/-1; }
  .pn-history-head { align-items: flex-start; flex-direction: column; }
  .pn-pagination { align-items: stretch; flex-direction: column; }
  .pn-pagination-actions { justify-content: space-between; }
  .purchase-notes-overlay { padding: 0; place-items: stretch; }
  .purchase-notes-detail { width: 100%; max-height: 100vh; min-height: 100vh; border-radius: 0; }
  .pn-detail-grid { grid-template-columns: 1fr 1fr; }
  .pn-detail-grid div,.pn-detail-grid div:nth-child(3n),.pn-detail-grid div:nth-last-child(-n+3) { border-right: 1px solid var(--pn-border); border-bottom: 1px solid var(--pn-border); }
  .pn-detail-grid div:nth-child(2n) { border-right: 0; }
  .pn-detail-grid div:last-child { border-bottom: 0; }
  .pn-detail-actions { position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; background: #fff; }
}

@media (max-width: 430px) {
  .pn-filters-simple { grid-template-columns: 1fr; }
  .pn-filters-simple .pn-filter:first-child { grid-column: auto; }
  .pn-detail-grid { grid-template-columns: 1fr; }
  .pn-detail-grid div,.pn-detail-grid div:nth-child(2n) { border-right: 0; }
}
