:root{
  --bg:#f6f7f9;
  --surface:#ffffff;
  --surface-soft:#fafbfc;
  --line:#d9dee7;
  --line-soft:#edf0f4;
  --text:#1f2328;
  --muted:#687385;
  --muted-2:#8a94a6;
  --primary:#1f6feb;
  --primary-dark:#1859bf;
  --danger:#c93c37;
  --ok:#1a7f37;
  --warn:#9a6700;
  --focus:rgba(31,111,235,.22);
  --shadow:0 1px 2px rgba(16,24,40,.06);
}

*{box-sizing:border-box;}

html,body{min-height:100%;}

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  font-size:14px;
}

a{color:inherit;text-decoration:none;}
button,input,select{font:inherit;}

.app-shell{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

.topbar{
  position:sticky;
  top:0;
  z-index:30;
  display:grid;
  grid-template-columns:minmax(180px,260px) 1fr auto;
  align-items:center;
  gap:18px;
  min-height:64px;
  padding:10px 20px;
  border-bottom:1px solid var(--line);
  background:rgba(255,255,255,.94);
  backdrop-filter:blur(10px);
}

.brand-title{
  font-weight:700;
  font-size:18px;
  letter-spacing:0;
}

.brand-subtitle{
  margin-top:2px;
  color:var(--muted);
  font-size:12px;
}

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

.nav-link{
  min-height:34px;
  display:inline-flex;
  align-items:center;
  padding:7px 10px;
  border-radius:6px;
  color:var(--muted);
  white-space:nowrap;
}

.nav-link:hover,
.nav-link.is-active{
  background:#eef3fb;
  color:#17324d;
}

.userbar{
  display:flex;
  align-items:center;
  gap:10px;
}

.user-label{
  color:var(--muted);
  max-width:180px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.catalog-topbar{
  grid-template-columns:minmax(130px,210px) 1fr auto;
  gap:12px;
  min-height:50px;
  padding:6px 20px;
}

.catalog-topbar .brand-subtitle{
  display:none;
}

.catalog-topbar .brand-title{
  font-size:17px;
}

.catalog-topbar .nav-link,
.catalog-topbar .button{
  min-height:30px;
  padding:5px 9px;
}

.catalog-topbar .catalog-tabs{
  align-items:center;
}

.nav-divider{
  width:1px;
  height:22px;
  margin:0 4px;
  background:var(--line);
  flex:0 0 auto;
}

.catalog{
  display:flex;
  flex-direction:column;
  gap:6px;
  padding:8px 20px 16px;
}

.catalog-tabs{
  display:flex;
  align-items:center;
  gap:5px;
  overflow:auto;
  padding:0;
}

.segment-tab{
  min-height:28px;
  padding:4px 9px;
  border:1px solid var(--line);
  border-radius:6px;
  background:#fff;
  color:#445064;
  cursor:pointer;
  white-space:nowrap;
}

.segment-tab:hover,
.segment-tab.is-active{
  border-color:#b7c8e8;
  background:#eaf2ff;
  color:#174ea6;
}

.catalog-toolbar,
.table-section{
  border:1px solid var(--line);
  background:var(--surface);
  box-shadow:var(--shadow);
}

.catalog-toolbar{
  display:grid;
  grid-template-columns:minmax(240px,430px) minmax(360px,1fr) auto;
  gap:8px;
  align-items:center;
  padding:8px 10px;
}

.search-block,
.filter-field{
  display:flex;
  flex-direction:column;
  gap:0;
  min-width:0;
}

.catalog-toolbar .field-label{
  position:absolute;
  width:1px;
  height:1px;
  margin:-1px;
  padding:0;
  overflow:hidden;
  clip:rect(0,0,0,0);
  white-space:nowrap;
  border:0;
}

.filters-grid{
  display:flex;
  align-items:center;
  gap:6px;
}

.filters-grid .filter-field{
  flex:1 1 92px;
}

.filters-grid .filter-field:last-child{
  flex:1.6 1 160px;
}

.field-label{
  color:var(--muted);
  font-size:12px;
  line-height:1.1;
}

.input,
.select{
  width:100%;
  min-height:32px;
  padding:5px 9px;
  border:1px solid var(--line);
  border-radius:6px;
  background:#fff;
  color:var(--text);
  outline:none;
}

.input:focus,
.select:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px var(--focus);
}

.search-input{
  min-height:32px;
  font-size:14px;
}

.toolbar-actions{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
  gap:6px;
}

.selection-actions{
  position:fixed;
  left:50%;
  bottom:14px;
  z-index:90;
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:center;
  gap:6px;
  max-width:min(980px,calc(100vw - 24px));
  padding:8px;
  border:1px solid var(--line);
  border-radius:8px;
  background:rgba(255,255,255,.96);
  box-shadow:0 14px 36px rgba(16,24,40,.20);
  transform:translateX(-50%);
  backdrop-filter:blur(10px);
}

.selection-actions[hidden]{
  display:none;
}

.selection-chip{
  display:inline-flex;
  align-items:center;
  min-height:30px;
  padding:5px 9px;
  border-radius:6px;
  background:#eef3fb;
  color:#17324d;
  font-size:12px;
  font-weight:700;
  white-space:nowrap;
}

.print-menu{
  position:relative;
  display:inline-flex;
}

.columns-menu{
  position:relative;
  display:inline-flex;
}

.columns-menu-panel{
  position:absolute;
  top:calc(100% + 6px);
  right:0;
  z-index:55;
  display:grid;
  grid-template-columns:repeat(2,minmax(150px,1fr));
  gap:3px 8px;
  min-width:360px;
  max-width:min(520px,calc(100vw - 32px));
  padding:8px;
  border:1px solid var(--line);
  border-radius:7px;
  background:#fff;
  box-shadow:0 12px 30px rgba(16,24,40,.18);
}

.columns-menu-panel[hidden]{
  display:none;
}

.column-toggle{
  display:flex;
  align-items:center;
  gap:7px;
  min-height:30px;
  padding:5px 6px;
  border-radius:5px;
  color:#2f3948;
  font-size:13px;
  cursor:pointer;
}

.column-toggle:hover{
  background:#f3f6fa;
}

.column-toggle input{
  width:16px;
  height:16px;
  margin:0;
  accent-color:var(--primary);
}

.print-menu-panel{
  position:absolute;
  top:calc(100% + 6px);
  right:0;
  z-index:50;
  min-width:210px;
  padding:5px;
  border:1px solid var(--line);
  border-radius:7px;
  background:#fff;
  box-shadow:0 12px 30px rgba(16,24,40,.18);
}

.selection-actions .print-menu-panel{
  top:auto;
  bottom:calc(100% + 6px);
}

.print-menu-panel[hidden]{
  display:none;
}

.menu-item{
  width:100%;
  min-height:32px;
  display:flex;
  align-items:center;
  justify-content:flex-start;
  padding:7px 9px;
  border:0;
  border-radius:5px;
  background:#fff;
  color:var(--text);
  cursor:pointer;
  text-align:left;
}

.menu-item:hover:not(:disabled){
  background:#f3f6fa;
}

.menu-item:disabled{
  opacity:.5;
  cursor:not-allowed;
}

.button{
  min-height:32px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:6px 10px;
  border:1px solid transparent;
  border-radius:6px;
  cursor:pointer;
  white-space:nowrap;
  transition:background .14s ease,border-color .14s ease,color .14s ease;
}

.button:disabled{
  opacity:.5;
  cursor:not-allowed;
}

.button-primary{
  background:var(--primary);
  color:#fff;
}

.button-primary:hover:not(:disabled){
  background:var(--primary-dark);
}

.button-ghost{
  border-color:var(--line);
  background:#fff;
  color:#2f3948;
}

.button-ghost:hover:not(:disabled){
  background:#f3f6fa;
}

.button.is-active,
.button[aria-pressed="true"]{
  border-color:#b7c8e8;
  background:#eaf2ff;
  color:#174ea6;
}

.table-section{
  min-height:420px;
}

.table-status{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  min-height:36px;
  padding:8px 12px;
  border-bottom:1px solid var(--line);
}

.muted{
  color:var(--muted);
  font-size:12px;
}

.table-wrap{
  width:100%;
  overflow:auto;
  max-height:calc(100vh - 168px);
  background:#fff;
}

body.has-selection .catalog{
  padding-bottom:88px;
}

body.has-selection .table-wrap{
  max-height:calc(100vh - 244px);
}

body.has-selection .toast{
  bottom:88px;
}

.catalog-table{
  width:100%;
  min-width:2466px;
  border-collapse:separate;
  border-spacing:0;
  table-layout:fixed;
}

.catalog-table th,
.catalog-table td{
  height:164px;
  padding:7px 8px;
  border-right:1px solid var(--line-soft);
  border-bottom:1px solid var(--line-soft);
  vertical-align:middle;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:normal;
  font-size:13px;
}

.catalog-table th{
  height:36px;
  position:sticky;
  top:0;
  z-index:10;
  background:var(--surface-soft);
  color:#445064;
  font-size:12px;
  font-weight:600;
  text-align:left;
}

.th-sort{
  width:100%;
  min-height:22px;
  display:inline-flex;
  align-items:center;
  justify-content:space-between;
  gap:6px;
  padding:0;
  border:0;
  background:transparent;
  color:inherit;
  font:inherit;
  cursor:pointer;
  text-align:left;
}

.th-sort:hover{
  color:var(--primary);
}

.sort-mark{
  color:var(--primary);
  font-size:11px;
  line-height:1;
}

.catalog-table th:first-child,
.catalog-table td:first-child{
  position:sticky;
  left:0;
  z-index:8;
  background:inherit;
}

.catalog-table th:first-child{
  z-index:12;
  background:var(--surface-soft);
}

.catalog-table tbody tr{
  background:#fff;
  cursor:default;
}

.catalog-table tbody tr:nth-child(even){
  background:#fcfdff;
}

.catalog-table tbody tr:hover{
  background:#f4f8ff;
}

.catalog-table tbody tr.is-selected{
  background:#eaf2ff;
  box-shadow:inset 3px 0 0 var(--primary);
}

.col-check{width:44px;text-align:center;}
.col-sku{width:92px;}
.col-gallery{width:86px;}
.col-photo{width:168px;}
.col-name{width:190px;}
.col-fitment{width:134px;}
.col-params{width:214px;}
.col-type{width:74px;}
.col-size{width:170px;}
.col-color{width:98px;}
.col-year{width:56px;}
.col-r{width:48px;text-align:center;}
.col-pcd{width:90px;}
.col-price{width:100px;text-align:right;}
.col-kit{width:68px;text-align:center;}
.col-discount{width:68px;text-align:center;}
.col-stock{width:86px;text-align:center;}
.col-warehouse{width:100px;}
.col-storage-location{width:112px;}
.col-warehouse-check{width:120px;text-align:center;}
.col-qr-work{width:132px;text-align:center;}
.col-qr{width:86px;text-align:center;}
.col-catalog-added{width:132px;}
.col-catalog-updated{width:132px;}
.col-last-imported{width:132px;}
.col-import-source{width:176px;}
.col-status{width:80px;}
.col-actions{width:132px;}

.thumb{
  width:150px;
  height:150px;
  border:1px solid var(--line);
  border-radius:5px;
  object-fit:cover;
  background:#f1f3f6;
  display:block;
}

.thumb-empty{
  width:150px;
  height:150px;
  border:1px dashed var(--line);
  border-radius:5px;
  background:#f7f8fa;
}

.row-check,
#selectAllRows{
  width:18px;
  height:18px;
  margin:0;
  cursor:pointer;
  accent-color:var(--primary);
}

.catalog-row .col-check{
  cursor:pointer;
}

.cell-stack{
  min-height:136px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:5px;
}

.cell-main-title{
  font-weight:650;
}

.cell-subline{
  display:block;
  color:var(--muted);
  font-size:12px;
  line-height:1.25;
}

.catalog-table .group-row td{
  position:relative;
  left:auto;
  z-index:6;
  padding:6px 12px;
  color:#17324d;
  font-weight:700;
  white-space:nowrap;
}

.catalog-table .group-row-r td{
  height:34px;
  border-top:1px solid #ead18b;
  border-bottom:1px solid #ead18b;
  background:#fff1b8;
  color:#6d3c00;
  text-align:center;
}

.catalog-table .group-row-pcd td{
  height:28px;
  border-top:1px solid #c8d5ea;
  border-bottom:1px solid #c8d5ea;
  background:#e8f0fe;
  color:#17324d;
  text-align:center;
}

.group-row span{
  margin-right:8px;
  font-size:15px;
}

.group-row-r span{
  font-size:20px;
  font-weight:800;
}

.group-row-pcd span{
  font-size:15px;
  font-weight:800;
}

.group-row small{
  color:#5d6f8c;
  font-size:12px;
  font-weight:600;
}

.group-row em{
  margin-left:10px;
  padding:2px 7px;
  border-radius:999px;
  background:#fff;
  color:#5d6f8c;
  font-size:11px;
  font-style:normal;
  font-weight:700;
  text-transform:uppercase;
}

.price-mode .catalog-table{
  min-width:1208px;
}

.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:24px;
  padding:3px 8px;
  border-radius:999px;
  font-size:12px;
  font-weight:600;
}

.badge-ok{
  background:#dafbe1;
  color:var(--ok);
}

.badge-ready{
  background:#eaf2ff;
  color:#174ea6;
}

.badge-warn{
  background:#fff8c5;
  color:var(--warn);
}

.badge-empty{
  background:#ffebe9;
  color:var(--danger);
}

.badge-muted{
  background:#eef1f5;
  color:#596579;
}

.cell-editable{
  min-height:28px;
  padding:5px 6px;
  border-radius:5px;
  outline:none;
  line-height:1.3;
  white-space:normal;
  overflow-wrap:anywhere;
}

.cell-editable:hover{
  background:#eef3fb;
}

.cell-editable:focus{
  background:#fff;
  box-shadow:inset 0 0 0 2px var(--primary);
}

.cell-saving{
  background:#fff8c5;
}

.cell-error{
  background:#ffebe9;
  color:var(--danger);
}

.row-actions{
  display:flex;
  align-items:center;
  gap:6px;
}

.text-link{
  background:transparent;
  border:0;
  color:var(--primary);
  cursor:pointer;
  font-weight:600;
  padding:0;
  text-align:left;
}

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

.gallery-link{
  min-height:28px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:4px 8px;
  border:1px solid #b7c8e8;
  border-radius:6px;
  background:#fff;
  color:var(--primary);
  text-decoration:none;
}

.gallery-link:hover{
  background:#eaf2ff;
  text-decoration:none;
}

.loading-cell,
.empty-cell{
  padding:28px;
  color:var(--muted);
  text-align:center;
}

.toast{
  position:fixed;
  right:18px;
  bottom:18px;
  z-index:80;
  max-width:min(380px,calc(100vw - 36px));
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius:7px;
  background:#fff;
  color:var(--text);
  box-shadow:0 12px 30px rgba(16,24,40,.18);
  opacity:0;
  pointer-events:none;
  transform:translateY(8px);
  transition:opacity .16s ease,transform .16s ease;
}

.toast.is-visible{
  opacity:1;
  transform:translateY(0);
}

.cases-gallery{
  display:flex;
  flex-direction:column;
  gap:12px;
  padding:12px 20px 24px;
}

.cases-gallery-topbar .brand-subtitle{
  display:block;
}

.cases-gallery-toolbar{
  display:grid;
  grid-template-columns:minmax(220px,360px) 1fr auto;
  gap:10px;
  align-items:end;
  padding:10px;
  border:1px solid var(--line);
  background:var(--surface);
  box-shadow:var(--shadow);
}

.cases-gallery-filters{
  display:grid;
  grid-template-columns:repeat(6,minmax(92px,1fr));
  gap:8px;
}

.cases-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(220px,1fr));
  gap:12px;
}

.case-card{
  min-width:0;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
  box-shadow:var(--shadow);
  cursor:pointer;
  overflow:hidden;
  transition:border-color .14s ease,box-shadow .14s ease,transform .14s ease;
}

.case-card:hover,
.case-card:focus{
  border-color:#b7c8e8;
  box-shadow:0 8px 22px rgba(16,24,40,.10);
  outline:none;
  transform:translateY(-1px);
}

.case-image-box{
  position:relative;
  width:100%;
  aspect-ratio:4/3;
  background:#f1f3f6;
  overflow:hidden;
}

.case-image-box img{
  width:100%;
  height:100%;
  display:block;
  object-fit:cover;
}

.case-image-placeholder{
  position:absolute;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  color:var(--muted);
  background:#f1f3f6;
  font-weight:650;
}

.case-image-box.is-empty .case-image-placeholder{
  display:flex;
}

.case-card-body{
  display:flex;
  flex-direction:column;
  gap:6px;
  padding:10px;
}

.case-card h3{
  margin:0;
  color:#202938;
  font-size:14px;
  line-height:1.25;
  overflow:hidden;
  display:-webkit-box;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:2;
}

.case-card p{
  min-height:34px;
  margin:0;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
  overflow:hidden;
  display:-webkit-box;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:2;
}

.case-chips{
  display:flex;
  flex-wrap:wrap;
  gap:5px;
}

.case-chips span{
  min-height:22px;
  display:inline-flex;
  align-items:center;
  padding:2px 7px;
  border:1px solid var(--line-soft);
  border-radius:999px;
  background:#f6f8fb;
  color:#596579;
  font-size:11px;
  font-weight:600;
}

.cases-empty{
  padding:34px;
  border:1px solid var(--line);
  background:#fff;
  color:var(--muted);
  text-align:center;
}

.case-modal[hidden]{
  display:none;
}

.case-modal{
  position:fixed;
  inset:0;
  z-index:100;
}

.case-modal-backdrop{
  position:absolute;
  inset:0;
  background:rgba(15,23,42,.48);
}

.case-modal-panel{
  position:absolute;
  inset:22px;
  display:flex;
  flex-direction:column;
  gap:12px;
  max-width:1180px;
  margin:0 auto;
  padding:14px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
  box-shadow:0 20px 60px rgba(16,24,40,.24);
}

.case-modal-header,
.case-modal-footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex:0 0 auto;
}

.case-modal-header h2{
  margin:0 0 4px;
  font-size:18px;
}

.case-modal-header p{
  margin:0;
  color:var(--muted);
  font-size:13px;
}

.case-modal-images{
  min-height:0;
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(240px,1fr));
  gap:10px;
  overflow:auto;
  padding-right:4px;
}

.case-modal-images .case-image-box{
  border:1px solid var(--line);
  border-radius:7px;
}

.has-modal{
  overflow:hidden;
}

@media (max-width:1100px){
  .topbar{
    grid-template-columns:1fr;
    gap:10px;
    align-items:start;
  }
  .topnav,
  .userbar{
    width:100%;
    overflow:auto;
  }
  .catalog-toolbar{
    grid-template-columns:1fr;
  }
  .filters-grid{
    grid-template-columns:repeat(2,minmax(120px,1fr));
  }
  .toolbar-actions{
    justify-content:flex-start;
  }
  .columns-menu-panel{
    right:auto;
    left:0;
  }
  .selection-actions{
    left:10px;
    right:10px;
    bottom:10px;
    justify-content:flex-start;
    max-width:none;
    max-height:42vh;
    overflow:auto;
    transform:none;
  }
  .table-wrap{
    max-height:none;
  }
  body.has-selection .catalog{
    padding-bottom:116px;
  }
  body.has-selection .table-wrap{
    max-height:none;
  }
  body.has-selection .toast{
    bottom:116px;
  }
  .cases-gallery-toolbar{
    grid-template-columns:1fr;
  }
  .cases-gallery-filters{
    grid-template-columns:repeat(3,minmax(120px,1fr));
  }
}

@media (max-width:620px){
  .catalog{
    padding:10px;
  }
  .topbar{
    padding:10px;
  }
  .filters-grid{
    display:grid;
    grid-template-columns:1fr;
  }
  .table-status{
    align-items:flex-start;
    flex-direction:column;
  }
  .columns-menu-panel{
    grid-template-columns:1fr;
    min-width:min(320px,calc(100vw - 24px));
  }
  .cases-gallery{
    padding:10px;
  }
  .cases-gallery-filters{
    grid-template-columns:1fr 1fr;
  }
  .cases-grid{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }
  .case-card-body{
    padding:8px;
  }
  .case-modal-panel{
    inset:8px;
  }
  .case-modal-header{
    align-items:flex-start;
    flex-direction:column;
  }
  .case-modal-images{
    grid-template-columns:1fr;
  }
}
