/* Purchase Bill Create — premium form UI */

.content:has(.pb-create) {
  padding: 24px;
  background: #f6f7f9;
}

.pb-create {
  max-width: 1280px;
  margin: 0 auto;
  padding-bottom: 24px;
  min-width: 0;
  container-type: inline-size;
  container-name: pb;
}

.pb-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

.pb-breadcrumb a {
  color: var(--text-soft);
  font-weight: 600;
}

.pb-breadcrumb a:hover {
  color: var(--primary);
}

.pb-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.pb-page-head-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.pb-page-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: none;
}

.pb-page-icon svg {
  width: 24px;
  height: 24px;
}

.pb-page-head h1 {
  margin: 0;
  font-size: clamp(26px, 2.5vw, 32px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.pb-page-head p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.pb-back-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.pb-back-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

/* Workspace layout */
.pb-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 280px);
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.pb-main {
  min-width: 0;
}

.pb-aside {
  position: sticky;
  top: 84px;
}

/* Cards */
.pb-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;
}

.pb-section-head {
  margin-bottom: 18px;
}

.pb-card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.pb-section-head .pb-card-title {
  margin-bottom: 0;
}

.pb-card-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.pb-card-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.pb-card-head-copy {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.pb-section-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: none;
}

.pb-section-icon svg {
  width: 20px;
  height: 20px;
}

.pb-card-head-row .pb-card-title {
  margin-bottom: 0;
}

/* Grids */
.pb-grid {
  display: grid;
  gap: 16px;
}

.pb-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Supplier row */
.pb-supplier-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.pb-supplier-select {
  flex: 1;
  min-width: 0;
}

.pb-add-supplier {
  flex: none;
  white-space: nowrap;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
}

/* Fields */
.pb-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.pb-req {
  color: var(--primary);
}

.pb-help {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.pb-help-warn {
  color: var(--warning);
}

.pb-control {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.pb-control:hover:not(:read-only):not(:disabled) {
  border-color: var(--line-strong);
}

.pb-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.14);
}

.pb-control:read-only,
.pb-control:disabled {
  background: var(--surface-muted);
  color: var(--muted);
  cursor: default;
}

.pb-control-sm {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 13px;
}

.pb-textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

.pb-select-wrap {
  position: relative;
}

.pb-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;
}

.pb-select-wrap select {
  appearance: none;
  padding-right: 36px;
}

/* Empty state */
.pb-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;
}

.pb-empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 12px;
}

.pb-empty-icon svg {
  width: 28px;
  height: 28px;
}

.pb-empty h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.pb-empty p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  max-width: 320px;
}

/* Items table */
.pb-items-card {
  overflow: visible;
}

.pb-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 12px;
}

.pb-items-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

/* Keep rows as real table rows even if a shared row class is ever reapplied. */
.pb-items-table tbody tr.p-row { display: table-row; }
.pb-items-table tbody tr.p-row > td { display: table-cell; }

.pb-items-table thead th {
  padding: 12px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.pb-items-table tbody td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  background: var(--surface);
}

.pb-items-table tbody tr:last-child td {
  border-bottom: 0;
}

.pb-items-table tbody tr:hover td {
  background: rgba(255, 107, 0, 0.02);
}

.pb-col-num { width: 40px; text-align: center; font-weight: 700; color: var(--muted); }
.pb-col-product .pb-control { min-width: 140px; }
.pb-col-desc .pb-control { min-width: 90px; }
.pb-col-qty { width: 72px; }
.pb-col-unit { width: 118px; }
.pb-col-rate { width: 112px; }
.pb-col-tax { width: 112px; }
.pb-col-total { width: 100px; font-weight: 700; text-align: right; white-space: nowrap; }
.pb-col-action { width: 64px; text-align: center; }

.pb-line-total {
  font-variant-numeric: tabular-nums;
}

.pb-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.18s ease, border-color 0.18s ease;
}

.pb-remove-btn svg {
  width: 16px;
  height: 16px;
}

.pb-remove-btn:hover {
  background: #fef2f2;
  border-color: #f87171;
}

.pb-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;
}

.pb-add-link svg {
  width: 16px;
  height: 16px;
}

.pb-add-link:hover {
  text-decoration: underline;
}

/* Summary */
.pb-summary-card {
  margin-bottom: 0;
}

.pb-summary-lines {
  margin: 0 0 12px;
}

.pb-summary-lines div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  font-size: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.pb-summary-lines div:last-child {
  border-bottom: 0;
}

.pb-summary-lines dt {
  color: var(--muted);
  font-weight: 600;
}

.pb-summary-lines dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pb-summary-grand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin: 12px 0 0;
  border-radius: 12px;
  background: var(--primary-soft);
  border: 1px solid rgba(255, 107, 0, 0.2);
}

.pb-summary-grand span {
  font-size: 14px;
  font-weight: 700;
}

.pb-summary-grand strong {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.pb-tax-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.pb-notes-card {
  margin-bottom: 0;
}

/* Sticky inside the form so it always shares the form's width, whatever the sidebar state. */
.pb-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);
}

.pb-form-actions .btn { white-space: nowrap; }

.pb-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 22px;
}

.pb-save-btn svg {
  width: 18px;
  height: 18px;
}

/* Responsive */
@media (max-width: 1100px) {
  .pb-workspace {
    grid-template-columns: 1fr;
  }

  .pb-aside {
    position: static;
  }
}

@container pb (max-width: 1180px) {
  .pb-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .pb-aside {
    position: static;
  }
}

@media (max-width: 768px) {
  .content:has(.pb-create) {
    padding: 16px 14px 110px;
  }

  .pb-grid-2 {
    grid-template-columns: 1fr;
  }

  .pb-supplier-row {
    flex-direction: column;
  }

  .pb-add-supplier {
    width: 100%;
    justify-content: center;
  }

  .pb-form-actions {
    bottom: calc(var(--bottom-h, 72px) + 8px + env(safe-area-inset-bottom, 0px));
    padding: 10px 12px;
  }

  .pb-form-actions .pb-save-btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

@media (max-width: 359px) {
  .pb-form-actions { flex-direction: column-reverse; align-items: stretch; }
  .pb-form-actions .btn { width: 100%; justify-content: center; }
}

/* Stacked item cards: below this width the 9-column table cannot fit without scrolling. */
@media (max-width: 900px) {
  .pb-table-wrap {
    border: 0;
    overflow: visible;
  }

  .pb-items-table {
    min-width: 0;
  }

  .pb-items-table thead {
    display: none;
  }

  .pb-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);
  }

  .pb-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;
  }

  .pb-items-table tbody tr.p-row td.pb-col-qty,
  .pb-items-table tbody tr.p-row td.pb-col-unit {
    grid-column: auto;
  }

  .pb-col-product .pb-control,
  .pb-col-desc .pb-control { min-width: 0; }

  .pb-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);
  }

  .pb-items-table tbody tr.p-row td.pb-col-num {
    font-size: 13px;
  }

  .pb-items-table tbody tr.p-row td.pb-col-num::before,
  .pb-items-table tbody tr.p-row td.pb-col-action::before {
    display: none;
  }

  .pb-items-table tbody tr.p-row td.pb-col-action {
    justify-items: end;
  }

  .pb-col-total.pb-line-total {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pb-control,
  .pb-remove-btn {
    transition: none;
  }
}

html[data-theme="dark"] .content:has(.pb-create) {
  background: #0b1220;
}

html[data-theme="dark"] .pb-card {
  background: #151c2e;
  border-color: #273049;
}

html[data-theme="dark"] .pb-items-table thead th {
  background: #1b2438;
}

html[data-theme="dark"] .pb-items-table tbody td {
  background: #151c2e;
}

html[data-theme="dark"] .pb-control {
  background: #151c2e;
  border-color: #273049;
  color: #f8fafc;
}

html[data-theme="dark"] .pb-control:read-only,
html[data-theme="dark"] .pb-control:disabled {
  background: #1b2438;
}

html[data-theme="dark"] .pb-summary-grand {
  background: rgba(255, 107, 0, 0.1);
  border-color: rgba(255, 107, 0, 0.25);
}

html[data-theme="dark"] .pb-remove-btn {
  background: #151c2e;
  border-color: #7f1d1d;
}

html[data-theme="dark"] .pb-form-actions {
  background: rgba(21, 28, 46, 0.96);
  border-color: #273049;
}
.pb-dropzone {
  position: relative;
  border: 1.5px dashed #d1d5db;
  border-radius: 14px;
  padding: 22px 16px;
  background: #fafafa;
  text-align: center;
}
.pb-dropzone.is-drag { border-color: var(--primary, #ff6a00); background: #fff7ed; }
.pb-dropzone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
.pb-dropzone-empty { display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.pb-dropzone-empty .btn { pointer-events: auto; position: relative; z-index: 1; }
.pb-dropzone-icon { width: 40px; height: 40px; color: var(--muted); }
.pb-dropzone-icon svg { width: 40px; height: 40px; }
.pb-dropzone-file {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  pointer-events: none;
}
.pb-dropzone-file .btn,
.pb-dropzone-file label { pointer-events: auto; position: relative; z-index: 1; }
.pb-file-icon { font-size: 22px; }
.pb-file-meta { flex: 1; min-width: 0; }
.pb-file-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-file-meta span { color: var(--muted); font-size: 13px; }

.pb-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;
}
