:root {
  --ink: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --bg: #f8fafc;
  --card: #ffffff;
  --primary: #0b6efd;
  --primary-ghost: #e8f2ff;
}

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

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); }

.top-nav {
  background: linear-gradient(90deg, #0b6efd, #0c65e6);
  padding: 10px 16px;
  border-radius: 12px;
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 6px 16px rgba(11, 110, 253, 0.25);
}
.top-nav__links {
  display: flex;
  gap: 12px;
  align-items: center;
}
.nav-link {
  color: #e8f2ff;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,0.18); color: #fff; }
.nav-link.active {
  background: #fff;
  color: #0b6efd;
  border-color: rgba(255,255,255,0.5);
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.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%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  color: var(--ink);
}
.field textarea { resize: vertical; }

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: var(--ink);
}
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn.success {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}
.btn.ghost {
  background: var(--primary-ghost);
  color: var(--primary);
  border-color: transparent;
}
.btn.danger {
  background: #e02424;
  color: #fff;
  border-color: #e02424;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.table-container { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  text-align: left;
  padding: 10px 8px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 10px 8px;
  border-bottom: 1px solid #edf2f7;
  font-size: 14px;
}
tbody tr:hover { background: #f5f7fb; }
.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: #fff;
  color: var(--muted);
}
.status-pill.success { background: #e6f7ee; color: #18794e; border-color: #b8e4c7; }
.status-pill.warning { background: #fff4e5; color: #9a6700; border-color: #f3d2a2; }
.status-pill.muted { background: #f8fafc; color: var(--muted); }
.intake-results { margin-top: 12px; }
.intake-list { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: #fff; 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 #e5e7eb; border-radius: 8px; background: #f9fbff; }
.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);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  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;
  background: #fff;
  box-shadow: -12px 0 30px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
  overflow-y: auto;
}
.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);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  width: 100%;
  height: 100%;
}
.modal__panel {
  position: relative;
  margin: 0;
  width: min(900px, 96%);
  max-height: 92vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 15px 45px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 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: #f8fafc;
  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;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.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 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-preview {
  width: 160px;
  height: 56px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px;
}
.logo-preview.hidden { display: none; }

.invoice-table {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  background: #fff;
}
.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;
  background: #fff;
  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;
  background: #fff;
}
.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: #f8fafc;
}
.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; } }

.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;
  background: #fff;
}
.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; }
