.companies-app{
  height:100vh;
  grid-template-rows:var(--header-h) minmax(0,1fr);
}

.companies-page{
  display:grid;
  grid-template-columns:360px minmax(0,1fr);
  gap:18px;
  padding:18px;
  min-height:0;
}

.companies-sidebar{
  display:flex;
  flex-direction:column;
  gap:14px;
  padding:18px;
  min-height:0;
}

.sidebar-head,
.panel-headline,
.tree-headline{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}

.panel-title{
  font-size:18px;
  font-weight:800;
  line-height:1.1;
}

.panel-subtitle{
  font-size:13px;
  color:var(--muted);
  margin-top:6px;
}

.sidebar-toolbar{display:flex;gap:10px}

.companies-stats{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
}

.company-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow:auto;
  padding-right:4px;
  min-height:0;
}

.company-list::-webkit-scrollbar,
.tree-board::-webkit-scrollbar,
.form-panel::-webkit-scrollbar{
  width:7px;
}

.company-list::-webkit-scrollbar-thumb,
.tree-board::-webkit-scrollbar-thumb,
.form-panel::-webkit-scrollbar-thumb{
  background:rgba(255,122,24,.25);
  border-radius:999px;
}

.company-card{
  position:relative;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.03);
  border-radius:18px;
  padding:14px;
  cursor:pointer;
  transition:.2s ease;
}

.company-card:hover{
  transform:translateY(-1px);
  border-color:rgba(255,122,24,.35);
}

.company-card.active{
  border-color:rgba(255,122,24,.8);
  box-shadow:0 0 0 1px rgba(255,122,24,.25), 0 12px 28px rgba(0,0,0,.22);
}

.company-card-title{
  font-size:15px;
  font-weight:800;
  margin-bottom:4px;
  padding-right:88px;
}

.company-card-meta{
  font-size:12px;
  color:rgba(255,255,255,.62);
  margin-bottom:10px;
}

.company-card-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:8px;
  font-size:12px;
}

.company-card-grid span{
  display:block;
  color:rgba(255,255,255,.56);
  margin-bottom:2px;
}

.node-status{
  position:absolute;
  top:12px;
  right:12px;
  padding:4px 8px;
  border-radius:999px;
  font-size:11px;
  font-weight:700;
}

.node-status.active{background:rgba(40,167,69,.16);color:#8de2a2}
.node-status.paused{background:rgba(255,193,7,.14);color:#ffd369}
.node-status.archive{background:rgba(108,117,125,.18);color:#c0c7d2}

.companies-workspace,
.workspace-grid,
.form-panel,
.tree-panel{
  min-height:0;
}

.workspace-grid{
  display:grid;
  grid-template-columns:430px minmax(0,1fr);
  gap:18px;
  height:100%;
}

.form-panel{
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:16px;
  overflow:auto;
}

.company-form{
  display:flex;
  flex-direction:column;
  gap:14px;
  min-height:min-content;
}

.form-grid{display:grid;gap:12px}
.form-grid.two-cols{grid-template-columns:repeat(2,minmax(0,1fr))}
.form-grid.three-cols{grid-template-columns:repeat(3,minmax(0,1fr))}

.company-form label{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.company-form label span{
  font-size:12px;
  color:rgba(255,255,255,.72);
}

.qi-input{
  width:100%;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.08);
  color:#fff;
  border-radius:14px;
  padding:12px 14px;
  outline:none;
}

.qi-input:focus{
  border-color:rgba(255,122,24,.65);
  box-shadow:0 0 0 3px rgba(255,122,24,.12);
}

.qi-input::placeholder{color:rgba(255,255,255,.40)}
.qi-input option{background:#101722;color:#fff}
.qi-textarea{resize:vertical;min-height:110px}

.node-tools{
  background:rgba(255,255,255,.035);
  border:1px solid rgba(255,255,255,.08);
  border-radius:18px;
  padding:14px;
}

.node-tools-title{
  font-size:13px;
  font-weight:800;
  margin-bottom:12px;
}

.node-tools-actions{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
}

.node-hint{
  margin-top:12px;
  font-size:12px;
  color:rgba(255,255,255,.66);
  line-height:1.45;
}

.form-actions-bottom{
  display:flex;
  justify-content:flex-end;
  margin-top:4px;
  padding-bottom:2px;
}

.tree-panel{
  padding:18px;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  gap:14px;
}

.tree-legend{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.tree-chip{
  padding:8px 12px;
  border-radius:999px;
  background:rgba(7,10,16,.72);
  border:1px solid rgba(255,255,255,.07);
  font-size:12px;
  font-weight:800;
  color:var(--muted);
}

.tree-board{
  overflow:auto;
  border:1px solid rgba(255,255,255,.06);
  border-radius:22px;
  background:
    linear-gradient(180deg, rgba(8,12,18,.9), rgba(10,14,22,.86));
  padding:16px;
}

.tree-root-list,
.tree-children{
  list-style:none;
  margin:0;
  padding:0;
}

.tree-children{
  margin-left:24px;
  padding-left:18px;
  border-left:1px dashed rgba(255,255,255,.10);
}

.tree-item{
  margin-bottom:10px;
}

.tree-row{
  display:flex;
  align-items:center;
  gap:10px;
  min-height:44px;
}

.tree-toggle{
  width:28px;
  height:28px;
  border:none;
  border-radius:10px;
  background:rgba(255,255,255,.05);
  color:#fff;
  cursor:pointer;
  flex:0 0 auto;
}

.tree-toggle.hidden{
  visibility:hidden;
}

.tree-node{
  flex:1;
  min-width:0;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.03);
  border-radius:16px;
  padding:10px 12px;
  cursor:pointer;
  transition:.18s ease;
}

.tree-node:hover{
  border-color:rgba(255,122,24,.35);
  transform:translateY(-1px);
}

.tree-node.active{
  border-color:rgba(255,122,24,.8);
  box-shadow:0 0 0 1px rgba(255,122,24,.22), 0 10px 24px rgba(0,0,0,.20);
}

.tree-node-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.tree-node-title{
  font-size:14px;
  font-weight:800;
  color:#fff;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.tree-node-badge{
  flex:0 0 auto;
  font-size:11px;
  font-weight:800;
  color:#fff1e5;
  border:1px solid rgba(255,122,24,.24);
  background:rgba(255,122,24,.12);
  border-radius:999px;
  padding:4px 8px;
}

.tree-node-meta{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
}

.tree-node-actions{
  display:flex;
  gap:6px;
  flex:0 0 auto;
}

.tree-mini-btn{
  width:34px;
  height:34px;
  border:none;
  border-radius:12px;
  background:rgba(255,255,255,.04);
  color:var(--muted);
  cursor:pointer;
  font-weight:800;
}

.tree-mini-btn:hover{
  background:linear-gradient(180deg, rgba(255,122,24,.26), rgba(255,122,24,.12));
  color:#fff1e5;
  box-shadow:inset 0 0 0 1px rgba(255,122,24,.28), 0 0 20px rgba(255,122,24,.08);
}

.empty-state{
  padding:18px;
  text-align:center;
  color:rgba(255,255,255,.6);
  border:1px dashed rgba(255,255,255,.08);
  border-radius:18px;
}

.mode-btn.companies-top-btn,
.mode-btn.company-action-btn,
.mode-btn.company-tool-btn,
.mode-btn.company-save-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  text-decoration:none;
}

.mode-btn.companies-top-btn,
.mode-btn.company-save-btn{
  background:linear-gradient(180deg, rgba(255,122,24,.26), rgba(255,122,24,.12));
  color:#fff1e5;
  box-shadow:inset 0 0 0 1px rgba(255,122,24,.28), 0 0 20px rgba(255,122,24,.08);
}

.mode-btn.company-action-btn,
.mode-btn.company-tool-btn{
  background:rgba(255,255,255,.025);
  color:var(--muted);
  border:1px solid rgba(255,255,255,.06);
}

.mode-btn.company-action-btn:hover,
.mode-btn.company-tool-btn:hover{
  background:linear-gradient(180deg, rgba(255,122,24,.26), rgba(255,122,24,.12));
  color:#fff1e5;
  box-shadow:inset 0 0 0 1px rgba(255,122,24,.28), 0 0 20px rgba(255,122,24,.08);
}

.mode-btn.company-action-btn.danger{
  color:#ffb0b0;
  border-color:rgba(255,91,84,.18);
}

.mode-btn.company-action-btn.danger:hover{
  background:linear-gradient(180deg, rgba(255,91,84,.22), rgba(255,91,84,.10));
  color:#fff1e5;
  box-shadow:inset 0 0 0 1px rgba(255,91,84,.28), 0 0 20px rgba(255,91,84,.08);
}

.mode-btn[disabled]{
  opacity:.45;
  cursor:not-allowed;
  pointer-events:none;
}

@media (max-width:1280px){
  .companies-page{grid-template-columns:320px minmax(0,1fr)}
  .workspace-grid{grid-template-columns:390px minmax(0,1fr)}
}

@media (max-width:1024px){
  body{overflow:auto}
  .companies-app{height:auto;grid-template-rows:auto auto}
  .companies-page{grid-template-columns:1fr}
  .workspace-grid{grid-template-columns:1fr}
}

html, body{
  height:100%;
}

body.page-companies{
  overflow:hidden;
}

.companies-app{
  height:100vh;
  min-height:100vh;
  display:grid;
  grid-template-rows:var(--header-h) minmax(0,1fr);
  overflow:hidden;
}

.companies-page-full{
  min-height:0;
  height:100%;
  overflow:hidden;
}

.companies-page{
  height:100%;
  min-height:0;
  display:grid;
  grid-template-columns:360px minmax(0,1fr);
  gap:18px;
  padding:18px;
  overflow:hidden;
}

.companies-sidebar,
.companies-workspace,
.workspace-grid,
.form-panel,
.tree-panel,
.tree-board,
.company-list{
  min-height:0;
}

.companies-sidebar{
  overflow:hidden;
}

.companies-workspace{
  overflow:hidden;
}

.workspace-grid{
  height:100%;
  overflow:hidden;
}

.form-panel{
  overflow:auto;
}

.tree-panel{
  overflow:hidden;
}

.tree-board{
  overflow:auto;
}

.company-list{
  overflow:auto;
}

.qi-companies-module{
  height:100%;
  min-height:0;
}

.companies-page{
  display:grid;
  grid-template-columns:360px minmax(0,1fr);
  gap:18px;
  padding:18px;
  height:calc(100vh - var(--header-h));
  min-height:0;
  overflow:hidden;
}

.companies-sidebar,
.companies-workspace,
.workspace-grid,
.form-panel,
.tree-panel{
  min-height:0;
}

.companies-sidebar{
  display:flex;
  flex-direction:column;
  gap:14px;
  padding:18px;
  overflow:hidden;
}

.companies-workspace{
  min-width:0;
  overflow:hidden;
}

.workspace-grid{
  display:grid;
  grid-template-columns:430px minmax(0,1fr);
  gap:18px;
  height:100%;
  min-height:0;
  overflow:hidden;
}

.form-panel{
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:16px;
  overflow:auto;
}

.tree-panel{
  padding:18px;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  gap:14px;
  overflow:hidden;
}

.tree-board{
  overflow:auto;
  min-height:0;
}

.company-list{
  overflow:auto;
  min-height:0;
}

.form-panel{
  padding-bottom:30px;
}

.form-actions-bottom{
  padding-bottom:20px;
}