/* Purchase Bills — list & detail */

.content:has(.pb-list),
.content:has(.pb-show) {
  padding: 24px;
  background: #f6f7f9;
}

.pb-list,
.pb-show {
  max-width: 1440px;
  margin: 0 auto;
  min-width: 0;
  container-type: inline-size;
  container-name: pb-page;
}

/* ——— List header ——— */
.pb-list-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.pb-list-head h1 {
  margin: 0;
  font-size: clamp(26px, 2.4vw, 32px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.pb-list-head p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
  max-width: 520px;
}

.pb-list-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  white-space: nowrap;
}

.pb-list-cta svg {
  width: 18px;
  height: 18px;
}

/* ——— KPI cards ——— */
.pb-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.pb-kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(11, 15, 25, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.pb-kpi-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.pb-kpi-value {
  font-size: clamp(20px, 2vw, 26px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.15;
  min-width: 0;
  overflow-wrap: anywhere;
}

.pb-kpi-meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ——— Toolbar ——— */
.pb-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 18px;
  margin-bottom: 16px;
  border-radius: 14px;
}

.pb-toolbar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pb-search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  min-height: 44px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 420px;
}

.pb-search-wrap svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex: none;
}

.pb-search-wrap input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 10px 0;
  font-size: 14px;
  outline: none;
}

.pb-toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.pb-filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}

.pb-filter-field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.pb-filter-field input,
.pb-select-wrap select {
  min-height: 44px;
  padding: 0 12px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.pb-select-wrap {
  position: relative;
}

.pb-select-wrap::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-top-color: var(--muted);
  pointer-events: none;
}

.pb-select-wrap select {
  width: 100%;
  padding-right: 32px;
  appearance: none;
  cursor: pointer;
}

.pb-toolbar-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

/* ——— Empty state ——— */
.pb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 56px 24px;
  border-radius: 14px;
}

.pb-empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 16px;
}

.pb-empty-icon svg {
  width: 32px;
  height: 32px;
}

.pb-empty h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
}

.pb-empty p {
  margin: 0 0 20px;
  max-width: 420px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

/* ——— Table ——— */
.pb-table-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(11, 15, 25, 0.04);
  min-width: 0;
  overflow: hidden;
}

.pb-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.pb-table {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
}

table.pb-table th,
table.pb-table td {
  padding: 14px 14px;
  vertical-align: middle;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}

table.pb-table thead th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-muted);
  white-space: nowrap;
}

table.pb-table tbody tr {
  transition: background 0.15s ease;
}

table.pb-table tbody tr:hover {
  background: var(--surface-hover);
}

table.pb-table tbody tr:last-child td {
  border-bottom: 0;
}

table.pb-table th.num,
table.pb-table td.num {
  text-align: right;
  white-space: nowrap;
}

table.pb-table .status-col {
  width: 100px;
}

table.pb-table .actions-col {
  width: 72px;
}

.pb-bill-link {
  font-weight: 700;
  color: var(--text);
}

.pb-bill-link:hover {
  color: var(--primary);
}

.pb-supplier-name {
  font-weight: 600;
}

.pb-col-items {
  max-width: 180px;
}

.pb-item-count {
  display: block;
  font-weight: 600;
  font-size: 13px;
}

.pb-item-preview {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pb-item-more {
  color: var(--muted);
}

.pb-col-total {
  font-weight: 700;
}

.pb-muted {
  color: var(--muted);
}

.pb-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.pb-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-soft);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pb-icon-btn:hover {
  background: var(--primary-soft);
  border-color: rgba(255, 107, 0, 0.25);
  color: var(--primary);
}

.pb-icon-btn svg {
  width: 18px;
  height: 18px;
}

.pb-no-results {
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ——— Mobile list cards ——— */
.pb-mobile-list {
  display: none;
  gap: 12px;
}

.pb-mobile-card {
  padding: 16px;
  border-radius: 14px;
}

.pb-mobile-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.pb-mobile-num {
  font-weight: 800;
  font-size: 16px;
  color: var(--text);
}

.pb-mobile-num:hover {
  color: var(--primary);
}

.pb-mobile-supplier {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.pb-mobile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.pb-mobile-meta strong {
  margin-left: auto;
  font-size: 16px;
  color: var(--text);
}

.pb-mobile-amounts {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.pb-mobile-actions {
  display: flex;
  gap: 8px;
}

/* ——— Detail page ——— */
.pb-show-breadcrumb {
  margin-bottom: 16px;
}

.pb-back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
}

.pb-back-link svg {
  width: 18px;
  height: 18px;
}

.pb-back-link:hover {
  color: var(--primary);
}

.pb-show-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.pb-show-eyebrow {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}

.pb-show-head h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 2.8vw, 36px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.pb-show-badge {
  font-size: 12px;
}

.pb-show-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 340px);
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.pb-show-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 1px 3px rgba(11, 15, 25, 0.04);
  margin-bottom: 16px;
}

.pb-show-card:last-child {
  margin-bottom: 0;
}

.pb-show-card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.pb-show-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.pb-show-card-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.pb-show-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px 24px;
}

.pb-show-meta-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.pb-show-meta strong {
  font-size: 15px;
  font-weight: 700;
}

.pb-show-meta-total .pb-show-total-amt {
  font-size: 22px;
  color: var(--primary);
}

.pb-show-table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

table.pb-show-items-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

table.pb-show-items-table th,
table.pb-show-items-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}

table.pb-show-items-table thead th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-muted);
}

table.pb-show-items-table th.num,
table.pb-show-items-table td.num {
  text-align: right;
}

.pb-item-name {
  font-weight: 600;
}

.pb-tax-rate {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.pb-tax-amt {
  display: block;
  font-size: 13px;
}

.pb-show-mobile-items {
  display: none;
  gap: 10px;
}

.pb-show-mobile-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
}

.pb-show-mobile-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.pb-item-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.pb-show-mobile-item-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 0;
}

.pb-show-mobile-item-grid div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pb-show-mobile-item-grid dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.pb-show-mobile-item-grid dd {
  margin: 0;
  font-size: 14px;
}

.pb-show-tax-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.pb-show-tax-lines,
.pb-show-totals,
.pb-show-pay-summary,
.pb-show-supplier-lines {
  margin: 0;
}

.pb-show-tax-lines div,
.pb-show-totals div,
.pb-show-pay-summary div,
.pb-show-supplier-lines div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}

.pb-show-tax-lines dt,
.pb-show-totals dt,
.pb-show-pay-summary dt,
.pb-show-supplier-lines dt {
  color: var(--muted);
  font-weight: 600;
}

.pb-show-tax-lines dd,
.pb-show-totals dd,
.pb-show-pay-summary dd,
.pb-show-supplier-lines dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.pb-show-grand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  margin: 12px 0;
  background: var(--primary-soft);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
}

.pb-show-grand strong {
  font-size: 20px;
  color: var(--primary);
}

.pb-show-aside {
  position: sticky;
  top: 84px;
}

.pb-show-totals-pay {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.pb-supplier-title {
  display: block;
  font-size: 16px;
  margin-bottom: 12px;
}

.pb-show-notes {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-soft);
}

.pb-show-empty-inline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ——— Responsive ——— */
@media (max-width: 1100px) {
  .pb-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pb-show-workspace {
    grid-template-columns: 1fr;
  }

  .pb-show-aside {
    position: static;
  }
}

@container pb-page (max-width: 900px) {
  .pb-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pb-show-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .pb-show-aside {
    position: static;
  }
}

@media (max-width: 768px) {
  .content:has(.pb-list),
  .content:has(.pb-show) {
    padding: 16px 14px;
  }

  .pb-kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .pb-kpi-card {
    padding: 14px;
  }

  .pb-toolbar {
    padding: 14px;
  }

  .pb-toolbar-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .pb-filter-field {
    min-width: 0;
    width: 100%;
  }

  .pb-table-card.desktop-only {
    display: none;
  }

  .pb-mobile-list {
    display: flex;
    flex-direction: column;
  }

  .pb-show-table-wrap.desktop-only {
    display: none;
  }

  .pb-show-mobile-items {
    display: flex;
    flex-direction: column;
  }

  .pb-list-head,
  .pb-show-head {
    flex-direction: column;
  }

  .pb-list-cta,
  .pb-show-head-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .pb-kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* ——— Dark theme ——— */
html[data-theme="dark"] .content:has(.pb-list),
html[data-theme="dark"] .content:has(.pb-show) {
  background: #0f1420;
}

html[data-theme="dark"] .pb-show-tax-lines div,
html[data-theme="dark"] .pb-show-totals div,
html[data-theme="dark"] .pb-show-pay-summary div,
html[data-theme="dark"] .pb-show-supplier-lines div {
  border-bottom-color: #273049;
}

html[data-theme="dark"] .pb-show-mobile-item {
  background: #151c2e;
}

.pb-has-doc { color: var(--primary, #ff6a00); }
.pb-doc-link {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary, #ff6a00);
  white-space: nowrap;
}
.pb-orig { display: grid; gap: 14px; }
.pb-orig-file, .pb-orig-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pb-inline-form { display: inline; margin: 0; }
.pb-orig-upload { display: grid; gap: 10px; justify-items: start; }
.pb-dropzone-compact { padding: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pb-dropzone-compact .pb-dropzone-input { width: 0.1px; height: 0.1px; }
.pb-viewer {
  border: 0;
  border-radius: 16px;
  width: min(960px, calc(100vw - 24px));
  max-width: 960px;
  height: min(86vh, 820px);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}
.pb-viewer::backdrop { background: rgba(15, 23, 42, 0.5); }
.pb-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line, #e5e7eb);
}
.pb-viewer-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-viewer-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.pb-viewer-body { height: calc(100% - 52px); overflow: auto; background: #111827; }
.pb-viewer-body iframe, .pb-viewer-body img { display: block; width: 100%; min-height: 100%; border: 0; }
.pb-viewer-body img { width: auto; max-width: 100%; margin: 0 auto; transform-origin: top center; }
