:root {
  --ink: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --bg: #f8fafc;
  --card: #ffffff;
  --primary: #3b82f6;
  --primary-ghost: rgba(59, 130, 246, 0.14);
}

* { box-sizing: border-box; }
/* Inherit global layout/background; only page-specific tweaks below */

body.fd-app.inventory-page {
  --ink: var(--fd-text);
  --muted: var(--fd-muted);
  --border: rgba(71, 85, 105, 0.45);
  --bg: transparent;
  --card: transparent;
}

h1, h2, h3 { margin: 0; }
.eyebrow { letter-spacing: 0.05em; text-transform: uppercase; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.subtitle { margin: 6px 0 0; color: var(--muted); }
.muted { color: var(--muted); }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  border-radius: 12px;
  padding: 14px 16px;
}
.header-actions { display: flex; gap: 8px; }

.card {
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
@media (max-width: 640px) {
  .filters {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
}
.field input,
.field select,
.field textarea {
  width: 100%;
}
.field textarea { resize: vertical; }

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { margin-top: 2px; font-size: 12px; line-height: 1.2; }
td.low-stock.warning { background: #fff4e5; }
td.low-stock.danger { background: #fee2e2; }
.stock-alert {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.stock-alert.warning { background: #fff4e5; color: #9a6700; }
.stock-alert.danger { background: #fee2e2; color: #b91c1c; }

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge.success { background: #e6f7ee; color: #18794e; }
.badge.warning { background: #fff4e5; color: #9a6700; }
.badge.muted { background: #f1f5f9; color: var(--muted); }

/* AI intake */
#intakeCard .table-head { gap: 12px; flex-wrap: wrap; }
.intake-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.intake-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-top: 8px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
}
.status-pill.success { background: rgba(16, 185, 129, 0.14); color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.status-pill.warning { background: rgba(245, 158, 11, 0.14); color: #f59e0b; border-color: rgba(245, 158, 11, 0.3); }
.status-pill.muted { background: transparent; color: var(--muted); }
.intake-results { margin-top: 12px; }
.intake-list { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: transparent; display: grid; gap: 8px; }
.intake-list.empty { color: var(--muted); font-style: italic; }
.intake-item { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: transparent; }
.intake-item strong { font-weight: 700; }
.intake-item small { color: var(--muted); }
.intake-actions-bottom { margin-top: 10px; display: flex; justify-content: flex-end; }

.drawer {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr;
  z-index: 50;
}
.drawer.hidden { display: none; }
.drawer__backdrop {
  grid-row: 1 / 1;
  grid-column: 1 / 1;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1;
}
.drawer__panel {
  grid-row: 1 / 1;
  grid-column: 1 / 1;
  margin-left: auto;
  width: min(980px, 100%);
  height: 100%;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
  overflow-y: auto;
}
@media (max-width: 768px) {
  .drawer__panel {
    width: 100%;
    box-shadow: -4px 0 15px rgba(0,0,0,0.3);
  }
}
@media (max-width: 480px) {
  .drawer__panel {
    width: 100vw;
  }
}
.drawer__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  transform: none;
  margin: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10050;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  width: 100%;
  height: 100%;
}
.modal__panel {
  position: relative;
  margin: 0;
  width: min(900px, 96%);
  max-height: 92vh;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
@media (max-width: 640px) {
  .modal__panel {
    width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
  }
}

/* Invoice history modal: force true centering even if other global modal styles exist */
#invoiceModal {
  position: fixed;
  inset: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10060;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none;
  height: 100%;
  transform: none;
  margin: 0;
  padding: 16px;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}
#invoiceModal.hidden { display: none; }
#invoiceModal .modal__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#invoiceModal .modal__panel {
  position: relative;
  margin: 0;
}
.modal__panel .form-grid,
.modal__panel .detail-grid {
  max-height: calc(92vh - 120px);
  overflow-y: auto;
}
.modal__header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.detail-grid {
  padding: 16px 18px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 12px;
  overflow-y: auto;
  max-height: 70vh;
}
.detail-inline {
  display: block;
}
.detail-inline.hidden {
  display: none;
}
.detail-row {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.detail-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-value {
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
}
.form-grid {
  padding: 16px 20px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  overflow-y: auto;
}
.span-2 { grid-column: span 2; }
@media (max-width: 720px) { .span-2 { grid-column: span 1; } }

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.form-actions .meta { color: var(--muted); font-weight: 600; }
.form-actions .buttons { display: flex; gap: 8px; }

@media (max-width: 900px) {
  .intake-grid { grid-template-columns: 1fr; }
}

/* Invoice maker */
#invoiceCard .table-head { gap: 12px; flex-wrap: wrap; }
.invoice-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.invoice-grid {
  display: grid;
  gap: 12px;
  margin-top: 10px;
  align-items: end;
}
.invoice-grid .field { min-width: 0; }
.invoice-grid .field > label {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#invoiceCard .invoice-grid-header {
  grid-template-columns: repeat(6, minmax(160px, 1fr));
}

#invoiceCard .invoice-grid-line {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  align-items: start;
}

#invoiceCard .invoice-grid-line .invoice-field-hint {
  grid-column: 1 / -1;
  margin-top: -4px;
  min-height: 18px;
}

#invoiceCard .invoice-grid-line .invoice-field-hint:empty {
  display: none;
  margin: 0;
  min-height: 0;
}

#invoiceCard .invoice-grid-line .invoice-field-action {
  grid-column: 1 / -1;
}

#invoiceCard .invoice-grid-line .inv-action-label {
  visibility: hidden;
}

#invoiceCard #invAddItem {
  width: 100%;
  min-height: 44px;
}

.invoice-details { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.invoice-details textarea { min-height: 150px; }
.inv-hint { font-size: 12px; margin-top: 6px; line-height: 1.3; }
.logo-upload {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.logo-preview {
  width: 100%;
  max-width: 100%;
  height: 56px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
}
.logo-preview.hidden { display: none; }

#invoiceCard #invLogoBtn {
  width: 100%;
  min-height: 44px;
}

.invoice-table {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}
.invoice-table table { margin: 0; }
.invoice-table td { vertical-align: middle; }
.invoice-table tr.inv-stock-warn td { background: #fff5f5; }
.invoice-table tr.inv-stock-warn .inv-total { color: #b91c1c; }
.invoice-table input {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  width: 110px;
}
.invoice-table .inv-qty { width: 90px; }
.invoice-table .inv-unit { white-space: nowrap; }
.invoice-table .inv-subtotal { white-space: nowrap; font-weight: 600; }
.invoice-table .inv-total { white-space: nowrap; font-weight: 700; }
.invoice-table .inv-empty td { text-align: center; padding: 16px 10px; }

.btn.sm { padding: 8px 10px; font-size: 12px; border-radius: 10px; }

.invoice-summary {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}
.invoice-summary strong { font-weight: 800; }
.inv-qr {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 160px;
}
.inv-qr.is-visible { display: flex; }
.inv-qr__label { font-size: 12px; font-weight: 700; color: var(--ink); }
.inv-qr__img { width: 120px; height: 120px; object-fit: contain; }
.inv-qr__hint { font-size: 11px; color: var(--muted); }

.invoice-preview {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.invoice-preview__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--fd-table-th-bg);
}
.invoice-preview__head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  color: var(--ink);
}
.invoice-preview__head p { margin: 4px 0 0; font-size: 12px; }
.invoice-preview__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.invoice-preview iframe { width: 100%; height: 860px; border: 0; background: #fff; }
.invoice-preview.is-collapsed iframe { display: none; }
@media (max-width: 900px) { .invoice-preview iframe { height: 720px; } }

@media (max-width: 1500px) {
  #invoiceCard .invoice-grid-header {
    grid-template-columns: repeat(3, minmax(200px, 1fr));
  }
  #invoiceCard .invoice-grid-line {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 980px) {
  #invoiceCard .invoice-grid-header,
  #invoiceCard .invoice-grid-line {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 640px) {
  #invoiceCard .invoice-grid-header,
  #invoiceCard .invoice-grid-line,
  #invoiceCard .invoice-details {
    grid-template-columns: 1fr;
  }
}

.inv-modal-body {
  padding: 14px 18px 18px;
  overflow-y: auto;
  max-height: calc(92vh - 120px);
}
.inv-modal-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.inv-modal-controls .field { min-width: 260px; flex: 1; }
.inv-modal-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.inv-modal-title { margin: 16px 0 8px; font-size: 13px; color: var(--ink); }
.inv-history-table {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}
.inv-history-table table { margin: 0; }
.inv-history-table th.num,
.inv-history-table td.num { text-align: right; white-space: nowrap; }
.inv-history-table td { vertical-align: middle; }
.inv-history-table td .btn + .btn { margin-left: 6px; }
.inv-history-table .inv-empty td { text-align: center; padding: 16px 10px; }

@media (max-width: 600px) {
  .invoice-table,
  .inv-history-table {
    max-height: min(520px, 55vh);
  }
}
