/* =========================================================
   HELD UK LTD — App Stylesheet
   Palette: Black nav, white cards, green primary, grey secondary
   ========================================================= */
:root {
  --black:    #0d0d0d;
  --white:    #ffffff;
  --bg:       #f4f5f7;        /* page background */
  --bg-card:  #ffffff;
  --text:     #1a1a1a;
  --muted:    #6b7280;
  --muted2:   #afafaf;
  --line:     #e2e4e9;
  --primary:  #000000;        /* HELD green */
  --primary-h:#444444;        /* hover */
  --primary-light: #444444;
  --danger:   #dc2626;
  --grey:     #6b7280;
  --grey-bg:  #727272;
  --grey-h:   #e5e7eb;
  --focus:    rgba(0,128,96,.3);
  --radius:   8px;
  --radius-lg:12px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:0 10px 24px rgba(0,0,0,.14);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bs-btn-disabled-bg: #444444 !important;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, video, canvas { max-width: 100%; height: auto; }

/* =========================================================
   SHELL HEADER — black bar
   ========================================================= */
.shell-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--white);
  border-bottom: 1px solid #2a2a2a;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.shell-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  min-width: 0;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.brand__text { font-weight: 700; color: var(--white); letter-spacing: .3px; font-size: 15px; }

/* Nav links */
.shell-nav { display: flex; gap: 2px; margin-left: 12px; min-width: 0; }
.nav-link {
  padding: 6px 12px;
  border-radius: 6px;
  color: #444;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: .1px;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--black); background: rgba(255,255,255,.1); text-decoration: none; }
.nav-link.is-active { color: var(--white); background: var(--primary); }

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: var(--white);
  cursor: pointer;
}
.menu-toggle__bar {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 2px;
  margin-left: -9px;
  margin-top: -1px;
  border-radius: 999px;
  background: currentColor;
  transition: transform .16s, opacity .16s;
}
.menu-toggle__bar:nth-child(1) { transform: translateY(-6px); }
.menu-toggle__bar:nth-child(3) { transform: translateY(6px); }

/* Shell actions (logout btn) */
.shell-actions { margin-left: auto; }

/* =========================================================
   PAGE CONTAINER
   ========================================================= */
.page {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
}
main.page { flex: 1 0 auto; }

/* =========================================================
   FOOTER
   ========================================================= */
.shell-footer {
  background: var(--black);
  border-top: 1px solid #2a2a2a;
  color: #9ca3af;
  margin-top: auto;
  flex-shrink: 0;
}
.shell-footer__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 18px; }
.card-body.p-0 { padding: 0; }

/* Legacy card helpers */
.card__header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.card__title  { font-size: 15px; font-weight: 600; margin: 0; }
.card__actions { display: flex; gap: 8px; }
.card .form-row { display: flex; gap: 12px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--text);
}
.page-subtitle {
  color: var(--muted);
  margin: 0;
  max-width: 760px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.status-badge.good {
  background: #e6f4f0;
  color: #006b52;
}
.status-badge.warn {
  background: #fff7e6;
  color: #8a5a00;
}
.status-badge.bad {
  background: #fee2e2;
  color: #991b1b;
}

.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.feed-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.feed-details {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}
.feed-details div {
  display: grid;
  gap: 3px;
}
.feed-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.feed-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* =========================================================
   FORM CONTROLS
   ========================================================= */
.label, .form-label {
  display: block;
  font-weight: 500;
  font-size: 12.5px;
  color: #374151;
  margin-bottom: 5px;
  letter-spacing: .02em;
}
.input, .select, .textarea,
.form-control, .form-select {
  display: block;
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--white);
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.input:focus, .select:focus, .textarea:focus,
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}
.form-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }

.field { min-width: 0; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.4;
  transition: background .14s, border-color .14s, box-shadow .14s, transform .08s, filter .14s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

/* Primary — green */
.btn-primary, .btn-success {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled):not([disabled]) {
  background: var(--primary-h);
  border-color: var(--primary-h);
  box-shadow: 0 4px 10px rgba(0,128,96,.28);
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

/* Secondary / outline */
.btn-outline, .btn-outline-secondary, .btn-secondary {
  background: var(--white);
  color: #374151;
  border-color: #d1d5db;
}
.btn-outline:hover:not(:disabled):not([disabled]),
.btn-outline-secondary:hover:not(:disabled):not([disabled]),
.btn-secondary:hover:not(:disabled):not([disabled]) {
  background: var(--grey-bg);
  border-color: #9ca3af;
  text-decoration: none;
}

/* Danger */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }

/* Warning */
.btn-warning {
  background: #d97706;
  color: #fff;
  border-color: #d97706;
}
.btn-warning:hover:not(:disabled) { filter: brightness(.92); }

/* Sizes */
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* =========================================================
   TABLES
   ========================================================= */
.table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table, .data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

.table thead th, .data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafb;
  color: #374151;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .45px;
  padding: 11px 14px;
  border-bottom: 2px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.table tbody td, .data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--text);
}

.table tbody tr:last-child td,
.data-table tbody tr:last-child td { border-bottom: none; }

.table tbody tr:hover,
.data-table tbody tr:hover { background: #f6fdf9; }

.table tfoot td, .table tfoot th {
  padding: 11px 14px;
  border-top: 2px solid var(--line);
  font-weight: 600;
  background: #f9fafb;
}

/* Alignment helpers */
.text-end, .t-right, .ta-right { text-align: right !important; }
.text-muted { color: var(--muted) !important; }
.fw-semibold, .fw-bold { font-weight: 600; }
.small { font-size: 12px; }

/* Numeric columns */
.table .ta-right, .table .text-end { font-variant-numeric: tabular-nums; }

.backorders-actions {
  align-items: flex-end !important;
  gap: 12px !important;
  padding: 0 !important;
  border-bottom: 0 !important;
}
.backorders-search {
  flex: 1 1 420px;
  min-width: 0;
  position: relative;
}
.backorders-meta {
  flex: 1 1 180px;
  min-width: 0;
  margin-left: auto;
  text-align: right;
  overflow-wrap: anywhere;
}
.backorders-results {
  width: 100%;
  max-width: 100%;
}

/* =========================================================
   BADGES
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge--ok, .bg-success { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.badge--warn, .bg-warning { background: #fef9c3; border-color: #fde68a; color: #854d0e; }
.badge--muted  { background: var(--grey-bg); border-color: var(--line); color: var(--muted); }
.badge--danger { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.badge.bg-light { background: var(--grey-bg); color: var(--text); }
.badge.text-dark { color: var(--text); }

/* =========================================================
   TYPEAHEAD / DROPDOWN
   ========================================================= */
.position-relative { position: relative; }

.typeahead-list, .dropdown {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  z-index: 300;
  background: var(--white);
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  display: none;
}
.typeahead-list.visible,
.typeahead-list[style*="block"],
.typeahead-list[style*="display: block"] { display: block !important; }

.typeahead-item, .dropdown__item {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
  border-bottom: 1px solid #f3f4f6;
  line-height: 1.4;
  transition: background .1s;
}
.typeahead-item:last-child, .dropdown__item:last-child { border-bottom: none; }
.typeahead-item:hover, .dropdown__item:hover,
.typeahead-item:focus, .dropdown__item:focus {
  background: var(--primary-light);
  outline: none;
}

/* =========================================================
   SUMMARY / STAT CARDS (used on statements)
   ========================================================= */
.stat-card { text-align: center; }
.stat-card .stat-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.stat-card .stat-value { font-size: 20px; font-weight: 700; color: var(--text); }

/* =========================================================
   LOADING / EMPTY STATES
   ========================================================= */
#empty, .empty-state {
  padding: 64px 20px;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  background: var(--white);
  border-radius: var(--radius-lg);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-weight: 600;
  letter-spacing: .5px;
}

/* =========================================================
   UTILITY CLASSES (Bootstrap shims for non-Bootstrap pages)
   ========================================================= */
.d-flex { display: flex !important; }
.d-none { display: none !important; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.ms-auto { margin-left: auto; }
.w-100 { width: 100% !important; }
.p-3 { padding: 16px; }
.p-0 { padding: 0 !important; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.hidden { display: none !important; }

/* =========================================================
   RESPONSIVE SHELL
   ========================================================= */
@media (max-width: 980px) {
  .shell-header__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    height: auto;
    min-height: 56px;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 16px;
  }

  .brand img { display: block; max-width: 112px; }

  .menu-toggle {
    display: inline-flex;
    position: relative;
    justify-self: end;
  }

  .shell-nav {
    grid-column: 1 / -1;
    display: none;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin-left: 0;
    overflow: visible;
    padding: 8px 0 0;
    border-top: 1px solid rgba(255,255,255,.12);
  }

  .nav-open .shell-nav {
    display: flex;
  }

  .nav-link {
    flex: none;
    width: 100%;
    padding: 11px 12px;
    font-size: 14px;
  }

  .shell-actions {
    grid-column: 1 / -1;
    display: none;
    width: 100%;
    margin-left: 0;
  }

  .nav-open .shell-actions {
    display: block;
  }

  .shell-actions .btn {
    width: 100%;
    min-height: 42px;
  }
}

@media (max-width: 640px) {
  html { font-size: 13px; }

  .page {
    padding: 16px 12px;
  }

  .page .row {
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .page .row > * {
    padding-left: 0;
    padding-right: 0;
  }

  .input, .select, .textarea,
  .form-control, .form-select {
    font-size: 16px;
  }

  .shell-header__inner {
    padding: 8px 12px;
  }

  .shell-footer__inner {
    padding: 12px;
    justify-content: center;
    text-align: center;
  }

  .card,
  .card.border-warning {
    border-radius: var(--radius);
  }

  .card-body,
  .card__body {
    padding: 14px;
  }

  .card-header,
  .card__header {
    gap: 10px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  h1, .page__title { font-size: 22px; }
  h2 { font-size: 19px; }
  h3 { font-size: 18px; }

  .page .row .btn,
  .page .form-row .btn {
    width: 100%;
  }

  .page .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 10px;
  }

  .page .d-flex.justify-content-between > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card .form-row {
    padding: 12px;
  }

  .card .form-row > * {
    flex: 1 1 100%;
    min-width: 0 !important;
  }

  .typeahead-list,
  .dropdown {
    max-height: min(300px, 58vh);
    width: 100%;
    max-width: 100%;
  }

  .backorders-meta {
    margin-left: 0;
    text-align: left;
  }

  .table-wrap,
  .table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: visible;
  }

  .table,
  .data-table {
    display: block;
    width: 100% !important;
    min-width: 0;
    max-width: 100%;
    border-collapse: separate;
  }

  .table thead,
  .data-table thead {
    display: none;
  }

  .table tbody,
  .table tfoot,
  .data-table tbody,
  .data-table tfoot {
    display: block;
    width: 100%;
  }

  .table tbody tr,
  .table tfoot tr,
  .data-table tbody tr,
  .data-table tfoot tr {
    display: block;
    width: 100%;
    margin: 0 0 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
  }

  .table tbody tr:last-child,
  .table tfoot tr:last-child,
  .data-table tbody tr:last-child,
  .data-table tfoot tr:last-child {
    margin-bottom: 0;
  }

  .table tbody td,
  .table tbody th,
  .table tfoot td,
  .table tfoot th,
  .data-table tbody td,
  .data-table tbody th,
  .data-table tfoot td,
  .data-table tfoot th {
    display: grid;
    grid-template-columns: minmax(88px, 38%) minmax(0, 1fr);
    gap: 10px;
    width: 100%;
    padding: 7px 0;
    border: 0;
    text-align: right !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .table tbody td::before,
  .table tbody th::before,
  .table tfoot td::before,
  .table tfoot th::before,
  .data-table tbody td::before,
  .data-table tbody th::before,
  .data-table tfoot td::before,
  .data-table tfoot th::before {
    content: attr(data-label);
    min-width: 0;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .table tbody td[data-label=""],
  .table tbody th[data-label=""],
  .table tfoot td[data-label=""],
  .table tfoot th[data-label=""],
  .data-table tbody td[data-label=""],
  .data-table tbody th[data-label=""],
  .data-table tfoot td[data-label=""],
  .data-table tfoot th[data-label=""] {
    display: flex;
    justify-content: flex-start;
    text-align: left !important;
  }

  .table tbody td[data-label=""]::before,
  .table tbody th[data-label=""]::before,
  .table tfoot td[data-label=""]::before,
  .table tfoot th[data-label=""]::before,
  .data-table tbody td[data-label=""]::before,
  .data-table tbody th[data-label=""]::before,
  .data-table tfoot td[data-label=""]::before,
  .data-table tfoot th[data-label=""]::before {
    content: none;
  }

  .table tbody td[data-full-row="true"],
  .table tbody th[data-full-row="true"],
  .table tfoot td[data-full-row="true"],
  .table tfoot th[data-full-row="true"],
  .data-table tbody td[data-full-row="true"],
  .data-table tbody th[data-full-row="true"],
  .data-table tfoot td[data-full-row="true"],
  .data-table tfoot th[data-full-row="true"] {
    display: block;
    text-align: left !important;
  }

  .table tbody td[data-full-row="true"]::before,
  .table tbody th[data-full-row="true"]::before,
  .table tfoot td[data-full-row="true"]::before,
  .table tfoot th[data-full-row="true"]::before,
  .data-table tbody td[data-full-row="true"]::before,
  .data-table tbody th[data-full-row="true"]::before,
  .data-table tfoot td[data-full-row="true"]::before,
  .data-table tfoot th[data-full-row="true"]::before {
    content: none;
  }

  .table .form-control,
  .table .form-select,
  .data-table .form-control,
  .data-table .form-select {
    min-width: 0;
  }

  #summary-cards .d-flex {
    flex-wrap: wrap;
  }

  #invDraftModal > div {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  #draftHeader {
    grid-template-columns: 1fr !important;
  }

  #draftLinesTable {
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .nav-link {
    font-size: 12.5px;
    padding: 7px 9px;
  }

  .btn {
    min-height: 42px;
    padding-left: 14px;
    padding-right: 14px;
  }
}
