:root {
  --tm-bg: #f4f6fb;
  --tm-surface: #ffffff;
  --tm-surface-soft: #f8fafc;
  --tm-border: rgba(15, 23, 42, 0.08);
  --tm-border-strong: rgba(15, 23, 42, 0.16);
  --tm-text: #0f172a;
  --tm-text-muted: #64748b;
  --tm-accent: #0f62fe;
  --tm-accent-soft: rgba(15, 98, 254, 0.10);
  --tm-danger: #b42318;
  --tm-danger-soft: rgba(180, 35, 24, 0.08);
  --tm-radius-sm: 0.8rem;
  --tm-radius: 1rem;
  --tm-radius-lg: 1.25rem;
  --tm-shadow-soft: 0 0.75rem 2rem rgba(15, 23, 42, 0.06);
  --tm-shadow-focus: 0 0 0 0.2rem rgba(15, 98, 254, 0.18);
  --tm-space-1: 0.25rem;
  --tm-space-2: 0.5rem;
  --tm-space-3: 0.75rem;
  --tm-space-4: 1rem;
  --tm-space-5: 1.5rem;
  --tm-space-6: 2rem;
}

body.tm-body {
  background:
    radial-gradient(circle at top, rgba(15, 98, 254, 0.06), transparent 30%),
    linear-gradient(180deg, #f8fafc 0%, var(--tm-bg) 100%);
  color: var(--tm-text);
}

.tm-main {
  min-height: calc(100vh - 5rem);
}

.card,
.tm-card,
.tm-table-shell,
.tm-toolbar {
  border: 1px solid var(--tm-border);
  border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow-soft);
}

.card,
.tm-card,
.tm-table-shell {
  background: var(--tm-surface);
}

.card.shadow-sm,
.tm-card.shadow-sm {
  box-shadow: var(--tm-shadow-soft) !important;
}

.tm-card-body {
  padding: 1.25rem;
}

.tm-page-header {
  align-items: flex-start;
  display: flex;
  gap: var(--tm-space-4);
  justify-content: space-between;
  margin-bottom: var(--tm-space-5);
}

.tm-page-header__body {
  min-width: 0;
}

.tm-page-header__actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: var(--tm-space-2);
  justify-content: flex-end;
}

.tm-page-header__eyebrow,
.account-eyebrow {
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
}

.tm-page-title {
  font-size: clamp(1.45rem, 1.2rem + 1vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
}

.tm-page-subtitle {
  color: var(--tm-text-muted);
  margin: 0.45rem 0 0;
  max-width: 68ch;
}

.tm-toolbar {
  align-items: center;
  background: var(--tm-surface);
  display: flex;
  flex-wrap: wrap;
  gap: var(--tm-space-3);
  justify-content: space-between;
  margin-bottom: var(--tm-space-3);
  padding: var(--tm-space-3) var(--tm-space-4);
}

.tm-toolbar--danger {
  background: linear-gradient(180deg, #fff7f7 0%, #fff 100%);
  border-color: rgba(180, 35, 24, 0.18);
}

.tm-toolbar__actions {
  align-items: center;
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: var(--tm-space-2);
}

.tm-toolbar__helper,
.tm-helper-text {
  color: var(--tm-text-muted);
  font-size: 0.875rem;
}

.tm-section-header,
.tm-card-header {
  align-items: flex-start;
  display: flex;
  gap: var(--tm-space-3);
  justify-content: space-between;
  margin-bottom: var(--tm-space-4);
}

.tm-section-header__actions,
.tm-card-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tm-space-2);
}

.tm-section-title,
.tm-card-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.tm-section-subtitle,
.tm-card-subtitle {
  color: var(--tm-text-muted);
  font-size: 0.92rem;
  margin: 0.3rem 0 0;
}

.tm-table-shell {
  overflow: hidden;
}

.tm-table-shell .table {
  margin-bottom: 0;
}

.tm-table-shell .table thead th {
  background: #f8fafc;
  border-bottom-color: var(--tm-border-strong);
  color: #334155;
  font-size: 0.87rem;
  font-weight: 700;
  vertical-align: middle;
}

.tm-table-shell .table-light th {
  background: #f1f5f9;
}

.tm-table-shell .table td,
.tm-table-shell .table th {
  padding: 0.9rem 0.8rem;
}

.tm-state {
  align-items: flex-start;
  background: var(--tm-surface-soft);
  border: 1px dashed var(--tm-border-strong);
  border-radius: var(--tm-radius-sm);
  display: flex;
  flex-direction: column;
  gap: var(--tm-space-2);
  padding: var(--tm-space-5);
  text-align: left;
}

.tm-state--loading {
  align-items: center;
  flex-direction: row;
}

.tm-state--error {
  background: #fff6f6;
  border-color: rgba(180, 35, 24, 0.25);
}

.tm-state__title {
  font-size: 1rem;
  font-weight: 700;
}

.tm-state__text {
  color: var(--tm-text-muted);
  margin: 0;
  max-width: 68ch;
}

.tm-danger-block {
  background: linear-gradient(180deg, #fff5f4 0%, #fff 100%);
  border: 1px solid rgba(180, 35, 24, 0.22);
  border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow-soft);
  padding: var(--tm-space-4);
}

.tm-danger-block__title {
  color: var(--tm-danger);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.tm-danger-block__text,
.tm-danger-block__hint {
  margin: 0;
}

.tm-danger-block__hint {
  color: var(--tm-text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.btn-primary {
  box-shadow: 0 0.4rem 1rem rgba(15, 98, 254, 0.16);
}

.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-danger {
  border-width: 1px;
}

.text-muted,
.form-text {
  color: var(--tm-text-muted) !important;
}

a {
  text-underline-offset: 0.12em;
}

a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.dropdown-item:focus-visible {
  box-shadow: var(--tm-shadow-focus);
  outline: none;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  border-color: rgba(15, 98, 254, 0.4);
  box-shadow: var(--tm-shadow-focus);
}

.help-content {
  min-width: 0;
}

.help-content img,
.help-content table {
  max-width: 100%;
}

.help-content table {
  display: block;
  overflow-x: auto;
}

.help-content code,
.font-monospace {
  font-size: 0.9em;
}



/* Depth banding for TreeTable rows */
.p-treetable .p-treetable-tbody > tr.depth-0 > td { background: #fafafa; }
.p-treetable .p-treetable-tbody > tr.depth-1 > td { background: #ffffff; }
.p-treetable .p-treetable-tbody > tr.depth-2 > td { background: #f2f8ff; }
.p-treetable .p-treetable-tbody > tr.depth-3 > td { background: #fff7e8; }
.p-treetable .p-treetable-tbody > tr.depth-4 > td { background: #f3fff3; }
.p-treetable .p-treetable-tbody > tr.depth-5 > td { background: #fff0f6; }
.p-treetable .p-treetable-tbody > tr.depth-6 > td { background: #f3f0ff; }
.p-treetable .p-treetable-tbody > tr.depth-7 > td { background: #eef7f7; }

/* subtle “branch” accent: coloured left stripe by depth */
.p-treetable .p-treetable-tbody > tr[class^="depth-"] > td:first-child {
  box-shadow: inset 4px 0 0 rgba(0,0,0,0.06);
}
.p-treetable .p-treetable-tbody > tr.depth-2 > td:first-child { box-shadow: inset 4px 0 0 #b3d9ff; }
.p-treetable .p-treetable-tbody > tr.depth-3 > td:first-child { box-shadow: inset 4px 0 0 #ffd38a; }
.p-treetable .p-treetable-tbody > tr.depth-4 > td:first-child { box-shadow: inset 4px 0 0 #a6e3a6; }
.p-treetable .p-treetable-tbody > tr.depth-5 > td:first-child { box-shadow: inset 4px 0 0 #ffb3cc; }
.p-treetable .p-treetable-tbody > tr.depth-6 > td:first-child { box-shadow: inset 4px 0 0 #c7b8ff; }


/* subtle colored bands by depth */
.tt-depth-0 { background: rgba(0, 0, 0, 0.00); }
.tt-depth-1 { background: rgba(0, 128, 255, 0.04); }
.tt-depth-2 { background: rgba(0, 200, 83, 0.05); }
.tt-depth-3 { background: rgba(255, 193, 7, 0.06); }
.tt-depth-4 { background: rgba(156, 39, 176, 0.06); }

/* keep PrimeReact gridlines but lighten them a touch */
.p-treetable .p-treetable-tbody > tr > td {
  border-color: rgba(0,0,0,.08);
}

/* leaf dot (for nodes without children) */
.tt-pncell {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.tt-leaf-dot {
  width: .4rem;
  height: .4rem;
  border-radius: 999px;
  background: rgba(0,0,0,.45);
  display: inline-block;
}


/* Make the tree a bit more compact */
.pd-tt.p-treetable {
  font-size: 0.92rem;
}

/* Prefer horizontal lines; mute verticals */
.pd-tt .p-treetable-thead > tr > th,
.pd-tt .p-treetable-tbody > tr > td {
  border-width: 0 0 1px 0;
  border-color: rgba(0,0,0,.08);
}

/* Slightly smaller cell padding */
.pd-tt .p-treetable-tbody > tr > td,
.pd-tt .p-treetable-thead > tr > th {
  padding: .35rem .5rem;
}

/* PN cell/link alignment */
.tt-pncell .tt-pnlink {
  display: inline-block;
  text-align: left;
  line-height: 1.1;
}

/* Level + thumbnail cell */
.tt-thumbcell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
}

.tt-level {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  opacity: .6;
  min-width: 12px;       /* keeps column from jittering when empty */
}

/* Preview image size */
.tt-thumb {
  max-height: 32px;
  max-width: 48px;
  object-fit: contain;
  display: block;
}

/* Tiny leaf dot (shown only in the level/preview column) */
.tt-leaf-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(0,0,0,.35);
  display: inline-block;
}

/* (keeps your depth-row striping/colors) */
.tt-depth-0 td { background-image: linear-gradient(to right, rgba(0,0,0,.02), rgba(0,0,0,0)); }
.tt-depth-1 td { background-image: linear-gradient(to right, rgba(0,0,0,.03), rgba(0,0,0,0)); }
.tt-depth-2 td { background-image: linear-gradient(to right, rgba(0,0,0,.04), rgba(0,0,0,0)); }
.tt-depth-3 td { background-image: linear-gradient(to right, rgba(0,0,0,.05), rgba(0,0,0,0)); }
.tt-depth-4 td { background-image: linear-gradient(to right, rgba(0,0,0,.06), rgba(0,0,0,0)); }



/* Smaller text and tight rows */
.pd-tt .p-treetable-tbody > tr > td {
  font-size: 0.92rem;
  vertical-align: middle;
}

/* Thumbnail (image-only column) */
.tt-thumb {
  max-height: 32px;
  max-width: 48px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* PN cell */
.tt-pncell .tt-pnlink {
  text-decoration: none;
}

/* Level guides column */
.tt-levelcell {
  --tt-indent: 16px;
  --tt-guide: rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  height: 100%;
  /* width set inline from TS (depth * indent) */
}

.tt-levelcell .tt-lvl {
  position: relative;
  width: var(--tt-indent);
  height: 28px; /* roughly matches small row size */
  flex: 0 0 var(--tt-indent);
}

/* vertical guide for ancestor levels */
.tt-levelcell .tt-lvl.keep::before {
  content: "";
  position: absolute;
  left: calc(50% - 0.5px);
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--tt-guide);
  opacity: 0.8;
}

/* current level cap: ├ or └ drawn with borders */
.tt-levelcell .tt-lvl.cap::after {
  content: "";
  position: absolute;
  left: calc(50% - 0.5px);
  right: 2px;             /* short of the next column */
  top: 50%;
  height: 1px;
  background: var(--tt-guide);
  opacity: 0.9;
}

/* vertical part of the cap */
.tt-levelcell .tt-lvl.cap::before {
  content: "";
  position: absolute;
  left: calc(50% - 0.5px);
  width: 1px;
  background: var(--tt-guide);
  opacity: 0.9;
}

/* ├ (has next sibling): full vertical through the row */
.tt-levelcell .tt-lvl.cap.mid::before {
  top: 0;
  bottom: 0;
}

/* └ (last sibling): from top to mid only */
.tt-levelcell .tt-lvl.cap.last::before {
  top: 0;
  bottom: 50%;
}


/* Expander column: lock width and remove any built-in indent */
.p-treetable .pd-tt td.tt-expander {
  width: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  overflow: visible;              /* avoid clipping on small columns */
}

/* PrimeReact adds left margin to the toggler for depth; kill it */
.p-treetable .pd-tt td.tt-expander .p-treetable-toggler {
  margin-left: 0 !important;
}

/* Make sure the toggler is visible and left-aligned */
.p-treetable .pd-tt td.tt-expander .p-treetable-toggler,
.p-treetable .pd-tt td.tt-expander .p-link {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
}

/* Optional: slightly smaller chevron to reduce visual jitter */
.p-treetable .pd-tt td.tt-expander .p-icon,
.p-treetable .pd-tt td.tt-expander .pi {
  font-size: 0.9rem;
  line-height: 1;
}

/* Status and priority badges */
.badge-status,
.badge-priority {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-status.status-draft,
.badge-status.status-inactive {
  background: #e9ecef;
  color: #495057;
}
.badge-status.status-released,
.badge-status.status-confirmed {
  background: #dbeafe;
  color: #1e40af;
}
.badge-status.status-in_progress,
.badge-status.status-in_production {
  background: #e0f2fe;
  color: #0369a1;
}
.badge-status.status-on_hold,
.badge-status.status-pending {
  background: #fef3c7;
  color: #92400e;
}
.badge-status.status-completed,
.badge-status.status-delivered,
.badge-status.status-active {
  background: #dcfce7;
  color: #166534;
}
.badge-status.status-cancelled,
.badge-status.status-blacklisted {
  background: #fee2e2;
  color: #991b1b;
}
.badge-status.status-submitted,
.badge-status.status-ready_to_ship,
.badge-status.status-shipped,
.badge-status.status-prospect {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-priority.priority-low {
  background: #e9ecef;
  color: #495057;
}
.badge-priority.priority-normal {
  background: #e0f2fe;
  color: #0369a1;
}
.badge-priority.priority-high {
  background: #fef3c7;
  color: #92400e;
}
.badge-priority.priority-urgent {
  background: #fee2e2;
  color: #991b1b;
}

/* Compact pick-mode UI for parts selector */
body.pick-mode nav.navbar {
  display: none;
}

body.pick-mode main.container {
  max-width: 100%;
  padding: 0.75rem;
}

body.pick-mode .pick-header {
  background: #f8f9fa;
  border-radius: 0.5rem;
}

body.pick-mode .pick-row td {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

/* Part number + description column sizing */
.table .col-part-number {
  min-width: 12ch;
  width: 12ch;
}

.table .col-description {
  min-width: 32ch;
  width: 45%;
}

/* Account surfaces */
.account-shell {
  display: block;
}

.account-panel {
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 0.75rem 2rem rgba(15, 23, 42, 0.04);
}

.account-panel--hero {
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 45%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.account-eyebrow {
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.account-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
}

.account-avatar {
  align-items: center;
  color: #ffffff;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  line-height: 1;
  text-transform: uppercase;
}

.account-avatar--circle {
  border-radius: 999px;
}

.account-avatar--rounded {
  border-radius: 0.9rem;
}

.account-avatar--square {
  border-radius: 0.35rem;
}

.account-avatar--sm {
  font-size: 0.72rem;
  height: 2rem;
  width: 2rem;
}

.account-avatar--md {
  font-size: 0.85rem;
  height: 2.4rem;
  width: 2.4rem;
}

.account-avatar--xl {
  font-size: 1.5rem;
  height: 4.5rem;
  width: 4.5rem;
}

.account-stats {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.account-stat {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 0.85rem;
  padding: 0.85rem;
}

.account-stat__label {
  color: #64748b;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.account-stat__value {
  color: #0f172a;
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

.account-chip-row,
.account-flag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.account-chip {
  background: #e2e8f0;
  border-radius: 999px;
  color: #0f172a;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
}

.account-chip--accent {
  background: #dbeafe;
  color: #1d4ed8;
}

.account-link-card {
  background: #f8fafc;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 0.9rem;
  color: inherit;
  display: block;
  height: 100%;
  padding: 1rem;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.account-link-card:hover {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0.65rem 1.5rem rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.account-kv {
  display: grid;
  gap: 0.75rem;
}

.account-kv > div {
  align-items: start;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  font-size: 0.92rem;
  gap: 1rem;
  justify-content: space-between;
  padding-bottom: 0.65rem;
}

.account-kv > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.account-kv span {
  color: #64748b;
}

.account-kv strong {
  color: #0f172a;
  font-weight: 600;
  text-align: right;
}

.account-flag {
  background: #e2e8f0;
  border-radius: 999px;
  color: #334155;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
}

.account-flag.is-on {
  background: #dcfce7;
  color: #166534;
}

.nav-account {
  align-items: center;
  display: inline-flex;
  gap: 0.6rem;
}

.tm-nav-search .form-control {
  min-width: 11rem;
}

.navbar .dropdown-menu {
  border: 1px solid var(--tm-border);
  border-radius: 0.9rem;
  box-shadow: var(--tm-shadow-soft);
}

.tm-nav-menu {
  min-width: 15rem;
}

.tm-nav-section-title {
  color: var(--tm-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tm-nav-section-title--danger {
  color: var(--tm-danger);
}

.nav-account__text {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.05;
}

.nav-account__label {
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
}

.nav-account__sub {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
}

.login-card {
  border: none;
  overflow: hidden;
}

.login-card__aside {
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.15), transparent 45%),
    linear-gradient(180deg, #f8fafc 0%, #eff6ff 100%);
  border-right: 1px solid rgba(15, 23, 42, 0.06);
}

.login-note {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
}

@media (max-width: 991.98px) {
  .tm-page-header {
    flex-direction: column;
  }

  .tm-page-header__actions {
    justify-content: flex-start;
  }

  .tm-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .tm-toolbar__actions {
    width: 100%;
  }

  .tm-nav-search {
    margin: 0.5rem 0;
    width: 100%;
  }

  .tm-nav-search .form-control {
    min-width: 0;
    width: 100%;
  }

  .tm-nav-menu {
    min-width: 0;
  }

  .account-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767.98px) {
  .tm-table-shell .table td,
  .tm-table-shell .table th {
    padding: 0.75rem 0.6rem;
  }

  .tm-state {
    padding: 1rem;
  }

  .account-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-kv > div {
    flex-direction: column;
    gap: 0.2rem;
  }

  .account-kv strong {
    text-align: left;
  }

  .nav-account__sub {
    display: none;
  }

  .login-card__aside {
    border-right: none;
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  }
}
