:root {
  /* Brand tokens */
  --bg: #0b1220;
  --panel: #0f1a2b;
  --panel-2: #0b1120;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.22);
  --ring: rgba(59, 130, 246, 0.35);
  --primary: #3b82f6;
  --primary-600: #2563eb;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;

  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);

  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;

  --sidebar-w: 280px;
}

::selection {
  background: rgba(59, 130, 246, 0.55);
  color: #f8fafc;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% 0%, rgba(59,130,246,.18), transparent 60%),
              radial-gradient(900px 500px at 80% 10%, rgba(16,185,129,.12), transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.35;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--primary); }

/* Layout */
.app-shell {
  position: relative;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-w);
  height: 100vh;
  border-right: 1px solid var(--border);
  background: rgba(15, 26, 43, 0.9);
  backdrop-filter: blur(10px);
  transform: translateX(0);
  transition: transform 180ms ease;
  z-index: 40;
  overflow-y: auto;
}


.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 30;
}

.sidebar-peek {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  cursor: ew-resize;
  z-index: 25;
  display: none;
}

.app-shell.is-sidebar-collapsed .sidebar {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

.app-shell.is-sidebar-collapsed .main {
  margin-left: 0;
}

.app-shell.is-sidebar-collapsed .sidebar-peek {
  display: block;
}

.app-shell.is-sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-badge {
  height: 34px;
  width: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(59,130,246,.18);
  border: 1px solid rgba(59,130,246,.35);
  box-shadow: 0 8px 18px rgba(59,130,246,.12);
  font-weight: 700;
}

.brand-title {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-title strong { font-size: 13px; }
.brand-title span { font-size: 12px; color: var(--muted); }

.sidebar__nav {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nav-group { margin-top: 0; }
.nav-group__title {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(148,163,184,.8);
  margin: 14px 10px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  width: 100%;
  box-sizing: border-box;
  border-radius: 12px;
  border: 1px solid transparent;
  color: rgba(226,232,240,.92);
}

.nav-item span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item:hover {
  background: rgba(148,163,184,.08);
  border-color: rgba(148,163,184,.18);
}

.nav-item.is-active {
  background: rgba(59,130,246,.14);
  border-color: rgba(59,130,246,.30);
  box-shadow: 0 0 0 3px rgba(59,130,246,.10);
}

.nav-item__hint {
  margin-left: auto;
  font-size: 11px;
  color: rgba(148,163,184,.8);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  margin-left: var(--sidebar-w);
  transition: margin-left 180ms ease;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 18, 32, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.icon-btn {
  height: 36px;
  width: 36px;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.22);
  background: rgba(15,26,43,.65);
  color: rgba(226,232,240,.92);
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
}

.icon-btn:hover {
  border-color: rgba(148,163,184,.30);
  background: rgba(15,26,43,.78);
}

.icon-btn:active {
  transform: translateY(1px);
}

.crumbs { display: flex; gap: 8px; align-items: center; color: rgba(148,163,184,.9); }
.crumbs a { color: rgba(226,232,240,.95); }
.crumbs .sep { opacity: .6; }

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,.22);
  background: rgba(15,26,43,.65);
}

.avatar {
  height: 26px;
  width: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(148,163,184,.12);
  border: 1px solid rgba(148,163,184,.22);
  font-weight: 700;
  font-size: 12px;
}

.content {
  padding: 22px;
  /* WMS grids need horizontal room (many columns).
     Keep the layout fluid; use cards/padding for comfort instead of hard max-width. */
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}

/* UI primitives */
.h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -0.02em; }
.subtle { color: var(--muted); font-size: 14px; }


/* Page header (standard top section inside content) */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.page-header__left { min-width: 0; }
.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .page-header { flex-direction: column; }
  .page-header__actions { justify-content: flex-start; }
}

/* Small layout helpers */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* KPI values on dashboard/cards */
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi-actions { margin-top: 10px; }

.card__title { font-weight: 800; }

.card {
  background: rgba(15, 26, 43, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card__body { padding: 14px 16px; }

/* Card body without padding (useful for full-width grids) */
.card__body--flush { padding: 0; }

/* Container for Tabulator grids */
.grid-host { width: 100%; }
.grid-host .tabulator { width: 100% !important; border: 0 !important; border-radius: 0; }

/* Make rows feel clickable where needed */
.grid-host--clickable .tabulator-row { cursor: pointer; }
.grid-host--clickable .tabulator-row:hover { background-color: rgba(59,130,246,.10) !important; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.toolbar__left { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar__right { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(148,163,184,.22);
  background: rgba(2, 6, 23, 0.15);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover { border-color: rgba(148,163,184,.35); background: rgba(148,163,184,.08); }
.btn:focus { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.btn-primary { background: rgba(59,130,246,.18); border-color: rgba(59,130,246,.40); }
.btn-primary:hover { background: rgba(59,130,246,.25); }
.btn-danger { background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.35); }
.btn-link { border: none; background: transparent; padding: 0; font-weight: 600; }

.input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.22);
  background: rgba(2, 6, 23, 0.25);
  color: var(--text);
}
.input:focus { outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: rgba(59,130,246,.45); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,.25);
  font-size: 12px;
  color: rgba(226,232,240,.92);
}
.badge.ok { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.32); }
.badge.warn { background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.32); }
.badge.danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.32); }
.badge.blue { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.32); }

/* Flash messages */
.messages { margin: 10px 0 14px; }
.alert {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  margin-bottom: 10px;
  font-size: 13px;
}
.alert-success { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.35); color: #d1fae5; }
.alert-error   { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.35);  color: #fee2e2; }
.alert-warning { background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.35); color: #ffedd5; }
.alert-info    { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.35); color: #dbeafe; }

/* Responsive */
@media (max-width: 1024px) {
  .main { margin-left: 0; }

  /* Mobile: sidebar is off-canvas by default */
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar-peek { display: block; }

  .app-shell.is-sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.is-sidebar-open .sidebar-peek { display: none; }

  .grid-4 { grid-template-columns: repeat(2, 1fr); }


}

/* Tabulator theme adjustments (we still use its base CSS from CDN) */
.tabulator {
  border: 1px solid rgba(148,163,184,.18) !important;
  background: rgba(2, 6, 23, 0.18) !important;
  border-radius: 14px;
}
.tabulator .tabulator-tableholder{
  /* Tabulator 6 иногда красит подложку/таблицу в белый. Пробиваем максимально жёстко. */
  background: rgba(2, 6, 23, 0.22) !important;
  background-color: rgba(2, 6, 23, 0.22) !important;
}

/* Dark scrollbars inside grids (keeps the horizontal bar from being white on macOS/Chrome) */
.tabulator .tabulator-tableholder{
  scrollbar-color: rgba(148,163,184,.35) rgba(2,6,23,.25);
  scrollbar-width: thin;
}
.tabulator .tabulator-tableholder::-webkit-scrollbar{ width: 10px; height: 10px; }
.tabulator .tabulator-tableholder::-webkit-scrollbar-track{
  background: rgba(2,6,23,.25);
  border-radius: 999px;
}
.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb{
  background: rgba(148,163,184,.28);
  border-radius: 999px;
  border: 2px solid rgba(2,6,23,.25);
}
.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb:hover{ background: rgba(148,163,184,.38); }
.tabulator .tabulator-tableholder::-webkit-scrollbar-corner{ background: rgba(2,6,23,.25); }

.tabulator .tabulator-tableholder .tabulator-table{
  background: transparent !important;
  background-color: transparent !important;
  /* If columns are narrow, Tabulator keeps the inner table 'inline-block' and it won't stretch. */
  min-width: 100% !important;
}
.tabulator .tabulator-table { background: transparent !important; background-color: transparent !important; color: rgba(226,232,240,.94) !important; }
.tabulator .tabulator-header { background: rgba(2, 6, 23, 0.35) !important; border-bottom: 1px solid rgba(148,163,184,.18) !important; }
.tabulator .tabulator-row { background: rgba(255,255,255,.01) !important; background-color: rgba(255,255,255,.01) !important; }
.tabulator .tabulator-row.tabulator-row-even { background: rgba(148,163,184,.06) !important; background-color: rgba(148,163,184,.06) !important; }
.tabulator .tabulator-row.tabulator-selected { background: rgba(59,130,246,.24) !important; background-color: rgba(59,130,246,.24) !important; }
.tabulator .tabulator-row:hover { background: rgba(148,163,184,.10) !important; background-color: rgba(148,163,184,.10) !important; }
.tabulator .tabulator-cell {
  border-right: 1px solid rgba(148,163,184,.10) !important;
  border-bottom: 1px solid rgba(148,163,184,.08) !important;
  background: transparent !important;
  background-color: transparent !important;
  color: rgba(226,232,240,.94) !important;
}
.tabulator .tabulator-footer { background: rgba(2, 6, 23, 0.25) !important; border-top: 1px solid rgba(148,163,184,.18) !important; }

.tabulator .tabulator-header .tabulator-col {
  background: transparent !important;
  border-right: 1px solid rgba(148,163,184,.10) !important;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  color: rgba(148,163,184,.92) !important;
  font-weight: 700;
}

.tabulator .tabulator-header .tabulator-col .tabulator-header-menu-button {
  color: rgba(148,163,184,.85) !important;
  opacity: .75;
  border-radius: 10px;
}
.tabulator .tabulator-header .tabulator-col .tabulator-header-menu-button:hover {
  opacity: 1;
  background: rgba(148,163,184,.10) !important;
}

.tabulator .tabulator-header-filter input,
.tabulator .tabulator-header-filter select {
  width: 100%;
  box-sizing: border-box;
  background: rgba(2, 6, 23, 0.30) !important;
  border: 1px solid rgba(148,163,184,.22) !important;
  color: rgba(226,232,240,.96) !important;
  border-radius: 10px;
  padding: 6px 8px;
}

.tabulator .tabulator-header-filter input::placeholder {
  color: rgba(148,163,184,.55) !important;
}

.tabulator .tabulator-header-filter input:focus,
.tabulator .tabulator-header-filter select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
  border-color: rgba(59,130,246,.45) !important;
}

.tabulator .tabulator-placeholder {
  color: rgba(148,163,184,.85) !important;
}

.tabulator .tabulator-footer label {
  color: rgba(148,163,184,.85) !important;
}

.tabulator .tabulator-footer .tabulator-page-size {
  background: rgba(2, 6, 23, 0.20) !important;
  border: 1px solid rgba(148,163,184,.22) !important;
  color: rgba(226,232,240,.96) !important;
  border-radius: 10px;
  padding: 6px 8px;
}

.tabulator .tabulator-footer .tabulator-page {
  background: rgba(2, 6, 23, 0.18) !important;
  border: 1px solid rgba(148,163,184,.22) !important;
  color: rgba(226,232,240,.96) !important;
  border-radius: 10px;
  padding: 6px 10px;
}

.tabulator .tabulator-footer .tabulator-page.active {
  background: rgba(59,130,246,.20) !important;
  border-color: rgba(59,130,246,.35) !important;
}

/* Header menu (columns picker) */
.tabulator-menu {
  background: rgba(2, 6, 23, 0.96) !important;
  border: 1px solid rgba(148,163,184,.22) !important;
  border-radius: 14px !important;
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  padding: 6px !important;
}

.tabulator-menu .tabulator-menu-item {
  color: rgba(226,232,240,.92) !important;
  border-radius: 10px;
  padding: 8px 10px;
}

.tabulator-menu .tabulator-menu-item:hover {
  background: rgba(148,163,184,.10) !important;
}

.tb-menu-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(148,163,184,.22);
  margin-right: 8px;
  font-weight: 800;
  line-height: 1;
  color: transparent;
  background: rgba(2, 6, 23, 0.35);
}

.tb-menu-check.is-on {
  color: rgba(226,232,240,.95);
  background: rgba(59,130,246,.18);
  border-color: rgba(59,130,246,.35);
}

.tb-menu-title {
  vertical-align: middle;
}

/* Compact action buttons inside grids */
.tabulator .btn.btn-sm {
  padding: 6px 10px;
  border-radius: 999px;
  line-height: 1;
  min-height: 28px;
}

/* -------------------------------------------------
   Portal helpers & variants
   ------------------------------------------------- */

/* Muted text helper (used across pages) */
.muted { color: var(--muted); }

/* Alerts: alias bootstrap-like names used by JS */
.alert-danger { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.35);  color: #fee2e2; }
.alert-ok     { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.35); color: #d1fae5; }

/* Button variants used in tables & actions */
.btn-sm { padding: 7px 10px; border-radius: 10px; font-size: 12px; }
.btn-xs { padding: 5px 8px; border-radius: 10px; font-size: 12px; }

.btn-ghost {
  background: transparent;
  border-color: rgba(148,163,184,.22);
}
.btn-ghost:hover { background: rgba(148,163,184,.06); border-color: rgba(148,163,184,.35); }

.btn-success { background: rgba(16,185,129,.16); border-color: rgba(16,185,129,.35); }
.btn-success:hover { background: rgba(16,185,129,.22); }

.btn-warning { background: rgba(245,158,11,.16); border-color: rgba(245,158,11,.35); }
.btn-warning:hover { background: rgba(245,158,11,.22); }

.btn:disabled, .btn[disabled] {
  opacity: .55;
  cursor: not-allowed;
}



/* Plain HTML tables (edit pages, details)
   ------------------------------------------------- */
.content table{
  width: 100%;
  border-collapse: collapse;
  color: rgba(226,232,240,.94);
  border: 1px solid rgba(148,163,184,.18);
  border-radius: 14px;
  overflow: hidden;
}
.content table thead th{
  background: rgba(2, 6, 23, 0.35);
  color: rgba(148,163,184,.92);
  font-weight: 700;
  text-align: left;
}
.content table th,
.content table td{
  padding: 10px 12px;
  border-bottom: 1px solid rgba(148,163,184,.12);
}
.content table tbody tr td{ background: rgba(2, 6, 23, 0.18); }
.content table tbody tr:nth-child(2n) td{ background: rgba(148,163,184,.05); }
.content table tbody tr:hover td{ background: rgba(148,163,184,.08); }
.content table td:first-child,
.content table th:first-child{ padding-left: 14px; }
.content table td:last-child,
.content table th:last-child{ padding-right: 14px; }

/* Badges: make them a bit more consistent */
.badge { display: inline-flex; align-items: center; gap: .35rem; }
.badge.muted { background: rgba(148,163,184,.10); border-color: rgba(148,163,184,.25); color: rgba(148,163,184,.95); }

/* SKU additional barcodes preview in Tabulator cells */
.sku-barcode-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Toasts (AppUI.toast) */
#toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: rgba(15, 26, 43, 0.92);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: 420px;
  color: var(--text);
}

.toast.ok { border-color: rgba(16,185,129,.35); }
.toast.warn { border-color: rgba(245,158,11,.35); }
.toast.danger { border-color: rgba(239,68,68,.35); }

.toast.hide {
  opacity: 0;
  transform: translateY(6px);
  transition: all .35s ease;
}


@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* -------------------------------------------------
   Mobile polish (app)
   ------------------------------------------------- */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
}

@media (max-width: 720px) {
  :root { --sidebar-w: 260px; }

  body { font-size: 13px; }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }

  .topbar__left { width: 100%; }

  .crumbs {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-pill {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
  }

  .user-pill > div:nth-child(2) { min-width: 0; }
  .user-pill > div:nth-child(2) > div:last-child { display: none; }

  .user-pill .btn { padding: 6px 10px; }

  .content { padding: 14px; }

  .page-header__actions,
  .toolbar,
  .toolbar__left,
  .toolbar__right {
    width: 100%;
  }

  .toolbar { gap: 8px; }

  .btn { padding: 8px 10px; }
  .input { padding: 9px 10px; }

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

  .card__header .btn {
    width: 100%;
    justify-content: center;
  }

  .card__header { padding: 12px 14px; }
  .card__body { padding: 12px 14px; }

  .kpi-value { font-size: 20px; }
  .kpi-title { font-size: 11px; }
  .kpi-actions { margin-top: 6px; }

  .grid-host { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .grid-host .tabulator { min-width: 640px; }

  .tabulator { font-size: 12px; }
  .tabulator .tabulator-cell { padding: 8px 8px; }
  .tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 8px; }
  .tabulator .tabulator-header-filter input,
  .tabulator .tabulator-header-filter select { padding: 5px 6px; }

  .content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .content table th,
  .content table td { white-space: nowrap; }

  .content table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(6px);
  }

  .content table th,
  .content table td { padding: 8px 10px; }

  .badge { font-size: 11px; }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .content { padding: 12px; }
  .btn-row { gap: 8px; }
  .card__header { padding: 10px 12px; }
  .card__body { padding: 10px 12px; }
}
