/* MES Design System — modern industrial UI */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --mes-font: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
  --mes-mono: 'JetBrains Mono', ui-monospace, monospace;

  --mes-primary: #0d9488;
  --mes-primary-hover: #0f766e;
  --mes-primary-soft: rgba(13, 148, 136, 0.12);
  --mes-accent: #3b82f6;
  --mes-accent-soft: rgba(59, 130, 246, 0.1);

  --mes-sidebar-bg: #111827;
  --mes-sidebar-surface: #1f2937;
  --mes-sidebar-border: rgba(148, 163, 184, 0.1);
  --mes-sidebar-text: #9ca3af;
  --mes-sidebar-text-active: #f9fafb;
  --mes-sidebar-muted: #6b7280;
  --mes-sidebar-hover: rgba(255, 255, 255, 0.04);
  --mes-sidebar-active-bg: rgba(59, 130, 246, 0.1);
  --mes-sidebar-active-border: #3b82f6;
  --mes-sidebar-width: 272px;
  --mes-sidebar-collapsed: 72px;

  --mes-topbar-h: 60px;
  --mes-bg: #f1f5f9;
  --mes-surface: #ffffff;
  --mes-border: #e2e8f0;
  --mes-text: #0f172a;
  --mes-text-muted: #64748b;

  --mes-radius: 12px;
  --mes-radius-sm: 8px;
  --mes-radius-lg: 16px;
  --mes-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
  --mes-shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.08);

  --mes-success: #059669;
  --mes-warning: #d97706;
  --mes-danger: #dc2626;
  --mes-info: #0284c7;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 15px;
  scroll-behavior: smooth;
  width: 100%;
}

@media (min-width: 1200px) {
  html { font-size: 16px; }
}

body.mes-app {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  font-family: var(--mes-font);
  color: var(--mes-text);
  background: var(--mes-bg);
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ── */
.mes-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--mes-sidebar-width);
  background: var(--mes-sidebar-bg);
  border-right: 1px solid var(--mes-sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.25s ease, width 0.25s ease;
}

.mes-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--mes-sidebar-border);
  text-decoration: none;
  color: #fff;
}

.mes-sidebar-brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--mes-sidebar-surface);
  border: 1px solid var(--mes-sidebar-border);
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: #e5e7eb;
  flex-shrink: 0;
  overflow: hidden;
}

.mes-brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mes-brand-tagline {
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 0.68rem;
}

.mes-sidebar-brand-text {
  line-height: 1.2;
}

.mes-sidebar-brand-text strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mes-sidebar-brand-text span {
  font-size: 0.7rem;
  color: var(--mes-sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mes-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.65rem 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,0.3) transparent;
  overflow-anchor: none;
  overscroll-behavior: contain;
}

.mes-sidebar-nav .collapse,
.mes-sidebar-nav .collapsing {
  transition: none !important;
}

.mes-nav-group {
  margin-bottom: 0.15rem;
}

/* Enterprise: single neutral palette — group accent classes kept for markup only */
.mes-nav-group--dashboard,
.mes-nav-group--production,
.mes-nav-group--inventory,
.mes-nav-group--quality,
.mes-nav-group--logistics,
.mes-nav-group--planning,
.mes-nav-group--reports,
.mes-nav-group--enterprise,
.mes-nav-group--master,
.mes-nav-group--settings {
  /* no per-group colors */
}

.mes-nav-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border: none;
  border-left: 2px solid transparent;
  background: transparent;
  color: #d1d5db;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  border-radius: 6px;
  cursor: pointer;
  scroll-margin: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mes-nav-group-toggle:hover {
  background: var(--mes-sidebar-hover);
  color: var(--mes-sidebar-text-active);
}

.mes-nav-group-toggle[aria-expanded="true"] {
  color: var(--mes-sidebar-text-active);
  border-left-color: var(--mes-sidebar-active-border);
  background: rgba(255, 255, 255, 0.03);
}

.mes-nav-group-toggle i.group-icon {
  width: 1.1rem;
  height: 1.1rem;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.72rem;
  color: var(--mes-sidebar-muted);
  background: transparent;
  border-radius: 0;
  opacity: 1;
  flex-shrink: 0;
}

.mes-nav-group-toggle:hover i.group-icon,
.mes-nav-group-toggle[aria-expanded="true"] i.group-icon {
  color: #9ca3af;
}

.mes-nav-group-toggle .chevron {
  margin-left: auto;
  font-size: 0.6rem;
  color: var(--mes-sidebar-muted);
  opacity: 0.8;
  transition: transform 0.2s, color 0.15s;
}

.mes-nav-group-toggle:hover .chevron,
.mes-nav-group-toggle[aria-expanded="true"] .chevron {
  color: #9ca3af;
}

.mes-nav-group-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.mes-nav-items {
  list-style: none;
  margin: 0.15rem 0 0.5rem;
  padding: 0 0.25rem;
}

.mes-nav-section {
  padding: 0.5rem 0.75rem 0.15rem;
  margin-top: 0.2rem;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mes-sidebar-muted);
  list-style: none;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
}

.mes-nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.75rem;
  margin-bottom: 1px;
  border-radius: 6px;
  border-left: 2px solid transparent;
  color: var(--mes-sidebar-text);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mes-nav-link i {
  width: 1.1rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--mes-sidebar-muted);
  opacity: 1;
}

.mes-nav-link:hover {
  background: var(--mes-sidebar-hover);
  color: #e5e7eb;
}

.mes-nav-link:hover i {
  color: #9ca3af;
}

.mes-nav-link.active {
  background: var(--mes-sidebar-active-bg);
  color: var(--mes-sidebar-text-active);
  border-left-color: var(--mes-sidebar-active-border);
}

.mes-nav-link.active i {
  color: #93c5fd;
}

.mes-sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--mes-sidebar-border);
  font-size: 0.72rem;
  color: var(--mes-sidebar-text);
  text-align: center;
}

.mes-shell {
  margin-left: var(--mes-sidebar-width);
  width: calc(100vw - var(--mes-sidebar-width));
  max-width: none;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease, width 0.25s ease;
}

.mes-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--mes-topbar-h);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--mes-border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
}

.mes-topbar-toggle {
  display: none;
  border: 1px solid var(--mes-border);
  background: var(--mes-surface);
  border-radius: var(--mes-radius-sm);
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--mes-text);
}

.mes-topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--mes-text);
  margin: 0;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mes-topbar-breadcrumb {
  font-size: 0.8rem;
  color: var(--mes-text-muted);
  margin: 0;
}

.mes-topbar-breadcrumb a {
  color: var(--mes-text-muted);
  text-decoration: none;
}

.mes-topbar-breadcrumb a:hover { color: var(--mes-primary); }

.mes-topbar > div:nth-child(2) {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.mes-topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mes-user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem 0.35rem 0.35rem;
  border-radius: 999px;
  background: var(--mes-bg);
  border: 1px solid var(--mes-border);
  text-decoration: none;
  color: var(--mes-text);
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.mes-user-chip:hover {
  border-color: var(--mes-primary);
  box-shadow: var(--mes-shadow);
  color: var(--mes-text);
}

.mes-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mes-primary), var(--mes-accent));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.mes-main {
  flex: 1;
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 1.25rem 1.25rem 2rem;
}

@media (min-width: 992px) {
  .mes-main { padding: 1.5rem 1.75rem 2.5rem; }
}

/* Mobile sidebar */
@media (max-width: 991.98px) {
  .mes-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--mes-shadow-lg);
  }

  body.mes-sidebar-open .mes-sidebar {
    transform: translateX(0);
  }

  .mes-shell {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }

  .mes-topbar-toggle { display: inline-flex; }

  body.mes-sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    z-index: 1035;
  }
}

/* ── Page patterns (auto-enhance existing views) ── */
.mes-main .container-fluid {
  padding-left: 0 !important;
  padding-right: 0 !important;
  width: 100%;
  max-width: none;
  min-width: 0;
}

/* Bootstrap .container caps width (~1320px) — stretch list/index pages to full shell */
.mes-main :is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl):not([style*="max-width"]) {
  width: 100%;
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

/* Wide tables: grow with columns + horizontal scroll (don't squash Actions) */
.mes-main .table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mes-main .card:has(.table-responsive),
.mes-main .card-body:has(> .table-responsive) {
  overflow: visible;
}

.mes-main .table-responsive > .table {
  width: max-content;
  min-width: 100%;
}

.mes-main .wo-steps-inner-table {
  width: max-content;
  min-width: 100%;
}

.mes-main .wo-group td[colspan] > .collapse,
.mes-main .wo-group td[colspan] > .collapsing {
  width: 100%;
}

/* Production / wide tables — keep Actions column visible while scrolling */
.mes-main .table-responsive > .table > :is(thead, tbody) > tr > :is(th, td):last-child,
.mes-main .table-responsive .wo-steps-inner-table > tbody > tr > td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--mes-surface);
  box-shadow: -6px 0 10px rgba(15, 23, 42, 0.06);
}

.mes-main .table-responsive > .table > thead > tr > th:last-child {
  z-index: 4;
  background: #f8fafc !important;
}

.mes-main .table-responsive > .table > tbody > tr.table-light > td:last-child,
.mes-main .table-responsive .wo-steps-inner-table > tbody > tr.table-light > td:last-child {
  background: #f8fafc;
}

.mes-main .table-responsive > .table.table-hover > tbody > tr:hover > td:last-child,
.mes-main .table-responsive .wo-steps-inner-table.table-hover > tbody > tr:hover > td:last-child {
  background: rgba(13, 148, 136, 0.04);
}

.mes-main .table-responsive .wo-steps-inner-table > tbody > tr > td:last-child {
  min-width: 160px;
  white-space: nowrap;
}

.mes-main h1, .mes-main h2, .mes-main h3, .mes-main h4 {
  letter-spacing: -0.02em;
  color: var(--mes-text);
}

.mes-main h3 {
  font-weight: 700;
  font-size: 1.45rem;
}

/* Cards */
.mes-main .card.routing-search-card,
.mes-main .card.routing-search-card .card-body {
  overflow: visible;
}

.mes-typeahead-dropdown {
  z-index: 1050;
  max-height: 280px;
  overflow-y: auto;
  top: 100%;
  margin-top: 2px;
  background: var(--mes-surface, #fff);
}

.mes-main .card {
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  box-shadow: var(--mes-shadow);
  background: var(--mes-surface);
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}

.mes-main .card .table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Fallback scroll when views omit .table-responsive wrapper */
.mes-main .card-body.p-0:has(> table),
.mes-main .card-body:has(> table:only-child),
.mes-main .card:has(> table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.mes-main form .row {
  min-width: 0;
}

.mes-main .input-group {
  flex-wrap: wrap;
}

.mes-main .input-group > .form-control,
.mes-main .input-group > .form-select,
.mes-main .input-group > .btn {
  min-width: 0;
}

.mes-main .card.shadow-sm,
.mes-main .card.border-0 {
  border: 1px solid var(--mes-border);
  box-shadow: var(--mes-shadow);
}

.mes-main .card-header {
  background: var(--mes-surface);
  border-bottom: 1px solid var(--mes-border);
  padding: 0.85rem 1.15rem;
  font-weight: 600;
}

.mes-main .card-body { padding: 1.15rem; }

.mes-main .card-footer {
  background: #f8fafc;
  border-top: 1px solid var(--mes-border);
  padding: 0.75rem 1.15rem;
}

/* Tables */
.mes-main .table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}

.mes-main .table thead th,
.mes-main .table-light th {
  background: #f8fafc !important;
  color: var(--mes-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--mes-border);
  padding: 0.75rem 1rem;
  white-space: normal;
}

@media (min-width: 1200px) {
  .mes-main .table thead th,
  .mes-main .table-light th {
    white-space: nowrap;
  }
}

.mes-main .table tbody td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.mes-main .table-hover tbody tr:hover {
  background: rgba(13, 148, 136, 0.04);
}

.mes-main .table tbody tr:last-child td {
  border-bottom: none;
}

/* Forms */
.mes-main .form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mes-text);
  margin-bottom: 0.35rem;
}

.mes-main .form-control,
.mes-main .form-select {
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.mes-main .form-control:focus,
.mes-main .form-select:focus {
  border-color: var(--mes-primary);
  box-shadow: 0 0 0 3px var(--mes-primary-soft);
}

.mes-main .form-control-lg {
  border-radius: var(--mes-radius);
  font-size: 1.05rem;
}

/* Buttons */
.btn {
  font-weight: 600;
  border-radius: var(--mes-radius-sm);
  font-size: 0.875rem;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--mes-primary);
  border-color: var(--mes-primary);
}

.btn-primary:hover, .btn-primary:focus {
  background: var(--mes-primary-hover);
  border-color: var(--mes-primary-hover);
}

.btn-outline-primary {
  color: var(--mes-primary);
  border-color: var(--mes-primary);
}

.btn-outline-primary:hover {
  background: var(--mes-primary);
  border-color: var(--mes-primary);
}

.mes-main .btn-sm {
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
}

/* Badges */
.badge {
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.35em 0.65em;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

/* Alerts */
.mes-main .alert,
.mes-flash .alert {
  border: none;
  border-radius: var(--mes-radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  border-left: 4px solid;
}

.mes-main .alert-success, .mes-flash .alert-success {
  background: #ecfdf5;
  color: #065f46;
  border-left-color: var(--mes-success);
}

.mes-main .alert-danger, .mes-flash .alert-danger {
  background: #fef2f2;
  color: #991b1b;
  border-left-color: var(--mes-danger);
}

.mes-main .alert-warning, .mes-flash .alert-warning {
  background: #fffbeb;
  color: #92400e;
  border-left-color: var(--mes-warning);
}

.mes-main .alert-info, .mes-flash .alert-info {
  background: #f0f9ff;
  color: #075985;
  border-left-color: var(--mes-info);
}

/* Pagination */
.mes-main .pagination .page-link {
  border-radius: var(--mes-radius-sm);
  margin: 0 2px;
  border-color: var(--mes-border);
  color: var(--mes-text);
  font-size: 0.85rem;
}

.mes-main .pagination .page-item.active .page-link {
  background: var(--mes-primary);
  border-color: var(--mes-primary);
}

/* Links in tables */
.mes-main .table a:not(.btn) {
  color: var(--mes-primary);
  font-weight: 600;
  text-decoration: none;
}

.mes-main .table a:not(.btn):hover {
  text-decoration: underline;
}

/* Code */
code {
  font-family: var(--mes-mono);
  font-size: 0.85em;
  background: #f1f5f9;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: #be185d;
}

/* Display stats (dashboard) */
.mes-stat-card {
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  background: var(--mes-surface);
  padding: 1.25rem;
  box-shadow: var(--mes-shadow);
  height: 100%;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.mes-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--mes-shadow-lg);
}

.mes-stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--mes-primary), var(--mes-accent));
}

.mes-stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mes-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mes-stat-value {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  margin: 0.35rem 0;
  letter-spacing: -0.03em;
}

.mes-stat-link {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mes-primary);
  text-decoration: none;
}

.mes-stat-link:hover { text-decoration: underline; }

/* Hub / module cards */
.mes-module-card {
  display: block;
  text-decoration: none;
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  background: var(--mes-surface);
  padding: 1.15rem;
  height: 100%;
  box-shadow: var(--mes-shadow);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  color: inherit;
}

.mes-module-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--mes-shadow-lg);
  border-color: var(--mes-primary);
  color: inherit;
}

.mes-module-card .module-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  background: var(--mes-primary-soft);
  color: var(--mes-primary);
}

.mes-module-card.proxy .module-icon {
  background: #fff7ed;
  color: var(--mes-warning);
}

/* Page header utility */
.mes-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
  min-width: 0;
  max-width: 100%;
}

.mes-page-header > div:first-child {
  min-width: 0;
  flex: 1 1 12rem;
}

.mes-page-header .d-flex,
.mes-topbar-actions {
  flex-shrink: 0;
}

.mes-main .row > [class*="col-"] {
  min-width: 0;
}

.mes-lot-cell {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mes-action-cell {
  white-space: nowrap;
}

.mes-action-cell .btn {
  margin-bottom: 0.15rem;
}

#gantt-scroll {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.mes-page-header h3 { margin-bottom: 0.15rem; }

.mes-page-subtitle {
  color: var(--mes-text-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Empty state */
.mes-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--mes-text-muted);
}

.mes-empty i {
  font-size: 2.5rem;
  opacity: 0.35;
  margin-bottom: 0.75rem;
}

/* Login */
.mes-login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f766e 100%);
  padding: 1.5rem;
}

.mes-login-card {
  width: 100%;
  max-width: 420px;
  background: var(--mes-surface);
  border-radius: var(--mes-radius-lg);
  box-shadow: var(--mes-shadow-lg);
  overflow: hidden;
}

.mes-login-header {
  background: linear-gradient(135deg, var(--mes-sidebar-bg), #1e293b);
  color: #fff;
  padding: 2rem 1.75rem 1.5rem;
  text-align: center;
}

.mes-login-header .brand-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #fff;
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  padding: 4px;
  box-shadow: 0 8px 20px rgba(13,148,136,0.4);
  overflow: hidden;
}

.mes-login-header .brand-icon .mes-brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mes-login-body { padding: 1.75rem; }

/* Print pages — no sidebar */
body.mes-print-layout .mes-sidebar,
body.mes-print-layout .mes-topbar { display: none; }
body.mes-print-layout .mes-shell {
  margin-left: 0;
  width: 100%;
  max-width: 100%;
}

/* Focus */
.btn:focus, .btn:active:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px var(--mes-primary-soft);
}

/* Scrollbar */
.mes-main ::-webkit-scrollbar { width: 8px; height: 8px; }
.mes-chart-wrap { position: relative; width: 100%; }
.mes-chart-wrap canvas { max-width: 100%; }

.mes-page-section {
  background: var(--mes-surface);
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  box-shadow: var(--mes-shadow);
}

.mes-mobile-stack {
  display: grid;
  gap: 0.875rem;
}

.mes-mobile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.mes-mobile-actions > * {
  flex: 1 1 160px;
}

.mes-scan-shell {
  max-width: 760px;
}

.mes-scan-status {
  margin-bottom: 1rem;
}

.mes-scan-form {
  display: grid;
  gap: 0.875rem;
}

.mes-scan-primary {
  position: sticky;
  bottom: 0;
  z-index: 3;
  background: linear-gradient(180deg, rgba(241,245,249,0) 0%, rgba(241,245,249,0.92) 24%, rgba(241,245,249,1) 100%);
  padding-top: 0.75rem;
}

.mes-scan-input-wrap {
  display: grid;
  gap: 0.75rem;
}

.mes-scan-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.mes-scan-hint {
  color: var(--mes-text-muted);
  font-size: 0.875rem;
  margin: 0;
}

.mes-scan-card {
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  background: var(--mes-surface);
  padding: 1rem;
  box-shadow: var(--mes-shadow);
}

.mes-scan-grid {
  display: grid;
  gap: 0.875rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.mes-scan-kv {
  display: grid;
  gap: 0.25rem;
}

.mes-scan-kv-label {
  color: var(--mes-text-muted);
  font-size: 0.8rem;
}

.mes-scan-kv-value {
  font-weight: 600;
  word-break: break-word;
}

.mes-mobile-list {
  display: grid;
  gap: 0.75rem;
}

.mes-mobile-list-item {
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius);
  background: var(--mes-surface);
  padding: 0.875rem 1rem;
  box-shadow: var(--mes-shadow);
}

.mes-mobile-list-item.is-success {
  border-color: rgba(5, 150, 105, 0.25);
  background: rgba(5, 150, 105, 0.05);
}

.mes-mobile-list-title {
  font-weight: 700;
}

.mes-mobile-list-meta {
  color: var(--mes-text-muted);
  font-size: 0.875rem;
}

.mes-mobile-list-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.mes-mobile-note {
  border-left: 4px solid var(--mes-accent);
  background: var(--mes-accent-soft);
  border-radius: 0 var(--mes-radius-sm) var(--mes-radius-sm) 0;
  padding: 0.875rem 1rem;
}

.mes-print-mobile-note {
  border: 1px solid rgba(217, 119, 6, 0.25);
  background: rgba(217, 119, 6, 0.08);
  color: #92400e;
  border-radius: var(--mes-radius);
  padding: 0.875rem 1rem;
}

.mes-scan-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 2000;
}

.mes-scan-modal {
  width: min(100%, 560px);
  background: #020617;
  color: #f8fafc;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(2, 6, 23, 0.45);
}

.mes-scan-modal-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  padding: 1rem 1rem 0.5rem;
}

.mes-scan-modal-title {
  font-size: 1rem;
  font-weight: 700;
}

.mes-scan-modal-subtitle {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.mes-scan-video-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #000;
}

.mes-scan-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mes-scan-reticle {
  position: absolute;
  inset: 18% 10%;
  border: 3px solid rgba(94, 234, 212, 0.95);
  border-radius: 20px;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.25);
}

.mes-scan-modal-actions {
  padding: 1rem;
}

.mes-mobile-table-hint {
  display: none;
}

@media (max-width: 767.98px) {
  .mes-main {
    padding-left: 0.875rem;
    padding-right: 0.875rem;
  }

  .container,
  .container-fluid {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  .mes-mobile-actions {
    flex-direction: column;
  }

  .mes-mobile-actions > * {
    flex-basis: auto;
  }

  .mes-scan-input-row {
    grid-template-columns: 1fr;
  }

  .mes-scan-card {
    padding: 0.875rem;
  }

  .mes-mobile-table-hint {
    display: block;
  }

  .mes-responsive-stack table,
  .mes-responsive-stack thead,
  .mes-responsive-stack tbody,
  .mes-responsive-stack th,
  .mes-responsive-stack td,
  .mes-responsive-stack tr {
    display: block;
  }

  .mes-responsive-stack thead {
    display: none;
  }

  .mes-responsive-stack tbody {
    display: grid;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .mes-responsive-stack tr {
    border: 1px solid var(--mes-border);
    border-radius: var(--mes-radius);
    padding: 0.875rem;
    background: var(--mes-surface);
    box-shadow: var(--mes-shadow);
  }

  .mes-responsive-stack td {
    border: 0;
    padding: 0.2rem 0;
    text-align: left !important;
  }

  .mes-responsive-stack td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.76rem;
    color: var(--mes-text-muted);
    margin-bottom: 0.1rem;
  }
}

/* ── User Guide — enterprise secondary nav ── */
.user-guide-page .user-guide-sidebar-header {
  background: var(--mes-sidebar-bg);
  color: #f3f4f6;
  border-bottom: 1px solid var(--mes-sidebar-border);
}

.user-guide-page .list-group-item-action {
  font-size: 0.875rem;
  color: var(--mes-text);
  border-color: var(--mes-border);
}

.user-guide-page .list-group-item-action:hover {
  background: #f8fafc;
  color: var(--mes-text);
}

.user-guide-page .list-group-item-action.active {
  background: var(--mes-sidebar-active-bg);
  color: #1e40af;
  border-color: var(--mes-border);
  border-left: 3px solid var(--mes-sidebar-active-border);
  font-weight: 600;
}

.user-guide-page .list-group-item.bg-light {
  background: #f8fafc !important;
  color: var(--mes-text-muted);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  border-color: var(--mes-border);
}

/* ── Searchable selects (Tom Select) ── */
.mes-app .ts-wrapper.form-select,
.mes-app .ts-wrapper.single .ts-control,
.mes-app .ts-wrapper.multi .ts-control {
  min-height: calc(1.5em + 0.75rem + 2px);
  border-radius: var(--mes-radius-sm);
  border-color: var(--mes-border);
  font-family: var(--mes-font);
}

.mes-app .ts-wrapper.focus .ts-control {
  border-color: var(--mes-primary);
  box-shadow: 0 0 0 0.2rem var(--mes-primary-soft);
}

.mes-app .ts-dropdown {
  z-index: 2000;
  border-radius: var(--mes-radius-sm);
  font-family: var(--mes-font);
}

.mes-app .ts-dropdown .option,
.mes-app .ts-dropdown .no-results {
  padding: 0.45rem 0.75rem;
}

.mes-app .ts-wrapper.disabled .ts-control {
  background-color: #e9ecef;
  opacity: 1;
}

/* ── Shell UX polish: quick search + breadcrumb + page header ── */
.mes-topbar-search {
  flex: 1 1 220px;
  max-width: 360px;
  margin: 0 0.75rem;
  min-width: 160px;
}
.mes-topbar-search form {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0;
}
.mes-topbar-search input {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--mes-border);
  border-radius: 999px;
  padding: 0 0.9rem;
  font-size: 0.86rem;
  background: #fff;
  color: var(--mes-text);
}
.mes-topbar-search input:focus {
  outline: none;
  border-color: var(--mes-primary);
  box-shadow: 0 0 0 3px var(--mes-primary-soft);
}
.mes-topbar-search button {
  height: 34px;
  border-radius: 999px;
  padding: 0 0.75rem;
  white-space: nowrap;
}
.mes-topbar-crumb a { color: var(--mes-primary); text-decoration: none; }
.mes-topbar-crumb a:hover { text-decoration: underline; }
.mes-topbar-crumb .sep { margin: 0 0.35rem; color: var(--mes-text-muted); }

.mes-page-header.mes-page-header--actions-only h3 { display: none; }
.mes-page-header.mes-page-header--actions-only {
  margin-top: 0;
  margin-bottom: 1rem;
  justify-content: flex-end;
}

/* Soft-hide first in-body title when it duplicates topbar (common MES index pattern) */
.mes-main > .d-flex.justify-content-between.align-items-center.mb-3 > h3.mb-0:first-child,
.mes-main > h3.mb-3:first-child,
.mes-main > h3.mb-4:first-child {
  /* keep visible for pages that don't set ViewData Title well; opt-in hide via class */
}

.mes-main.mes-hide-dup-title > .d-flex.justify-content-between.align-items-center.mb-3 > h3:first-child,
.mes-main.mes-hide-dup-title > h3:first-of-type {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Tag Journey inside shell */
.tj-rail-wrap {
  background: var(--mes-surface);
  border: 1px solid var(--mes-border);
  border-radius: var(--mes-radius-lg);
  padding: 1.25rem 1rem 1.5rem;
  max-width: 100%;
  min-width: 0;
}
.tj-rail-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mes-text-muted);
  margin-bottom: 0.85rem;
}
.tj-rail-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-bottom: 0.4rem;
  scrollbar-gutter: stable;
}
.tj-rail {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: max-content;
  min-width: max-content;
  padding: 0.25rem 0.5rem;
}
.tj-node { width: 230px; flex: 0 0 auto; display: flex; flex-direction: column; }
.tj-stage { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: 0.4rem; }
.tj-stage.wip { color: var(--mes-accent); }
.tj-stage.fg { color: var(--mes-primary-hover); }
.tj-stage.cust { color: #b45309; }
.tj-stage.rm { color: #a16207; }
.tj-box {
  flex: 1;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  padding: 0.85rem 0.9rem;
  background: #fff;
  min-height: 168px;
  display: flex;
  flex-direction: column;
}
.tj-box.wip { border-color: #93c5fd; background: #eff6ff; }
.tj-box.fg { border-color: #5eead4; background: #f0fdfa; }
.tj-box.cust { border-color: #fcd34d; background: #fffbeb; }
.tj-box.rm { border-color: #fde68a; background: #fffbeb; }
.tj-box.current { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }
.tj-box.inferred { border-style: dashed; }
.tj-tag a { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.02rem; }
.tj-tag a:hover { text-decoration: underline; }
.tj-meta { font-size: 0.8rem; color: var(--mes-text-muted); margin-top: 0.12rem; line-height: 1.35; }
.tj-drill { margin-top: auto; padding-top: 0.55rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tj-drill a {
  font-size: 0.68rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
  color: #334155;
  background: #fff;
}
.tj-drill a:hover { border-color: #64748b; background: #f8fafc; }
.tj-connector {
  width: 40px;
  flex: 0 0 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-top: 1.35rem;
}
.tj-connector::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #cbd5e1, #64748b);
  border-radius: 2px;
}
.tj-connector span {
  position: relative;
  z-index: 1;
  background: var(--mes-surface);
  color: #334155;
  font-weight: 800;
  padding: 0 0.15rem;
  font-size: 1.05rem;
}
.tj-panel {
  margin-top: 1rem;
  background: var(--mes-surface);
  border: 1px solid var(--mes-border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}
.tj-panel h2 { font-size: 1rem; margin: 0 0 0.65rem; font-weight: 700; }
.tj-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tj-tools a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--mes-border);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  text-decoration: none;
  color: var(--mes-text);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 600;
}
.tj-tools a:hover { border-color: #94a3b8; background: #f8fafc; }
.tj-tools a .hint { font-weight: 400; color: var(--mes-text-muted); font-size: 0.75rem; }
.tj-step-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tj-step-table th, .tj-step-table td { border-top: 1px solid var(--mes-border); padding: 0.55rem 0.4rem; vertical-align: top; }
.tj-step-table th { color: var(--mes-text-muted); font-weight: 600; text-align: left; width: 9rem; }

@media (max-width: 900px) {
  .mes-topbar-search { max-width: none; margin: 0 0.35rem; flex-basis: 140px; }
  .mes-topbar-search .btn-label { display: none; }
}
