/* Purchase Order Create — premium form UI */

.po-create {
  max-width: 1280px;
  margin: 0 auto;
  padding-bottom: 24px;
  min-width: 0;
  container-type: inline-size;
  container-name: po;
}

.po-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 280px);
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.po-main { min-width: 0; }

.po-aside {
  position: sticky;
  top: 84px;
}

.po-section-head {
  margin-bottom: 18px;
}

.po-section-head .po-card-title {
  margin-bottom: 0;
}

.po-supplier-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.po-supplier-select {
  flex: 1;
  min-width: 0;
}

.po-add-supplier {
  flex: none;
  white-space: nowrap;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
}

.po-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  margin-bottom: 12px;
}

.po-empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 12px;
}

.po-empty-icon svg { width: 28px; height: 28px; }

.po-empty h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.po-empty p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  max-width: 320px;
}

.po-tax-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.po-summary-lines div {
  border-bottom: 1px solid #f1f5f9;
}

/* Sticky inside the form so it always shares the form's width, whatever the sidebar state. */
.po-form-actions {
  position: sticky;
  bottom: 12px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 4px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 -4px 20px rgba(11, 15, 25, 0.06);
  backdrop-filter: blur(8px);
}

.po-form-actions .btn { white-space: nowrap; }

@media (max-width: 1100px) {
  .po-workspace { grid-template-columns: 1fr; }
  .po-aside { position: static; }
}

@container po (max-width: 1180px) {
  .po-workspace { grid-template-columns: minmax(0, 1fr); }
  .po-aside { position: static; }
}

@media (max-width: 768px) {
  .content:has(.po-create) {
    padding: 16px 14px 110px;
  }
  .po-supplier-row { flex-direction: column; }
  .po-add-supplier { width: 100%; justify-content: center; }
  .po-form-actions {
    bottom: calc(var(--bottom-h, 72px) + 8px + env(safe-area-inset-bottom, 0px));
    padding: 10px 12px;
  }
  .po-form-actions .po-save-btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 359px) {
  .po-form-actions { flex-direction: column-reverse; align-items: stretch; }
  .po-form-actions .btn { width: 100%; justify-content: center; }
}

html[data-theme="dark"] .po-form-actions {
  background: rgba(21, 28, 46, 0.96);
  border-color: #273049;
}

.po-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

.po-breadcrumb a {
  color: var(--text-soft);
  font-weight: 600;
}

.po-breadcrumb a:hover {
  color: var(--primary);
}

.po-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.po-page-head-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.po-page-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: none;
}

.po-page-icon svg {
  width: 24px;
  height: 24px;
}

.po-page-head h1 {
  margin: 0;
  font-size: clamp(24px, 2.5vw, 30px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.po-page-head p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.po-back-btn,
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.po-back-btn:hover,
.btn-secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

/* Cards */
.po-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(11, 15, 25, 0.04);
  padding: 22px;
  margin-bottom: 20px;
}

.po-card-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.po-card-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.po-card-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.po-card-head-copy {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.po-section-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: none;
}

.po-section-icon svg {
  width: 20px;
  height: 20px;
}

.po-card-head-row .po-card-title {
  margin-bottom: 0;
}

/* Grids */
.po-grid {
  display: grid;
  gap: 16px;
}

.po-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.po-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.po-bottom-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* Fields */
.po-field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.po-req {
  color: var(--primary);
}

.po-help {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.po-help-warn {
  color: var(--warning);
}

.po-control {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.po-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.14);
}

.po-control:read-only {
  background: var(--surface-muted);
  color: var(--muted);
  cursor: default;
}

.po-control-sm {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 13px;
}

.po-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

.po-select-wrap {
  position: relative;
}

.po-select-wrap::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.po-select-wrap select {
  appearance: none;
  padding-right: 36px;
}

/* Items table */
.po-items-card {
  overflow: visible;
}

.po-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 12px;
}

.po-items-table {
  width: 100%;
  min-width: 866px;
  border-collapse: collapse;
}

/* Keep rows as real table rows even if a shared row class is ever reapplied. */
.po-items-table tbody tr.p-row { display: table-row; }
.po-items-table tbody tr.p-row > td { display: table-cell; }

.po-items-table thead th {
  padding: 11px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.po-items-table tbody td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  background: var(--surface);
}

.po-items-table tbody tr:last-child td {
  border-bottom: 0;
}

.po-items-table tbody tr:hover td {
  background: var(--surface-hover);
}

.po-col-num {
  width: 36px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}

.po-col-product .po-control { min-width: 140px; }
.po-col-desc .po-control { min-width: 80px; }
.po-col-qty { width: 72px; }
.po-col-unit { width: 118px; }
.po-col-rate { width: 112px; }
.po-col-tax { width: 112px; }
.po-col-total { width: 100px; font-weight: 700; text-align: right; white-space: nowrap; }
.po-col-action { width: 64px; text-align: center; }

.po-line-total {
  font-variant-numeric: tabular-nums;
}

.po-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #fecaca;
  border-radius: 9px;
  background: #fff;
  color: #dc2626;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.po-remove-btn svg {
  width: 16px;
  height: 16px;
}

.po-remove-btn:hover {
  background: #fef2f2;
  border-color: #f87171;
}

.po-add-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.po-add-link svg {
  width: 16px;
  height: 16px;
}

.po-add-link:hover {
  text-decoration: underline;
}

/* Summary */
.po-summary-card {
  align-self: start;
}

.po-summary-lines {
  margin: 0 0 12px;
}

.po-summary-lines div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  font-size: 14px;
}

.po-summary-lines dt {
  color: var(--muted);
  font-weight: 600;
}

.po-summary-lines dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.po-summary-grand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  margin: 8px 0 16px;
  border-radius: 12px;
  background: var(--primary-soft);
  border: 1px solid rgba(255, 107, 0, 0.2);
}

.po-summary-grand span {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.po-summary-grand strong {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.po-amount-words {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.po-amount-words span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.po-amount-words p {
  margin: 0;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 600;
}

.po-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
}

.po-save-btn svg {
  width: 18px;
  height: 18px;
}

/* Responsive — stacked item rows on mobile */
@media (max-width: 960px) {
  .po-grid-2,
  .po-grid-3,
  .po-bottom-grid {
    grid-template-columns: 1fr;
  }
}

/* Stacked item cards: below this width the 9-column table cannot fit without scrolling. */
@media (max-width: 900px) {
  .po-table-wrap {
    border: 0;
    overflow: visible;
  }

  .po-items-table {
    min-width: 0;
  }

  .po-items-table thead {
    display: none;
  }

  .po-items-table tbody tr.p-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 12px;
    background: var(--surface);
  }

  .po-items-table tbody tr.p-row td {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-column: 1 / -1;
    gap: 6px;
    align-items: center;
    width: auto;
    padding: 6px 0;
    border: 0;
    background: transparent !important;
    text-align: left;
  }

  .po-items-table tbody tr.p-row td.po-col-qty,
  .po-items-table tbody tr.p-row td.po-col-unit {
    grid-column: auto;
  }

  .po-col-product .po-control,
  .po-col-desc .po-control { min-width: 0; }

  .po-items-table tbody tr.p-row td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .po-items-table tbody tr.p-row td.po-col-num {
    font-size: 13px;
  }

  .po-items-table tbody tr.p-row td.po-col-num::before,
  .po-items-table tbody tr.p-row td.po-col-action::before {
    display: none;
  }

  .po-items-table tbody tr.p-row td.po-col-action {
    justify-items: end;
  }

  .po-col-total.po-line-total {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .po-control,
  .po-remove-btn {
    transition: none;
  }
}

/* Dark mode */
html[data-theme="dark"] .po-card,
html[data-theme="dark"] .po-form-actions {
  background: #151c2e;
  border-color: #273049;
}

html[data-theme="dark"] .po-items-table thead th {
  background: #1b2438;
}

html[data-theme="dark"] .po-items-table tbody td {
  background: #151c2e;
}

html[data-theme="dark"] .po-control {
  background: #151c2e;
  border-color: #273049;
  color: #f8fafc;
}

html[data-theme="dark"] .po-control:read-only {
  background: #1b2438;
}

html[data-theme="dark"] .po-summary-grand {
  background: rgba(255, 107, 0, 0.1);
  border-color: rgba(255, 107, 0, 0.25);
}

html[data-theme="dark"] .po-remove-btn {
  background: #151c2e;
  border-color: #7f1d1d;
}

.content:has(.po-create) {
  padding: 24px;
  background: #f5f6f8;
}

html[data-theme="dark"] .content:has(.po-create) {
  background: #0b1220;
}

@media (max-width: 768px) {
  .content:has(.po-create) {
    padding: 16px 14px 110px;
  }
}

.po-items-table .p-name.is-invalid {
  border-color: var(--danger, #dc2626);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* Item suggestions live in <body> so the table's horizontal scroll box never clips them. */
.pi-ac-layer {
  position: absolute;
  z-index: 1200;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface, #fff);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(11, 15, 25, 0.14);
  font-size: 13px;
}

.pi-ac-layer[hidden] { display: none; }

.pi-ac-opt {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.pi-ac-opt:hover,
.pi-ac-opt[aria-selected="true"] {
  background: var(--primary-soft);
}

.pi-ac-name {
  font-weight: 600;
  color: var(--text);
  overflow-wrap: anywhere;
}

.pi-ac-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.pi-ac-note {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

html[data-theme="dark"] .pi-ac-layer {
  background: #151c2e;
  border-color: #273049;
}
